using Centron.BusinessLogic; using Centron.BusinessLogic.WebServices.Administration.Customization; using Centron.Common.TextCoding; using Centron.DAO; using Centron.Data.Entities.Administration.Customization; using Centron.Data.WebServices.Administration.Customization; using Centron.Interfaces; using Centron.Interfaces.Administration.Customization; using Centron.Interfaces.BL; using Centron.Tests.EndToEnd.Infrastructure; using System; using System.Collections.Generic; using Xunit; using Xunit.Abstractions; namespace Centron.Tests.EndToEnd.Tests.ModuleCustomProperties { public class ModuleCustomPropertiesTests : EndToEndTest { private CentronObjectKindNumeric _referenceObjectKind = CentronObjectKindNumeric.HelpdeskClass; private int _referenceObjectI3D = 10491; private string _testSecuriteyKey = "abcdedfghijklmnopqrstuvwxyz"; private Dictionary _propertyDataTypeToI3DMapping; public ModuleCustomPropertiesTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { this._propertyDataTypeToI3DMapping = new Dictionary(); } public override void Execute() { this.SaveCustomPropertyStructure(); this.GetCustomPropertyStructure(); this.SaveCustomPropertyValues(); this.GetCustomPropertyValues(); } private void SaveCustomPropertyStructure() { using var session = new BLSession(); var result = session .GetBL() .SaveCustomPropertyStructure( this.GetLoggedInUser(), new List { new ModuleCustomPropertyDTO { Category = "cat", DataType = CustomizationDataTypes.Hyperlink, IsVisible = true, Name = "most fitting subreddit", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 1, }, new ModuleCustomPropertyDTO { Category = "cat", DataType = CustomizationDataTypes.String, IsVisible = true, Name = "description", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 2, }, new ModuleCustomPropertyDTO { Category = "dog", DataType = CustomizationDataTypes.DateTime, IsVisible = true, Name = "date of first tail catching", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 3, }, new ModuleCustomPropertyDTO { Category = "dog", DataType = CustomizationDataTypes.Integer, IsVisible = true, Name = "number of legs", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 4, }, new ModuleCustomPropertyDTO { Category = "trashpanda", DataType = CustomizationDataTypes.Image, IsVisible = false, Name = "picture", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 4, }, new ModuleCustomPropertyDTO { Category = "trashpanda", DataType = CustomizationDataTypes.File, IsVisible = false, Name = "tax file", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 4, }, new ModuleCustomPropertyDTO { Category = "trashpanda", DataType = CustomizationDataTypes.EncryptedText, IsVisible = false, Name = "secret hideout password", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 4, } , new ModuleCustomPropertyDTO { Category = "trashpanda", DataType = CustomizationDataTypes.ComboBox, IsVisible = false, Name = "personality", ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, SortOrder = 4, PossibleValues = new List { new ModuleCustomPropertyPossibleValueDTO { IsVisible = true, Value = "cute" }, new ModuleCustomPropertyPossibleValueDTO { IsVisible = true, Value = "angery" }, new ModuleCustomPropertyPossibleValueDTO { IsVisible = true, Value = "trash" }, } } }, this._referenceObjectKind, this._referenceObjectI3D); Assert.Equal(ResultStatus.Success, result.Status); } private void GetCustomPropertyStructure() { using var session = new BLSession(); var result = session .GetBL() .GetCustomPropertyStructureForModule(this.GetLoggedInUser(), new CustomPropertyFilter { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind }); this.Verifier.Verify("ModuleCustomPropertyStructure", result); // we save the type + the new I3Ds here so we can reuse the i3ds when saving values in later tests. foreach (var currentProperty in result.Data) { if (this._propertyDataTypeToI3DMapping.ContainsKey(currentProperty.DataType)) continue; this._propertyDataTypeToI3DMapping.Add(currentProperty.DataType, currentProperty.I3D); } } private void SaveCustomPropertyValues() { using var session = new BLSession(); var textToBeEncrypted = "encryptedText"; var result = session .GetBL() .SaveCustomPropertyValues( this.GetLoggedInUser(), this._referenceObjectI3D, this._referenceObjectKind, new List { new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.Hyperlink], ValueString = "https://www.reddit.com/r/standardissuecat/", }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.String], ValueString = "standard issue", }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.DateTime], ValueDateTime = new DateTime(2020, 1, 1), }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.Integer], ValueInteger = 3, }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.Image], ValueBytes = new byte[20], }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.File], ValueBytes = new byte[20], ValueString = "trash_accounting_numbers.csv", }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, Sealed = true, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.EncryptedText], ValueEncryptedString = textToBeEncrypted, }, new ModuleCustomPropertyValueDTO { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind, Sealed = true, ModuleCustomPropertyI3D = this._propertyDataTypeToI3DMapping[CustomizationDataTypes.ComboBox], ValueInteger = 1, // we can safely us I3D 1 here as this table is completely new }, }, this._testSecuriteyKey); Assert.Equal(ResultStatus.Success, result.Status); // we want to test that the values actually get properly encrypted in the database var encryptedText = new AESCryptoLogic().EncryptText(textToBeEncrypted, this._testSecuriteyKey); this.Verifier.VerifyTable("EncryptedModuleCustomPropertyValueEntity", "ModuleCustomPropertyValues", $"ValueEncryptedString = '{encryptedText}'"); } private void GetCustomPropertyValues() { using var session = new BLSession(); var result = session .GetBL() .GetCustomPropertyValues(new CustomPropertyValueFilter { ObjectI3D = this._referenceObjectI3D, ObjectKind = this._referenceObjectKind }, this._testSecuriteyKey); this.Verifier.Verify("ModuleCustomPropertyValues", result); } } }