Пример #1
0
        public void DefaultCreators_CustomCreator()
        {
            var creator = new Mock <IMemberConsumer>();

            Map.AcceptOverrides(new OverrideDefaultCreators <CloneableTestContext>(new[] { creator.Object }).OverrideMapping);
            Assert.Throws <UnmappedMembersException>(() => InvokeMapper(new ClassWithSeveralPropertiesSrc(), new ClassWithSeveralPropertiesDest()));
            creator.Verify(c => c.CreateMap(It.IsAny <IMappingCollection <ClassWithSeveralPropertiesSrc, ClassWithSeveralPropertiesDest, CloneableTestContext> >()));
        }
Пример #2
0
        public void Map_IgnoredAllProperties_NoExceptionThrown()
        {
            Map.AcceptOverrides(new IgnoreAllDefaultCreators <ClassWithSeveralPropertiesSrc, ClassWithSeveralPropertiesDest, CloneableTestContext>().OverrideMapping);
            Map.Initialize();
            var mapper = Map.GetMapper(typeof(ClassWithSeveralPropertiesSrc), typeof(ClassWithSeveralPropertiesDest));

            Assert.IsNotNull(mapper);
            Assert.DoesNotThrow(() => mapper.Invoke(null, new object(), null));
        }
Пример #3
0
        public void DefaultCreators_Null_UsesDefaultMapper()
        {
            Map.AcceptOverrides(new OverrideDefaultCreators <CloneableTestContext>(null).OverrideMapping);
            var destObject = InvokeMapper(new ClassWithSeveralPropertiesSrc(), new ClassWithSeveralPropertiesDest());

            Assert.IsNotNull(destObject);
            Assert.AreEqual(0, destObject.Property1);
            Assert.AreEqual(0, destObject.Property2);
            Assert.AreEqual(0, destObject.Property3);
        }
Пример #4
0
        public void SetOrder_IsPreserved()
        {
            Map.AcceptOverrides(new ClassWithSeveralPropertiesOverride <CloneableTestContext>().OverrideMapping);
            var destObject = InvokeMapper(new ClassWithSeveralPropertiesSrc(), new ClassWithSeveralPropertiesDest());

            Assert.IsNotNull(destObject);
            Assert.AreEqual(0, destObject.Property2);
            Assert.AreEqual(1, destObject.Property1);
            Assert.AreEqual(2, destObject.Property3);
        }
Пример #5
0
        public void Map_ChangesContext_NewContextReceivedInChildMapper()
        {
            var originalContext = new CloneableTestContext();

            Map.AcceptOverrides(new AssertsClonedContext(originalContext).OverrideMapping);
            Map.Initialize();
            var mapper = Map.GetMapper(typeof(ClassWithSeveralPropertiesSrc), typeof(ClassWithSeveralPropertiesDest));

            Assert.IsNotNull(mapper);
            InvokeMapper(new ClassWithSeveralPropertiesSrc(), new ClassWithSeveralPropertiesDest(), originalContext);
        }
Пример #6
0
 public void DefaultCreators_EmptyList_OverridesResourceMapper()
 {
     Map.AcceptOverrides(new OverrideDefaultCreators <CloneableTestContext>(new IMemberConsumer[0]).OverrideMapping);
     Assert.Throws <UnmappedMembersException>(() => InvokeMapper(new ClassWithSeveralPropertiesSrc(), new ClassWithSeveralPropertiesDest()));
 }