コード例 #1
0
        public void Map_PassedTAndNoConstructor_ReturnsMappedObject()
        {
            // arrange
            var converter = new TestObjectMapper();

            // act
            var orange = converter.CreateInstance(new Apple {
                Type = "TEST"
            });

            // assert
            Assert.AreEqual("TEST", orange.Type);
        }
コード例 #2
0
        public void DefineMap_PassedMappingConfiguration_CallsCreateMapOnMappingConfiguration()
        {
            // arrange
            var converter = new TestObjectMapper(new Mock <IMappingEngine>().Object);

            var configurationFake = new Mock <IConfiguration>();

            // act
            converter.DefineMap(configurationFake.Object);

            // assert
            configurationFake.Verify(x => x.CreateMap <Apple, Orange>(), Times.Once());
        }
コード例 #3
0
        public void Map_PassedEnumerableT_ReturnsEnumerableFromAutoMapper()
        {
            // arrange
            var mappingEngineFake = new Mock <IMappingEngine>();

            mappingEngineFake.Setup(x => x.Map <Apple, Orange>(It.IsAny <Apple>()))
            .Returns(new Orange());

            var converter = new TestObjectMapper(mappingEngineFake.Object);

            // act
            var oranges = converter.CreateSet(new[] { new Apple(), new Apple(), new Apple() });

            // assert
            Assert.AreEqual(3, oranges.Count());
        }
コード例 #4
0
        public void Map_PassedTAndOutVariable_SetsOutValueToMappedResult()
        {
            // arrange
            var expectedOrange = new Orange();

            var apple  = new Apple();
            var orange = new Orange();

            var mappingEngineFake = new Mock <IMappingEngine>();

            var converter = new TestObjectMapper(mappingEngineFake.Object);

            // act
            converter.LoadIntoInstance(apple, orange);

            // assert
            mappingEngineFake.Verify(x => x.Map(apple, orange), Times.Once());
        }
コード例 #5
0
        public void Map_PassedTAndMappingConfigurationInConstructor_ReturnsMappedObject()
        {
            // arrange

            var mappingConfiguration = ConfigurationHelpers.CreateDefaultConfiguration();

            mappingConfiguration.CreateMap <Apple, Orange>();

            var converter = new TestObjectMapper(mappingConfiguration);

            // act
            var orange = converter.CreateInstance(new Apple {
                Type = "TEST"
            });

            // assert
            Assert.AreEqual("TEST", orange.Type);
        }
コード例 #6
0
        public void Map_PassedT_ReturnsResultFromAutoMapper()
        {
            // arrange
            var expectedOrange = new Orange();

            var apple = new Apple();

            var mappingEngineFake = new Mock <IMappingEngine>();

            mappingEngineFake.Setup(x => x.Map <Apple, Orange>(apple))
            .Returns(expectedOrange);

            var converter = new TestObjectMapper(mappingEngineFake.Object);

            // act
            var orange = converter.CreateInstance(apple);

            // assert
            Assert.AreSame(expectedOrange, orange);
        }