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" ); }
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)); }
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)); }
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" ); }
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)); }
public void InitialisingWithNullPropertyInfoShouldFail() { Assert.Throws <ArgumentNullException>( () => { var propertyGetter = new AutoMapperEnabledPropertyGetter <SourceType, string>( null, new MappingEngine(getBasicAutoMapperConfiguration()) ); }, "Constructor should throw an exception for null propertyInfo" ); }
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++; } }