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); }
public void GetScopeName_Should_Return_Attribute_When_Parameter_Is_Empty() { // arrange var mapper = new ConfigurationPropertyMapper(new MockedConfiguration()); // act var scope = mapper.GetScopeName(new ScopedTestObject(), String.Empty); // assert Assert.Equal("ScopeTest", scope); }
public void GetScopeName_Should_Return_Parameter_Over_Attribute() { // arrange var mapper = new ConfigurationPropertyMapper(new MockedConfiguration()); // act var scope = mapper.GetScopeName(new ScopedTestObject(), "Test"); // assert Assert.Equal("Test", scope); }
public void Mapper_Should_Use_Scope_From_Parameter_Over_Attribute() { // arrange var mapper = new ConfigurationPropertyMapper(BuildSampleConfiguration()); var obj = new ScopedSampleObject(); // act mapper.Map(obj, "Scope2"); // assert Assert.Equal(obj.Key1, "Scope2Value1"); }
public void Mapper_Should_Determine_Key_From_AttributeValue() { // arrange var type = typeof(TestObject); var mapper = new ConfigurationPropertyMapper(new MockedConfiguration()); // act var propertyInfo = type.GetProperty("MappedStringValue"); var keyName = mapper.GetKeyName(propertyInfo); // assert Assert.Equal("StringValue", keyName); }
public void Mapper_Should_Map_Values_Without_Scope() { // arrange var config = BuildSampleConfiguration(); var obj = new SampleObject(); // act var mapper = new ConfigurationPropertyMapper(config); mapper.Map(obj); // assert Assert.Equal("Value1", obj.String1); Assert.Equal(new DateTime(1979, 1, 17, 20, 59, 0), obj.Date1); Assert.Null(obj.Key1); }
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); }
public void Mapper_Should_Map_Scoped_Values() { // arrange var config = BuildSampleConfiguration(); var obj = new SampleObject(); // act config = config.GetSubKey("Scope1"); var mapper = new ConfigurationPropertyMapper(config); mapper.Map(obj); // assert Assert.Null(obj.String1); Assert.Equal(DateTime.MinValue, obj.Date1); Assert.Equal(obj.Key1, "Scope1Value1"); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }