Exemple #1
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);
        }
        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();
        }
Exemple #6
0
        public void AddManualMapWithFromTo([Frozen] Mock <IMapperConfiguration> configurationMock, Mapper.SetupMapping map)
        {
            map.FromTo <ClassAModel, ClassA>();

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