Example #1
0
        public void DateTime_Formatting_Test()
        {
            TestObj x1 = InitializeMocks();
            var x = new StringFormatterCollection();
            x.Add(new ExpressionFormatter<TestObj>(o => o.MyDateTime.ToShortDateString()));

            var propertyNameAndValues = new PropertyMapper(x).GetMappings(x1);
            Assert.AreEqual(new DateTime(2011, 1, 1, 12, 1, 1).ToShortDateString(), propertyNameAndValues["MyDateTime"]);
        }
Example #2
0
        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"]);
        }
Example #3
0
        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"]);
        }
Example #4
0
        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]"]);
        }
Example #5
0
 public PropertyMapper(StringFormatterCollection formatters)
 {
     _formatters = formatters;
 }
Example #6
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"]);
        }
Example #7
0
        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"]);
        }
Example #8
0
        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"]);
        }
Example #9
0
        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"]);
        }
Example #10
0
        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"]);
        }