示例#1
0
        public void ComplexObjectDescriptorSimpleTestWithMissingDescriptor()
        {
            var data = Mockup.Data.GetComplexTwoLevelMockupData();

            var factory = new FlatDTO.FlatDTOFactory();

            var propertyString = Mockup.Data.GetComplexTwoLevelMockupDataPropertyStrings().ToList();

            propertyString.Add("ComplexProperty");

            var mapper = factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString.ToArray(), GetMappingEngine());
            var dtoList = mapper.Map(data.ToArray());

            Assert.IsTrue(dtoList.Count() == 2);

            var value = dtoList[0];
            var rootType = value.GetType();
            Assert.IsTrue(((string)rootType.GetProperty(propertyString[0]).GetValue(value, null)).Equals(data[0].StringValue, StringComparison.InvariantCultureIgnoreCase), "The string property was not correct");
            Assert.IsTrue(((decimal)rootType.GetProperty(propertyString[1]).GetValue(value, null)) == data[0].DecimalValue, "The decimal property was not correct");
            Assert.IsTrue(((int)rootType.GetProperty(propertyString[2]).GetValue(value, null)) == data[0].IntegerValue, "The int property was not correct");

            //Get the complex property
            var propertyPath = propertyString[3].Replace(".", "_");

            var property = rootType.GetProperty(propertyPath);

            Assert.IsTrue(((string)property.GetValue(value, null)).Equals(data[0].ComplexProperty.StringValue, StringComparison.InvariantCultureIgnoreCase), "The value on Complex type on level 1 do not match");

            propertyPath = propertyString[4].Replace(".", "_");

            property = rootType.GetProperty(propertyPath);

            Assert.IsTrue(((string)property.GetValue(value, null)).Equals(data[0].ComplexProperty.ComplexProperty.StringValue, StringComparison.InvariantCultureIgnoreCase), "The value on Complex type on level 2 do not match");
        }
示例#2
0
        public void DummyMapperExtensionTest()
        {
            var factory = new FlatDTO.FlatDTOFactory();
            var properties = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();
            var data = Mockup.Data.GetSimpleOneLevelMockupData();
            var mapper = factory.Create<Mockup.Data.FlatDataType>(data[0].GetType(), properties, new Mockup.DummyMapperFlatEngineExtension());

            Assert.IsTrue(mapper.DestinationType.FullName.Contains("mjau"));
        }
示例#3
0
        public void FlatMapperEngineWithRepeaterTestWithMultipleLineInstructions()
        {
            var factory = new FlatDTO.FlatDTOFactory();
            var properties = Mockup.Data.GetComplexTwoLevelListMockupDataPropertyStrings().ToList();

            properties.Add("ComplexPropertyList2.ComplexProperty.StringValue");
            var data = Mockup.Data.GetComplexTwoLevelMockupData();
            var mapper = factory.Create<Mockup.Data.FlatDataType>(data[0].GetType(), properties.ToArray(),
                                                                    new FlatDTO.MappingEngine.FlatMapperEngineWithRepeater());
            var result = mapper.Map(data);
        }
        public void RunMapperComplexEntityToFlatDTOWithComplexPropertiesAndSingleMapListProperty()
        {
            var data = Mockup.Data.GetComplexTwoLevelMockupData();

            var factory = new FlatDTO.FlatDTOFactory();

            var propertyString = Mockup.Data.GetComplexTwoLevelListMockupDataPropertyStrings().Where(x => x =="ComplexPropertyList.StringValue").ToArray();

            var mapper = factory.Create<Mockup.Data.DTOBaseEmpty>(data[0].GetType(), propertyString, GetMappingEngine());
            var dtoList = mapper.Map(data.ToArray());

            Assert.IsTrue(dtoList.Count() == 4);
        }
