コード例 #1
0
        public void RetrieveIntValue_AsSourceType()
        {
            var mappingConfig = getBasicAutoMapperConfiguration();

            mappingConfig.CreateMap <int, SourceType>().ConstructUsing(x => new SourceType()
            {
                IntValue = x
            });
            var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, SourceType>(
                typeof(SourceType).GetProperty("IntValue"),
                new MappingEngine(mappingConfig)
                );
            var src = new SourceType()
            {
                IntValue = 3
            };
            var result = propertyGetter.GetValue(src);

            Assert.IsNotNull(result, "Converted property value should not be null");
            Assert.AreEqual(3, result.IntValue);
            Assert.True(
                Common.DoSerialisableObjectsHaveMatchingContent(
                    new SourceType()
            {
                IntValue = 3
            },
                    result
                    ),
                "Converted property value has unexpected data set"
                );
        }
コード例 #2
0
        public void RetrieveIntValueList_1_2_3_NoConversion()
        {
            var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, int[]>(
                typeof(SourceType).GetProperty("IntValueList"),
                new MappingEngine(getBasicAutoMapperConfiguration())
                );
            var src = new SourceType()
            {
                IntValueList = new[] { 1, 2, 3 }
            };

            Assert.AreEqual(new[] { 1, 2, 3 }, propertyGetter.GetValue(src));
        }
コード例 #3
0
        public void RetrieveIntValue_NoConversion()
        {
            var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, int>(
                typeof(SourceType).GetProperty("IntValue"),
                new MappingEngine(getBasicAutoMapperConfiguration())
                );
            var src = new SourceType()
            {
                IntValue = 3
            };

            Assert.AreEqual(3, propertyGetter.GetValue(src));
        }
コード例 #4
0
 public void InitialisingWithNullMappingEngineShouldFail()
 {
     Assert.Throws <ArgumentNullException>(
         () =>
     {
         var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, string>(
             typeof(SourceType).GetProperty("IntValue"),
             null
             );
     },
         "Constructor should throw an exception for null mappingEngine"
         );
 }
コード例 #5
0
        public void RetrieveIntValueList_Null_AsStringArray()
        {
            var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, IEnumerable <string> >(
                typeof(SourceType).GetProperty("IntValueList"),
                new MappingEngine(getBasicAutoMapperConfiguration())
                );
            var src = new SourceType()
            {
                IntValueList = null
            };

            Assert.AreEqual(null, propertyGetter.GetValue(src));
        }
コード例 #6
0
 public void InitialisingWithNullPropertyInfoShouldFail()
 {
     Assert.Throws <ArgumentNullException>(
         () =>
     {
         var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, string>(
             null,
             new MappingEngine(getBasicAutoMapperConfiguration())
             );
     },
         "Constructor should throw an exception for null propertyInfo"
         );
 }
コード例 #7
0
        public void RetrieveIntValueList_1_2_3_AsSourceTypeArray()
        {
            var mappingConfig = getBasicAutoMapperConfiguration();

            mappingConfig.CreateMap <int, SourceType>().ConstructUsing(x => new SourceType()
            {
                IntValue = x
            });
            var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, IEnumerable <SourceType> >(
                typeof(SourceType).GetProperty("IntValueList"),
                new MappingEngine(mappingConfig)
                );
            var src = new SourceType()
            {
                IntValueList = new[] { 1, 2, 3 }
            };
            var result = propertyGetter.GetValue(src);

            Assert.IsNotNull(result, "Converted property value should not be null");
            Assert.AreEqual(3, result.Count(), "Resulting IEnumerable<SourceType> should have three entries");
            var index = 0;

            foreach (var resultEntry in result)
            {
                var expectedIntValue = index + 1;
                Assert.AreEqual(expectedIntValue, resultEntry.IntValue, "Index " + index.ToString() + ": Unexpected IntValue");
                Assert.True(
                    Common.DoSerialisableObjectsHaveMatchingContent(
                        new SourceType()
                {
                    IntValue = expectedIntValue
                },
                        resultEntry
                        ),
                    "Index " + index.ToString() + ": Converted property value has unexpected data set"
                    );
                index++;
            }
        }