Exemplo n.º 1
0
        public void Mapper_Should_Not_Change_Defaults_With_No_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            var obj = new TestObject()
            {
                StringValue = "Default",
                IntValue    = 42,
                FloatValue  = 3.14159265359,
                DateValue   = new DateTime(1979, 01, 17, 20, 59, 00),
                BoolValue   = true,
                CharValue   = 'a',
                ByteValue   = 128,
                EnumValue   = TestEnum.Mon,
            };

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal("Default", obj.StringValue);
            Assert.Equal(42, obj.IntValue);
            Assert.InRange(obj.FloatValue, 3.141500, 3.141599);
            Assert.Equal(new DateTime(1979, 01, 17, 20, 59, 00), obj.DateValue);
            Assert.True(obj.BoolValue);
            Assert.Equal('a', obj.CharValue);
            Assert.Equal(128, obj.ByteValue);
            Assert.Equal(TestEnum.Mon, obj.EnumValue);
            Assert.Equal(null, obj.MappedStringValue);
        }
Exemplo n.º 2
0
        public void Mapper_Should_Not_Fail_On_Not_Existing_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("OtherValue", "OtherValue");

            var obj = new TestObject();

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);             // should not throw exception

            // assert
            Assert.True(true);
        }
Exemplo n.º 3
0
        public void Mapper_Should_Map_Enum_Values_By_Value()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("EnumValue", "3");

            var obj = new TestObject();

            Assert.Equal(default(TestEnum), obj.EnumValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal(TestEnum.Wed, obj.EnumValue);
        }
Exemplo n.º 4
0
        public void Mapper_Should_Map_Byte_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("ByteValue", "255");

            var obj = new TestObject();

            Assert.Equal(default(byte), obj.ByteValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal(255, obj.ByteValue);
        }
Exemplo n.º 5
0
        public void Mapper_Should_Map_Char_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("CharValue", "b");

            var obj = new TestObject();

            Assert.Equal(default(char), obj.CharValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal('b', obj.CharValue);
        }
Exemplo n.º 6
0
        public void Mapper_Should_Map_Bool_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("BoolValue", "true");

            var obj = new TestObject();

            Assert.False(obj.BoolValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.True(obj.BoolValue);
        }
Exemplo n.º 7
0
        public void Mapper_Should_Map_DateTime_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("DateValue", "1979-01-17T20:59:00");

            var obj = new TestObject();

            Assert.Equal(DateTime.MinValue, obj.DateValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal(new DateTime(1979, 01, 17, 20, 59, 00), obj.DateValue);
        }
Exemplo n.º 8
0
        public void Mapper_Should_Map_Float_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("FloatValue", "3.14159265359");

            var obj = new TestObject();

            Assert.Equal(0.0D, obj.FloatValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.InRange(obj.FloatValue, 3.141500, 3.141599);
        }
Exemplo n.º 9
0
        public void Mapper_Should_Map_Integer_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("IntValue", "42");

            var obj = new TestObject();

            Assert.Equal(0, obj.IntValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal(42, obj.IntValue);
        }
Exemplo n.º 10
0
        public void Mapper_Should_Map_Empty_String_Values()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("StringValue", String.Empty);

            var obj = new TestObject();

            Assert.Null(obj.StringValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal(String.Empty, obj.StringValue);
        }
Exemplo n.º 11
0
        public void Mapper_Should_Map_Values_For_Attributed_Key()
        {
            // arrange
            var config = new MockedConfiguration();

            config.TestData.Add("StringValue", "TestValue");

            var obj = new TestObject();

            Assert.Equal(default(TestEnum), obj.EnumValue);

            // act
            var mapper = new ConfigurationPropertyMapper(config);

            mapper.Map(obj);

            // assert
            Assert.Equal("TestValue", obj.StringValue);
            Assert.Equal("TestValue", obj.MappedStringValue);
        }