示例#5
0
        public void FlatMapperEngineWithRepeaterTestRegularRepeater()
        {
            var factory = new FlatDTO.FlatDTOFactory();
            var properties = Mockup.Data.GetComplexTwoLevelListMockupDataPropertyStrings();
            var data = Mockup.Data.GetComplexTwoLevelMockupData();
            var mapper = factory.Create<Mockup.Data.FlatDataType>(data[0].GetType(), properties,
                                                                    new FlatDTO.MappingEngine.FlatMapperEngineWithRepeater());

            //Data records sent in is 2
            var result = mapper.Map(data);
            //Result is 22, the DummyMapperEngine uses another mapper that returns static 10 items per item sent in
            Assert.IsTrue(result.Count() == 4);

            var property = result[0].GetType().GetProperty("ComplexPropertyList_ComplexProperty_StringValue");
            var value = ((string)property.GetValue(result[0], null));

            Assert.IsTrue(String.Equals(value, "LineComplexValue1"));

            property = result[0].GetType().GetProperty("ComplexPropertyList_StringValue");
            value = ((string)property.GetValue(result[0], null));

            Assert.IsTrue(String.Equals(value, "Line1"));
        }
示例#6
0
        public void VerifyThatCacheWorksWithPolymorficInstruction()
        {
            var data = Mockup.Data.GetComplexTwoLevelMockupDataPolymorfic();
            var propertyStringPoly = Mockup.Data.GetComplexTwoLevelMockupDataPropertyStringsPolymorfic();

            var manualPolymorfic = new List<PolymorficTypeConverterInstruction>();

            manualPolymorfic.Add(new PolymorficTypeConverterInstruction("ComplexProperty", typeof(Mockup.Data.ComplexPropertyLevel12)));

            var factory = new FlatDTO.FlatDTOFactory();

            _cacheHit = 0;
            _compileHit = 0;
            factory.CacheHit += new EventHandler(factory_CacheHit);
            factory.Compiling += new EventHandler(factory_Compiling);

            //Run 1
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyStringPoly, GetMappingEngine(), manualPolymorfic);

            //Run 2
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyStringPoly, GetMappingEngine(), manualPolymorfic);

            var propertyString = Mockup.Data.GetComplexTwoLevelMockupDataPropertyStrings();

            //Run 3
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());

            //Run 4
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyStringPoly, GetMappingEngine(), manualPolymorfic);

            Assert.IsTrue(_compileHit == 2, string.Format("The compile hit event was fired {0}, should be {1}", _compileHit, 2));
            Assert.IsTrue(_cacheHit == 2, string.Format("The cache event was fired {0}, should be {1}", _cacheHit, 2));

            Assert.IsTrue(factory.RegisteredMappers.Count() == 2, "The number of mappers are larger than 2");
        }
示例#7
0
        public void VerifyThatCacheWorks()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();
            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            var factory = new FlatDTO.FlatDTOFactory();

            _cacheHit = 0;
            _compileHit = 0;
            factory.CacheHit += new EventHandler(factory_CacheHit);
            factory.Compiling += new EventHandler(factory_Compiling);

            //Run 1
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());

            //Run 2
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());

            //Run 3
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());

            Assert.IsTrue(_compileHit == 1, "The compile hit event was not 1");
            Assert.IsTrue(_cacheHit == 2, "The cache event was not fired");

            Assert.IsTrue(factory.RegisteredMappers.Count() == 1, "More then one mapper have been created, should be 1");
        }
示例#8
0
        public void TestThatTheCacheIsFasterThenCompiling()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();
            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            var factory = new FlatDTO.FlatDTOFactory();

            var start = DateTime.Now;
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());
            var resultBase = GetDiffms(start, DateTime.Now);

            start = DateTime.Now;
            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());
            var result = GetDiffms(start, DateTime.Now);

            Assert.IsTrue(result < resultBase, "The timing cache result is {0}, the compile result is {1}", result, resultBase);
        }
示例#9
0
        public void RunSingleMapperFlatEntityToFlatDTOWithSimplePropertiesInLevel0()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();

            var factory = new FlatDTO.FlatDTOFactory();

            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            var mapper = factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());
            var dto = mapper.Map(data[0]);

            Assert.IsTrue(((string)dto.GetType().GetProperty(propertyString[0]).GetValue(dto, null)).Equals(data[0].StringValue, StringComparison.InvariantCultureIgnoreCase), "The string property was not correct");
            Assert.IsTrue(((decimal)dto.GetType().GetProperty(propertyString[1]).GetValue(dto, null)) == data[0].DecimalValue, "The decimal property was not correct");
            Assert.IsTrue(((int)dto.GetType().GetProperty(propertyString[2]).GetValue(dto, null)) == data[0].IntegerValue, "The int property was not correct");
        }
