public void Multiple_Formats2_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<TestObj>(o => o.MyDateTime.ToShortTimeString())); x.Add(new ExpressionFormatter<DateTime>(o => o.ToShortDateString())); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual(new DateTime(2011, 1, 1, 12, 1, 1).ToShortTimeString(), propertyNameAndValues["MyDateTime"]); Assert.AreEqual(new DateTime(2011, 2, 2, 12, 2, 2).ToShortDateString(), propertyNameAndValues["Sub.SubDateTime"]); }
public void Multiple_Formats_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<TestObj>(o => o.MyString + " I'm the exception", o => o.MyDateTime.ToShortTimeString())); x.Add(new ExpressionFormatter<string>(o => o + " hello world")); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual(new DateTime(2011, 1, 1, 12, 1, 1).ToShortTimeString(), propertyNameAndValues["MyDateTime"]); Assert.AreEqual("I'm A String I'm the exception", propertyNameAndValues["MyString"]); Assert.AreEqual("I'm a Sub String hello world", propertyNameAndValues["Sub.SubString"]); }
public void BasicTypeTest() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<TestObj>(o => "my lucky number is " + o.MyInt + " set from unit test")); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("my lucky number is 10 set from unit test", propertyNameAndValues["MyInt"]); }
public void Primitive_As_Root2_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<string>(o => o.ToUpper())); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("I'M A STRING", propertyNameAndValues["MyString"]); Assert.AreEqual("I'M A SUB STRING", propertyNameAndValues["Sub.SubString"]); //Assert.AreEqual("I'M", propertyNameAndValues["MyList[0]"]); }
public void Enum_Format_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<TestObj>(o => o.MyEnum.ToString() + " hello")); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("e1 hello", propertyNameAndValues["MyEnum.e1"]); }
public void Deep_Property_ToString_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<TestObj>(o => o.Sub.Inner.InnerInt.ToString() + "LOLZ")); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("99LOLZ", propertyNameAndValues["Sub.Inner.InnerInt"]); }
public void Object_ToString_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<InnerObj>(o => o.ToString())); x.Add(new ExpressionFormatter<TestObj>(o => "I'm an Int " + (1 + o.MyInt))); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("I'm the ToString of InnerObj99", propertyNameAndValues["Sub.Inner"]); Assert.AreEqual("I'm an Int 11", propertyNameAndValues["MyInt"]); }
public void ComplexList_Format_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<string>(o => o.ToUpper())); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("LIST STRING 1", propertyNameAndValues["MyComplexList[0].SubString"]); }
public void Bool_Format_Test() { TestObj x1 = InitializeMocks(); var x = new StringFormatterCollection(); x.Add(new ExpressionFormatter<bool>(o => o ? "Yes" : "No")); var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1); Assert.AreEqual("Yes", propertyNameAndValues["MyBool"]); }