public void ThrowExceptionOnSomePropertyNotConfiguredOrMapped()
        {
            var configuration = new MapperConfiguration {
                Scanner = { Enabled = false }
            };

            var setupMap = new Mapper.SetupMapping(configuration);

            configuration.AddConvention <SameNameIgnoreCaseConvention>();

            setupMap.FromTo <ValidatorTest1, ValidatorTest1Model>();

            configuration.Initialize();

            Assert.Throws <SomePropertiesNotMappedException>(() => configuration.AssertAllPropertiesMappedOnDestinationObjects());
        }
        public void NotThrowExceptionOnAllPropertiesConfigured()
        {
            var configuration = new MapperConfiguration {
                Scanner = { Enabled = false }
            };

            var setupMap = new Mapper.SetupMapping(configuration);

            configuration.AddConvention <SameNameIgnoreCaseConvention>();

            setupMap.FromTo <ValidatorTest1, ValidatorTest1Model>().Ignore(x => x.OtherProperty);

            configuration.Initialize();

            configuration.AssertAllPropertiesMappedOnDestinationObjects();
        }
        public void ThrowExceptionOnInitializeForMissingTypeMapWithAutomapDisabled()
        {
            var configuration = new MapperConfiguration {
                Scanner = { Enabled = false }, CreateMissingMapsAutomatically = false
            };

            var setupMap = new Mapper.SetupMapping(configuration);

            configuration.AddConvention <SameNameIgnoreCaseConvention>();

            setupMap.FromTo <ValidatorTest1, ValidatorTest1Model>().SetManually((s, d) => {
                d.OtherProperty = "Hejsan";
            }, x => x.OtherProperty);

            Assert.Throws <MapNotConfiguredException>(() => configuration.Initialize());
            Assert.Throws <MapperException>(() => configuration.AssertAllPropertiesMappedOnDestinationObjects());
        }
        public void NotThrowExceptionWhenManualSetHasBeenSpecified()
        {
            var configuration = new MapperConfiguration {
                Scanner = { Enabled = false }
            };

            var setupMap = new Mapper.SetupMapping(configuration);

            configuration.AddConvention <SameNameIgnoreCaseConvention>();

            setupMap.FromTo <ValidatorTest1, ValidatorTest1Model>().SetManually((s, d) => {
                d.OtherProperty = "Hejsan";
            }, x => x.OtherProperty);

            configuration.Initialize();

            configuration.AssertAllPropertiesMappedOnDestinationObjects();
        }
예제 #5
0
        public void SetPropertiesToIgnoreWhenMappingWithConventions([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            ManualMap <ClassAModel, ClassA> manualMap = null;

            configurationMock.Setup(
                x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()))
            .Callback <Type, Type, IPropertyMap>((a, b, c) => manualMap = (ManualMap <ClassAModel, ClassA>)c);

            map.FromTo <ClassAModel, ClassA>().Ignore(x => x.P1, x => x.P2);

            Assert.Contains("P1", manualMap.IgnoreProperties);
            Assert.Contains("P2", manualMap.IgnoreProperties);
        }
예제 #6
0
        public void SetManualMap([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            ManualMap <ClassAModel, ClassA> manualMap = null;

            configurationMock.Setup(
                x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()))
            .Callback <Type, Type, IPropertyMap>((a, b, c) => manualMap = (ManualMap <ClassAModel, ClassA>)c);

            map.From <ClassAModel>().To <ClassA>()
            .SetManually((s, d) =>
            {
                d.P1 = s.P1;
                d.P2 = s.P2;
                d.P3 = s.P3;
            });

            Assert.NotNull(manualMap.ObjectMap);
        }
예제 #7
0
        public void AddGenericConvention([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            map.WithConvention <SameNameIgnoreCaseConvention>();

            configurationMock.Verify(x => x.AddConvention(It.IsAny <Func <PropertyInfo[], PropertyInfo[], IEnumerable <object> > >()), Times.Once);
        }
예제 #8
0
        public void AddManualMapWithFromAndThenTo([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            map.From <ClassAModel>().To <ClassA>();

            configurationMock.Verify(x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()), Times.Once);
        }
예제 #9
0
        public void AddConventions([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            map.WithConvention(
                (s, d) =>
                from destination in d
                join source in s on destination.Name.ToLower() equals source.Name.ToLower()
                where source.CanRead && destination.CanWrite
                select new { source, destination });

            configurationMock.Verify(x => x.AddConvention(It.IsAny <Func <PropertyInfo[], PropertyInfo[], IEnumerable <object> > >()), Times.Once);
        }
예제 #10
0
        public void AddCustomConversion([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            ManualMap <ClassAModel, ClassA> manualMap = null;

            configurationMock.Setup(
                x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()))
            .Callback <Type, Type, IPropertyMap>((a, b, c) => manualMap = (ManualMap <ClassAModel, ClassA>)c);

            map.From <ClassAModel>().To <ClassA>()
            .WithCustomConversion <int, string>(i => i.ToString(CultureInfo.CurrentCulture));

            Assert.True(manualMap.Conversions.Count == 1);
        }
예제 #11
0
        public void AddCustomConventionUsingGenerics([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            ManualMap <ClassAModel, ClassA> manualMap = null;

            configurationMock.Setup(
                x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()))
            .Callback <Type, Type, IPropertyMap>((a, b, c) => manualMap = (ManualMap <ClassAModel, ClassA>)c);

            map.From <ClassAModel>().To <ClassA>().WithCustomConvention <SameNameIgnoreCaseConvention>();

            Assert.True(manualMap.Conventions.Count == 1);
        }
예제 #12
0
        public void AddCustomConvention([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            ManualMap <ClassAModel, ClassA> manualMap = null;

            configurationMock.Setup(
                x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()))
            .Callback <Type, Type, IPropertyMap>((a, b, c) => manualMap = (ManualMap <ClassAModel, ClassA>)c);

            map.From <ClassAModel>().To <ClassA>()
            .WithCustomConvention((s, d) =>
                                  from destination in d
                                  join source in s on destination.Name.ToLower() equals source.Name.ToLower()
                                  where source.CanRead && destination.CanWrite
                                  select new { source, destination });

            Assert.True(manualMap.Conventions.Count == 1);
        }
예제 #13
0
        public void AddMapsForInheritanceWithIncludeTo([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            map.From <ClassAModel>().To <ClassA>().IncludeTo <ClassB>();

            configurationMock.Verify(x => x.AddMap(It.IsAny <Type>(), It.IsAny <Type>(), It.IsAny <IPropertyMap>()), Times.Exactly(2));
        }