示例#10
0
        public void RunMapperFlatEntityToFlatDTOWithSimplePropertiesInLevel0WithNonExistingProperty()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();

            var factory = new FlatDTO.FlatDTOFactory();

            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            propertyString[2] = propertyString[2] + "XYZ";

            var mapper = factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());
            var dtoList = mapper.Map(data.ToArray());

            Assert.IsTrue(dtoList.Count() == 2);

            var value = dtoList[0];
            Assert.IsTrue(((string)value.GetType().GetProperty(propertyString[0]).GetValue(value, null)).Equals(data[0].StringValue, StringComparison.InvariantCultureIgnoreCase), "The string property was not correct");
            Assert.IsTrue(((decimal)value.GetType().GetProperty(propertyString[1]).GetValue(value, null)) == data[0].DecimalValue, "The decimal property was not correct");
            Assert.IsTrue(((int)value.GetType().GetProperty(propertyString[2]).GetValue(value, null)) == data[0].IntegerValue, "The int property was not correct");
        }
示例#11
0
        public void RunMapperComplexEntityToFlatDTOWithComplexPropertiesLevel1And2AndManualPolymorficInstruction()
        {
            var data = Mockup.Data.GetComplexTwoLevelMockupDataPolymorfic();

            var factory = new FlatDTO.FlatDTOFactory();

            var propertyString = Mockup.Data.GetComplexTwoLevelMockupDataPropertyStringsPolymorfic();

            var manualPolymorfic = new List<PolymorficTypeConverterInstruction>();

            manualPolymorfic.Add(new PolymorficTypeConverterInstruction("ComplexProperty", typeof(Mockup.Data.ComplexPropertyLevel12)));

            var mapper = factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine(), manualPolymorfic);
            var dtoList = mapper.Map((object[])data.ToArray());

            Assert.IsTrue(dtoList.Count() == 2);

            var value = dtoList[0];
            var rootType = value.GetType();
            Assert.IsTrue(((string)rootType.GetProperty(propertyString[0]).GetValue(value, null)).Equals(data[0].StringValue, StringComparison.InvariantCultureIgnoreCase), "The string property was not correct");
            Assert.IsTrue(((decimal)rootType.GetProperty(propertyString[1]).GetValue(value, null)) == data[0].DecimalValue, "The decimal property was not correct");
            Assert.IsTrue(((int)rootType.GetProperty(propertyString[2]).GetValue(value, null)) == data[0].IntegerValue, "The int property was not correct");

            //Get the complex property
            var propertyPath = propertyString[3].Replace(".", "_");

            var property = rootType.GetProperty(propertyPath);

            Assert.IsTrue(((string)property.GetValue(value, null)).Equals(data[0].ComplexProperty.StringValue, StringComparison.InvariantCultureIgnoreCase), "The value on Complex type on level 1 do not match");

            //Check the polymorfic string
            propertyPath = propertyString[4].Replace(".", "_");

            property = rootType.GetProperty(propertyPath);

            Assert.IsTrue(((string)property.GetValue(value, null)).Equals(((Mockup.Data.ComplexPropertyLevel12)data[0].ComplexProperty).PolymorficString, StringComparison.InvariantCultureIgnoreCase), "The value on the polymorfic string at Complex type on level 2 do not match");
        }
示例#12
0
        public void FlatDTOSaveAssemblyNotImplemented()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();

            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            var factory = new FlatDTO.FlatDTOFactory();

            var mapper = factory.Create<Mockup.Data.DTOBase>(typeof(Mockup.Data.FlatDataType), propertyString, GetMappingEngine());
            var dtoList = mapper.Map(data.ToArray());
            factory.SaveMappersToDisk();
        }
