public void TestCustomFieldsContainerCopy() { var dataConfiguratorCollectionFactory = new TestDataConfiguratorCollectionFactory(); var dataConfiguratorCollection = new TestDataConfiguratorCollection <WebData>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { configurator.Target(x => x.CustomFieldsCopy.Value.Each().Key).Set(x => x.CustomFields.Value.Current().Key); configurator.Target(x => x.CustomFieldsCopy.Value.Each().Value.Value).Set(x => x.CustomFields.Value.Current().Value.Value); configurator.Target(x => x.CustomFieldsCopy.Value.Each().Value.TypeCode).Set(x => x.CustomFields.Value.Current().Value.TypeCode); configurator.Target(x => x.CustomFieldsCopy.Value.Each().Value.Title).Set(x => x.CustomFields.Value.Current().Value.Title); }); var mutator = dataConfiguratorCollection.GetMutatorsTree(MutatorsContext.Empty).GetTreeMutator(); var data = new WebData { CustomFields = new Lazy <Dictionary <string, CustomFieldValue> >(() => new Dictionary <string, CustomFieldValue> { { "X", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 0 } }, { "Y", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 1 } }, { "Z", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 2 } } }), }; mutator(data); Assert.AreEqual(0, data.CustomFieldsCopy.Value["X"].Value); Assert.AreEqual(1, data.CustomFieldsCopy.Value["Y"].Value); Assert.AreEqual(2, data.CustomFieldsCopy.Value["Z"].Value); }
public void TestModelDataValidator() { var dataConfiguratorCollectionFactory = new TestDataConfiguratorCollectionFactory(); var dataConfiguratorCollection = new TestDataConfiguratorCollection <Data>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { configurator.Target(data => data.S).Required(); configurator.Target(data => data.StrArr.Each()).InvalidIf(data => data.StrArr.Current() == "zzz", data => null); configurator.Target(data => data.Items.Each().S).Required(); } ); var modelDataConfiguratorCollection = new TestDataConfiguratorCollection <ModelData>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { }); dataConfiguratorCollectionFactory.Register(dataConfiguratorCollection); dataConfiguratorCollectionFactory.Register(new TestDataConfiguratorCollection <WebData>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { })); dataConfiguratorCollectionFactory.Register(modelDataConfiguratorCollection); var modelValidator = modelDataConfiguratorCollection.GetMutatorsTree(new[] { typeof(Data), typeof(WebData) }, new[] { MutatorsContext.Empty, MutatorsContext.Empty, MutatorsContext.Empty, }, new[] { MutatorsContext.Empty, MutatorsContext.Empty, }).GetValidator(); var validationResultTreeNode = modelValidator(new ModelData { CustomFields = new Dictionary <string, CustomFieldValue> { { "S", new CustomFieldValue { TypeCode = TypeCode.String } }, { "StrArr", new CustomFieldValue { TypeCode = TypeCode.String, IsArray = true, Value = new[] { "qxx", "zzz" } } } }, Items = new[] { new ModelDataItem { CustomFields = new Dictionary <string, CustomFieldValue> { { "S", new CustomFieldValue { TypeCode = TypeCode.String } } }, }, } }); validationResultTreeNode.AssertEquivalent( new ValidationResultTreeNode <ModelData> { { "CustomFields.S.Value", FormattedValidationResult.Error(new ValueRequiredText(), null, new SimplePathFormatterText { Paths = new[] { "CustomFields.S.Value" } }, 0) }, { "CustomFields.StrArr.Value.1", FormattedValidationResult.Error(null, "zzz", new SimplePathFormatterText { Paths = new[] { "CustomFields.StrArr.Value[1]" } }, 0) }, { "Items.0.CustomFields.S.Value", FormattedValidationResult.Error(new ValueRequiredText(), null, new SimplePathFormatterText { Paths = new[] { "Items[0].CustomFields.S.Value" } }, 0) }, } ); }
public void TestModelDataMutator() { var dataConfiguratorCollectionFactory = new TestDataConfiguratorCollectionFactory(); var dataConfiguratorCollection = new TestDataConfiguratorCollection <Data>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { configurator.Target(data => data.X).Set(data => data.Y + data.Z); configurator.Target(data => data.Items.Each().X).Set(data => data.Items.Current().Y + data.Items.Current().Z); } ); var modelDataConfiguratorCollection = new TestDataConfiguratorCollection <ModelData>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { }); dataConfiguratorCollectionFactory.Register(dataConfiguratorCollection); dataConfiguratorCollectionFactory.Register(new TestDataConfiguratorCollection <WebData>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { })); dataConfiguratorCollectionFactory.Register(modelDataConfiguratorCollection); var modelMutator = modelDataConfiguratorCollection.GetMutatorsTree(new[] { typeof(Data), typeof(WebData) }, new[] { MutatorsContext.Empty, MutatorsContext.Empty, MutatorsContext.Empty, }, new[] { MutatorsContext.Empty, MutatorsContext.Empty, }).GetTreeMutator(); var modelData = new ModelData { CustomFields = new Dictionary <string, CustomFieldValue> { { "X", new CustomFieldValue { Value = 0, TypeCode = TypeCode.Int32 } }, { "Y", new CustomFieldValue { Value = 1, TypeCode = TypeCode.Int32 } }, { "Z", new CustomFieldValue { Value = 2, TypeCode = TypeCode.Int32 } } }, Items = new[] { new ModelDataItem { CustomFields = new Dictionary <string, CustomFieldValue> { { "X", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 0 } }, { "Y", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 1 } }, { "Z", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 2 } } }, }, } }; modelMutator(modelData); Assert.AreEqual(3, modelData.CustomFields["X"].Value); Assert.AreEqual(3, modelData.Items[0].CustomFields["X"].Value); }
public void TestWebDataMutator() { LambdaCompiler.DebugOutputDirectory = @"c:\temp"; var dataConfiguratorCollectionFactory = new TestDataConfiguratorCollectionFactory(); var dataConfiguratorCollection = new TestDataConfiguratorCollection <Data>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { configurator.Target(data => data.X).Set(data => data.Y + data.Z); configurator.Target(data => data.Items.Each().X).Set(data => data.Items.Current().Y + data.Items.Current().Z); configurator.Target(data => data.Sum).Set(data => data.DecimalArr.Sum()); configurator.Target(data => data.ComplexArrSum).Set(data => data.ComplexArr.Sum(x => x.Y)); } ); var webDataConfiguratorCollection = new TestDataConfiguratorCollection <WebData>(dataConfiguratorCollectionFactory, converterCollectionFactory, pathFormatterCollection, configurator => { }); dataConfiguratorCollectionFactory.Register(dataConfiguratorCollection); dataConfiguratorCollectionFactory.Register(webDataConfiguratorCollection); var webMutator = webDataConfiguratorCollection.GetMutatorsTree <Data, WebData>(MutatorsContext.Empty, MutatorsContext.Empty, MutatorsContext.Empty).GetTreeMutator(); var webData = new WebData { CustomFields = new Lazy <Dictionary <string, CustomFieldValue> >(() => new Dictionary <string, CustomFieldValue> { { "X", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 0 } }, { "Y", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 1 } }, { "Z", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 2 } }, { "Sum", new CustomFieldValue { TypeCode = TypeCode.Decimal, Value = 0m } }, { "ComplexArrSum", new CustomFieldValue { TypeCode = TypeCode.Decimal, Value = 0m } }, { "DecimalArr", new CustomFieldValue { TypeCode = TypeCode.Decimal, IsArray = true, Value = new object[] { 1m, 2m, 3m } } }, { "ComplexArr", new CustomFieldValue { TypeCode = TypeCode.Object, IsArray = true, TypeCodes = new Dictionary <string, TypeCode> { { "Y", TypeCode.Decimal } }, Value = new[] { new Hashtable { { "Y", 1m }, }, new Hashtable { { "Y", 2m } } } } } }), Items = new[] { new WebDataItem { CustomFields = new Dictionary <string, CustomFieldValue> { { "X", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 0 } }, { "Y", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 1 } }, { "Z", new CustomFieldValue { TypeCode = TypeCode.Int32, Value = 2 } } }, }, } }; webMutator(webData); Assert.AreEqual(3, webData.CustomFields.Value["X"].Value); Assert.AreEqual(3, webData.Items[0].CustomFields["X"].Value); Assert.AreEqual(6m, webData.CustomFields.Value["Sum"].Value); Assert.AreEqual(3m, webData.CustomFields.Value["ComplexArrSum"].Value); }