using System.Collections.Generic; using System.Linq; using Centron.BusinessLogic; using Centron.BusinessLogic.Administration.Customization; using Centron.BusinessLogic.WebServices.Accounts; using Centron.Data.Entities.Administration.Customization; using Centron.Interfaces; using Centron.Interfaces.Accounts; using Centron.Interfaces.Administration.Customization; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.Administration.Customization; public class AccountSearchCustomPropertiesTests : EndToEndTest { public AccountSearchCustomPropertiesTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } public override void Execute() { var properties = PrepareAdditionalProperties(); PrepareAccountsWithCustomProperties(properties); ExecuteAccountSearch("Search term 'Wasserschaden'", new AccountSearchFilter() { IsActive = true, SearchText = "Wasserschaden" }, new List() { 4, 7 }); ExecuteAccountSearch("Search term 'C#'", new AccountSearchFilter() { IsActive = true, SearchText = "C#" }, new List() { 16 }); ExecuteAccountSearch("Custom property Text 'Überflutung'", new AccountSearchFilter() { IsActive = true, CustomPropertyFilterItems = new List() { new ModuleCustomPropertyFilterItem() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Text").I3D, DataType = CustomizationDataTypes.Text, Value = "Überflutung" } } }, new List() { 16 }); ExecuteAccountSearch("Custom property Text 'Hochwasser'", new AccountSearchFilter() { IsActive = true, CustomPropertyFilterItems = new List() { new ModuleCustomPropertyFilterItem() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Text").I3D, DataType = CustomizationDataTypes.Text, Value = "Hochwasser" } } }, new List() { }); ExecuteAccountSearch("Custom property Integer '16'", new AccountSearchFilter() { IsActive = true, CustomPropertyFilterItems = new List() { new ModuleCustomPropertyFilterItem() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Integer").I3D, DataType = CustomizationDataTypes.Integer, Value = "16" } } }, new List() { 16 }); ExecuteAccountSearch("Custom property ComboBox 'Web Tools'", new AccountSearchFilter() { IsActive = true, CustomPropertyFilterItems = new List() { new ModuleCustomPropertyFilterItem() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld ComboBox").I3D, DataType = CustomizationDataTypes.ComboBox, Value = properties.First(f => f.Name == "Zusatzfeld ComboBox").PossibleValues.First().I3D } } }, new List() { 4, 7 }); ExecuteAccountSearch("Custom property Boolean 'false'", new AccountSearchFilter() { IsActive = true, CustomPropertyFilterItems = new List() { new ModuleCustomPropertyFilterItem() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Boolean").I3D, DataType = CustomizationDataTypes.Boolean, Value = false } } }, new List() { 1036 }); ExecuteAccountSearch("Search without custom properties", new AccountSearchFilter() { IsActive = true, SearchText = "Sparkasse Ulm" }, new List() { 11 }); } private void ExecuteAccountSearch(string checkCaption, AccountSearchFilter filter, List shouldHaveAccountI3Ds) { using var session = new BLSession(); var searchResult = session.GetBL().SearchAccountsThroughPaging(base.GetLoggedInUser(),filter, 1, int.MaxValue).ThrowIfError(); if (!shouldHaveAccountI3Ds.Any()) { Assert.True(!searchResult.Result.Any(), checkCaption); } else { Assert.True(searchResult.Result.All(f => shouldHaveAccountI3Ds.Contains(f.I3D)), checkCaption); } } private List PrepareAdditionalProperties() { using var session = new BLSession(); var properties = new List() { new ModuleCustomProperty() { Name = "Zusatzfeld Text", Category = "Allgemein", DataType = CustomizationDataTypes.Text, ObjectI3D = 0, ObjectKind = CentronObjectKindNumeric.Account, IsVisible = true, SortOrder = 0 }, new ModuleCustomProperty() { Name = "Zusatzfeld ComboBox", Category = "Allgemein", DataType = CustomizationDataTypes.ComboBox, ObjectI3D = 0, ObjectKind = CentronObjectKindNumeric.Account, IsVisible = true, SortOrder = 0, PossibleValues = new List() { new ModuleCustomPropertyPossibleValue() { Value = "Web Tools", IsVisible = true }, new ModuleCustomPropertyPossibleValue() { Value = "C#", IsVisible = true } } }, new ModuleCustomProperty() { Name = "Zusatzfeld Boolean", Category = "Allgemein", DataType = CustomizationDataTypes.Boolean, ObjectI3D = 0, ObjectKind = CentronObjectKindNumeric.Account, IsVisible = true, SortOrder = 0 }, new ModuleCustomProperty() { Name = "Zusatzfeld Integer", Category = "Allgemein", DataType = CustomizationDataTypes.Integer, ObjectI3D = 0, ObjectKind = CentronObjectKindNumeric.Account, IsVisible = true, SortOrder = 0 } }; session.GetBL().SaveCustomPropertyStructure(base.GetLoggedInUser(), properties, CentronObjectKindNumeric.Account).ThrowIfError(); return properties; } private void PrepareAccountsWithCustomProperties(List properties) { using var session = new BLSession(); session.GetBL().SaveCustomPropertyValues(base.GetLoggedInUser(), 4, CentronObjectKindNumeric.Account, new List() { new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Text").I3D, ObjectI3D = 4, ObjectKind = CentronObjectKindNumeric.Account, ValueText = "Wasserschaden" }, new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld ComboBox").I3D, ObjectI3D = 4, ObjectKind = CentronObjectKindNumeric.Account, ValueInteger = properties.First(f => f.Name == "Zusatzfeld ComboBox").PossibleValues.First().I3D }, }); session.GetBL().SaveCustomPropertyValues(base.GetLoggedInUser(), 7, CentronObjectKindNumeric.Account, new List() { new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Text").I3D, ObjectI3D = 7, ObjectKind = CentronObjectKindNumeric.Account, ValueText = "Wasserschaden" }, new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld ComboBox").I3D, ObjectI3D = 7, ObjectKind = CentronObjectKindNumeric.Account, ValueInteger = properties.First(f => f.Name == "Zusatzfeld ComboBox").PossibleValues.First().I3D }, }); session.GetBL().SaveCustomPropertyValues(base.GetLoggedInUser(), 16, CentronObjectKindNumeric.Account, new List() { new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Text").I3D, ObjectI3D = 16, ObjectKind = CentronObjectKindNumeric.Account, ValueText = "Überflutung des Kellers" }, new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld ComboBox").I3D, ObjectI3D = 16, ObjectKind = CentronObjectKindNumeric.Account, ValueInteger = properties.First(f => f.Name == "Zusatzfeld ComboBox").PossibleValues.Last().I3D }, new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Integer").I3D, ObjectI3D = 16, ObjectKind = CentronObjectKindNumeric.Account, ValueInteger = 16 }, new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Boolean").I3D, ObjectI3D = 16, ObjectKind = CentronObjectKindNumeric.Account, ValueBoolean = true } }); session.GetBL().SaveCustomPropertyValues(base.GetLoggedInUser(), 1036, CentronObjectKindNumeric.Account, new List() { new ModuleCustomPropertyValue() { ModuleCustomPropertyI3D = properties.First(f => f.Name == "Zusatzfeld Boolean").I3D, ObjectI3D = 1036, ObjectKind = CentronObjectKindNumeric.Account, ValueBoolean = false } }); } }