示例#1
0
        public async Task Automapping_should_work_with_enumerable()
        {
            //Arrange
            MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true));
            var fromObject = new FromObject()
            {
                Numbers = new [] { 1, 2, 3 }
            };

            //Act
            var toObject = await fromObject.ConvertAsync <ToObject>();

            //Assert
            toObject.Numbers.Should().Equal(new [] { 1, 2, 3 });
        }
示例#2
0
        public async Task Mapping_Should_Work_Reversed()
        {
            //Arrange
            MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true));
            var fromObject = new FromObject()
            {
                Name = "Testsson",
                Age  = 22
            };

            //Act
            var toObject = await fromObject.ConvertAsync <ToObject>();

            //Assert
            fromObject.Name.Should().Be(toObject.Name);
        }
示例#3
0
        public void Mapping_should_throw_if_fields_are_missing()
        {
            //Arrange
            MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, FailingToObject>(MappingPropertySource.Source));

            var fromObject = new FromObject()
            {
                Name = "Testsson",
                Age  = 22
            };

            //Act
            Func <Task> tryToConvert = async() => await fromObject.ConvertAsync <FailingToObject>();

            //Assert
            tryToConvert.Should().Throw <KeyNotFoundException>();
        }
示例#4
0
        public async Task Automapping_should_work_with_enums()
        {
            //Arrange
            MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true));
            var fromObject = new FromObject()
            {
                Name      = "Testsson",
                EnumValue = "Yes",
                Age       = 22
            };

            //Act
            var toObject = await fromObject.ConvertAsync <ToObject>();

            //Assert
            toObject.TestValue.Should().Be(TestEnum.Yes);
        }
示例#5
0
        public async Task Mapping_Should_Work_With_Wrapped_Elements()
        {
            //Arrange
            MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true));
            MappingHandler.AddMapping <string, WrappedValue>((source) => new WrappedValue()
            {
                Value = source
            });
            var fromObject = new FromObject()
            {
                Name         = "Testsson",
                WrappedValue = "inner value",
                Age          = 22
            };

            //Act
            var toObject = await fromObject.ConvertAsync <ToObject>();

            //Assert
            fromObject.WrappedValue.Should().Be(toObject.WrappedValue.Value);
        }
示例#6
0
        public async Task Automapping_should_work_with_dictionaries()
        {
            //Arrange
            MappingHandler.AddMapping(MappingHandler.AutoConverter <FromObject, ToObject>(MappingPropertySource.Target, requireAllProperties: true));
            var fromObject = new FromObject()
            {
                Table = new Dictionary <int, string> {
                    { 1, "1" },
                    { 2, "2" },
                    { 3, "3" }
                }
            };

            //Act
            var toObject = await fromObject.ConvertAsync <ToObject>();

            //Assert
            toObject.Table.Should().Equal(new Dictionary <int, string> {
                { 1, "1" },
                { 2, "2" },
                { 3, "3" }
            });
        }