Exemple #1
0
 public void BoolPropertyZeroIsParsedAsFalse()
 {
     string input = "<TestClass BoolProp=\"0\" /> ";
     var mapper = new Mapper<TestClass>(input);
     TestClass result = mapper.ParseNext();
     Assert.IsFalse(result.BoolProp);
 }
Exemple #2
0
 public void BoolPropertyTrueStringIsParsedAsTrue()
 {
     string input = "<TestClass BoolProp=\"true\" /> ";
     var mapper = new Mapper<TestClass>(input);
     TestClass result = mapper.ParseNext();
     Assert.IsTrue(result.BoolProp);
 }
Exemple #3
0
        public void ElementValueAndAttributeWithSameNameAreParsedCorrectly()
        {
            string input = "<TestClass TestElement=\"1\">" +
                            "<TestElement>2</TestElement>" +
                           "</TestClass>";
            var mapper = new Mapper<TestClass>(input);

            mapper.SetAttributeMap("TestElement", "DoubleProp");
            mapper.SetElementMap("TestElement", "DecimalProp");

            TestClass result = mapper.ParseNext();
            Assert.AreEqual(1, result.DoubleProp);
            Assert.AreEqual(2, result.DecimalProp);
        }
Exemple #4
0
 public void DoublePropertyParsedCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(5.0, t.DoubleProp);
 }
Exemple #5
0
 public void DecimalPropertyParsedCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(1.23456789, t.DecimalProp);
 }
Exemple #6
0
 public void DateTimeParsingWorksCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(new DateTime(2001, 11, 16), t.Date);
 }
Exemple #7
0
 public void NamedElementPropertyParsedCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(55, t.PropWithSpecifiedEelementName);
 }
Exemple #8
0
 public void ParseOptionsOnElementValuesWorkCorrectly()
 {
     string input = "<TestClass> <WeirdDate>2001-05;17</WeirdDate> </TestClass>";
     var mapper = new Mapper<TestClass>(input);
     mapper.SetElementMap("WeirdDate", "Date", "yyyy-MM;dd");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(new DateTime(2001, 05, 17), t.Date);
 }
Exemple #9
0
 public void PropertyUsedWithSetAttributeMapParsedCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     mapper.SetAttributeMap("BarFoo", "FooBar");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(1, t.FooBar);
 }
Exemple #10
0
        public void ParseNextStepsThroughTheCollectionCorrectly()
        {
            string input = "<Collection>" +
                    "<TestClass IntProp=\"0\" /> " +
                    "<TestClass IntProp=\"1\" /> " +
                    "<TestClass IntProp=\"2\" /> " +
                    "<TestClass IntProp=\"3\" /> " +
                "</Collection>";

            var mapper = new Mapper<TestClass>(input);

            TestClass result = mapper.ParseNext();
            Assert.AreEqual(0, result.IntProp);

            result = mapper.ParseNext();
            Assert.AreEqual(1, result.IntProp);

            result = mapper.ParseNext();
            Assert.AreEqual(2, result.IntProp);

            result = mapper.ParseNext();
            Assert.AreEqual(3, result.IntProp);
        }
Exemple #11
0
 public void ParseOptionsOnAttributeValuesWorkCorrectly()
 {
     string input = "<TestClass WeirdDate=\"2001-05;17\" />";
     var mapper = new Mapper<TestClass>(input);
     mapper.SetAttributeMap("WeirdDate", "Date", "yyyy-MM;dd");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(new DateTime(2001, 05, 17), t.Date);
 }
Exemple #12
0
 public void NullableDoubleParsingWorksWhenValueIsNumber()
 {
     string input = "<TestClass NullableDoubleProp=\"0.05\" /> ";
     var mapper = new Mapper<TestClass>(input);
     TestClass result = mapper.ParseNext();
     Assert.AreEqual(0.05, result.NullableDoubleProp);
 }
Exemple #13
0
 public void NullableDoubleParsingReturnsNullWhenParsingDoesNotWork()
 {
     string input = "<TestClass NullableDoubleProp=\"asdf\" /> ";
     var mapper = new Mapper<TestClass>(input);
     TestClass result = mapper.ParseNext();
     Assert.AreEqual(null, result.NullableDoubleProp);
 }
Exemple #14
0
 public void NotXmlMappedAttributeStopsMapping()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(0, t.NotMapped);
 }
Exemple #15
0
 public void FluentAttributeMappingWorksCorrectly()
 {
     string input = "<TestClass TestAttr=\"5\" /> ";
     var mapper = new Mapper<TestClass>(input);
     mapper.SetAttributeMap("TestAttr", x => x.DoubleProp);
     TestClass result = mapper.ParseNext();
     Assert.AreEqual(null, result.NullableDoubleProp);
 }
Exemple #16
0
 public void StringPropertyParsedCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual("BobTheBuilder", t.StringProp);
 }
Exemple #17
0
 public void FluentElementMappingWorksCorrectly()
 {
     string input = "<TestClass> <TestAttr>10</TestAttr> </TestClass>";
     var mapper = new Mapper<TestClass>(input);
     mapper.SetElementMap("TestAttr", x => x.IntProp);
     TestClass result = mapper.ParseNext();
     Assert.AreEqual(10, result.IntProp);
 }
Exemple #18
0
 public void NamedAttributePropertyParsedCorrectly()
 {
     var mapper = new Mapper<TestClass>(_input, "SampleXml");
     TestClass t = mapper.ParseNext();
     Assert.AreEqual(99, t.PropWithSpecifiedAttributeName);
 }