示例#13
0
        public void FlatDTOMappingEngineUnMapNotImplemented()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();

            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            var factory = new FlatDTO.FlatDTOFactory();

            var mapper = factory.Create<Mockup.Data.DTOBase>(typeof(Mockup.Data.FlatDataType), propertyString, GetMappingEngine());
            var dtoList = mapper.Map(data.ToArray());
            mapper.UnMap<Mockup.Data.FlatDataType>(dtoList);

            Assert.IsTrue(dtoList.Count() == 0);
        }
示例#14
0
        public void CreateMethodPropertyInputNull()
        {
            var factory = new FlatDTO.FlatDTOFactory();

            factory.Create<Mockup.Data.DTOBase>(null, null, GetMappingEngine());
        }
示例#15
0
        public void CreateMethodPropertyInputEmptyPropertyArray()
        {
            var data = Mockup.Data.GetSimpleOneLevelMockupData();

            var propertyString = new string[] { };

            var factory = new FlatDTO.FlatDTOFactory();

            factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());
        }
示例#16
0
        public void CreateMethodPropertyInputEmptyDataArray()
        {
            var data = new object[] { };

            var propertyString = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();

            var factory = new FlatDTO.FlatDTOFactory();

            var mapper = factory.Create<Mockup.Data.DTOBase>(typeof(Mockup.Data.FlatDataType), propertyString, GetMappingEngine());
            var dtoList = mapper.Map((object[])data.ToArray());

            Assert.IsTrue(dtoList.Count() == 0);
        }
示例#17
0
        public void RunMapperComplexEntityToFlatDTOWithComplexPropertiesAndListPropertyLevel1And2()
        {
            var data = Mockup.Data.GetComplexTwoLevelMockupData();

            var factory = new FlatDTO.FlatDTOFactory();

            var propertyString = Mockup.Data.GetComplexTwoLevelListMockupDataPropertyStrings();

            var mapper = factory.Create<Mockup.Data.DTOBase>(data[0].GetType(), propertyString, GetMappingEngine());
            var dtoList = mapper.Map(data.ToArray());

            if(!(mapper.MapperEngine is FlatDTO.MappingEngine.FlatMapperEngineWithRepeater))
                Assert.IsTrue(dtoList.Count() == 2);

            var value = dtoList[0];
            var rootType = value.GetType();
            Assert.IsTrue(((string)rootType.GetProperty(propertyString[0]).GetValue(value, null)).Equals(data[0].StringValue, StringComparison.InvariantCultureIgnoreCase), "The string property was not correct");
            Assert.IsTrue(((decimal)rootType.GetProperty(propertyString[1]).GetValue(value, null)) == data[0].DecimalValue, "The decimal property was not correct");
            Assert.IsTrue(((int)rootType.GetProperty(propertyString[2]).GetValue(value, null)) == data[0].IntegerValue, "The int property was not correct");

            //Get the complex property
            var propertyPath = propertyString[3].Replace(".", "_");

            var property = rootType.GetProperty(propertyPath);

            Assert.IsTrue(((string)property.GetValue(value, null)).Equals(data[0].ComplexProperty.StringValue, StringComparison.InvariantCultureIgnoreCase), "The value on Complex type on level 1 do not match");

            propertyPath = propertyString[4].Replace(".", "_");

            property = rootType.GetProperty(propertyPath);

            Assert.IsTrue(((string)property.GetValue(value, null)).Equals(data[0].ComplexProperty.ComplexProperty.StringValue, StringComparison.InvariantCultureIgnoreCase), "The value on Complex type on level 2 do not match");
        }
示例#18
0
        public void UseCustomMapperToVerify1ObjectToMany()
        {
            var factory = new FlatDTO.FlatDTOFactory();
            var properties = Mockup.Data.GetSimpleOneLevelMockupDataPropertyStrings();
            var data = Mockup.Data.GetSimpleOneLevelMockupData();
            var mapper = factory.Create<Mockup.Data.FlatDataType>(data[0].GetType(), properties,
                                                                    new Mockup.DummyMapperEngine());

            //Data records sent in is 2
            var result = mapper.Map(data);
            //Result is 22, the DummyMapperEngine uses another mapper that returns static 10 items per item sent in
            Assert.IsTrue(result.Count() > 21);
        }