Ejemplo n.º 1
0
        public void CustomeNameMatching_Success()
        {
            TinyMapper.Config(config =>
            {
                config.NameMatching((x, y) => string.Equals(x + "1", y, StringComparison.OrdinalIgnoreCase));
            });

            var sourceCustom = new SourceCustom {
                Custom = "Hello", Default = "Default"
            };
            var targetCustom = TinyMapper.Map <TargetCustom>(sourceCustom);

            Assert.Equal(sourceCustom.Custom, targetCustom.Custom1);
            Assert.True(string.IsNullOrEmpty(targetCustom.Default));

            TinyMapper.Config(config =>
            {
                config.Reset();
            });

            var sourceDefault = new SourceDefault {
                Custom = "Hello", Default = "Default"
            };
            var targetDefault = TinyMapper.Map <TargetDefault>(sourceDefault);

            Assert.True(string.IsNullOrEmpty(targetDefault.Custom1));
            Assert.Equal(sourceDefault.Default, targetDefault.Default);
        }
Ejemplo n.º 2
0
        public void DisablePolymorphicMappingTest()
        {
            // Arrange
            TinyMapper.Config(n =>
            {
                n.EnablePolymorphicMapping = false;
            });

            SourceB source = new SourceB
            {
                FirstName = "John",
                LastName  = "Doe",
                Age       = 37
            };

            TargetA target = null;

            // This binding will be ignored because it will not be recognised as a binding for these types
            TinyMapper.Bind <SourceA, TargetA>(n => n.Bind(from => from.FirstName, to => to.Name));

            // Act
            target = TinyMapper.Map <TargetA>(source);

            // Assert
            Assert.NotEqual(source.FirstName, target.Name);
        }
Ejemplo n.º 3
0
        public void CustomeNameMatching_IsIsolated()
        {
            TestDomain.DoCallBack(() => {
                TinyMapper.Config(config =>
                {
                    config.NameMatching((x, y) => string.Equals(x + "1", y, StringComparison.OrdinalIgnoreCase));

                    TinyMapper.Bind <SourceCustom, TargetCustom>();
                    var sourceCustomOtherDomain = new SourceCustom {
                        Custom = "Hello", Default = "Default"
                    };
                    var targetCustomOtherDomain = TinyMapper.Map <TargetCustom>(sourceCustomOtherDomain);

                    Assert.Equal(sourceCustomOtherDomain.Custom, targetCustomOtherDomain.Custom1);
                    Assert.True(string.IsNullOrEmpty(targetCustomOtherDomain.Default));
                });
            });

            TinyMapper.Bind <SourceCustom, TargetCustom>();
            var sourceCustom = new SourceCustom {
                Custom = "Hello", Default = "Default"
            };
            var targetCustom = TinyMapper.Map <TargetCustom>(sourceCustom);

            TinyMapper.Bind <SourceDefault, TargetDefault>();
            var sourceDefault = new SourceDefault {
                Custom = "Hello", Default = "Default"
            };
            var targetDefault = TinyMapper.Map <TargetDefault>(sourceDefault);

            Assert.True(string.IsNullOrEmpty(targetDefault.Custom1));
            Assert.Equal(sourceDefault.Default, targetDefault.Default);
        }
Ejemplo n.º 4
0
        public void ReversePolymorphicShouldFailWithException()
        {
            // Arrange
            TinyMapper.Config(n => n.EnableAutoBinding = false);

            SourceB source = new SourceB
            {
                FirstName = "John",
                LastName  = "Doe",
                Age       = 37
            };

            // Act / Assert
            Assert.Throws <MappingException>(() => TinyMapper.Map <TargetB>(source));
        }