public void SimpleList() { String str = @">| Name | Value| Key | CreatedOn | | Ma rrow | 13.07| 0 | 2017-03-15| | Marrow 1 | 13 | -123| 2018-03-15| | Marrow one two| -16 | 56 | 2019-03-15| " ; var parser = new MarrowParser(); var struct1 = parser.Parse <List <Struct1> >(str); Assert.AreEqual("Ma rrow", struct1[0].Name, "Name parsing failed for line 0"); Assert.AreEqual(13.07, struct1[0].Value, "Value parsing failed for line 0"); Assert.AreEqual(0, struct1[0].Key, "Key parsing failed for line 0"); Assert.AreEqual(new DateTime(2017, 03, 15), struct1[0].CreatedOn, "CreatedOn parsing failed for line 0"); Assert.AreEqual("Marrow 1", struct1[1].Name, "Name parsing failed for line 1"); Assert.AreEqual(13, struct1[1].Value, "Value parsing failed for line 1"); Assert.AreEqual(-123, struct1[1].Key, "Key parsing failed for line 1"); Assert.AreEqual(new DateTime(2018, 03, 15), struct1[1].CreatedOn, "CreatedOn parsing failed for line 1"); Assert.AreEqual("Marrow one two", struct1[2].Name, "Name parsing failed for line 2"); Assert.AreEqual(-16, struct1[2].Value, "Value parsing failed for line 2"); Assert.AreEqual(56, struct1[2].Key, "Key parsing failed for line 2"); Assert.AreEqual(new DateTime(2019, 03, 15), struct1[2].CreatedOn, "CreatedOn parsing failed for line 2"); }
public void OneLineTestData() { String str = @">| Name1 | Value1 | | Marrow | 13.07 | >| StrcutProp1 | Name2 | Value2 | | | SubMarrow | 0 | | Marrow 3 | -12 | " ; var parser = new MarrowParser(); var actual = parser.Parse <List <Struct1> >(str); var expected = new List <Struct1> { new Struct1 { Name1 = "Marrow", Value1 = 13.07, StrcutProp1 = new Struct2 { Name2 = "SubMarrow", Value2 = 0 } }, new Struct1 { Name1 = "Marrow 3", Value1 = -12 } }; CompareLogic compareLogic = new CompareLogic(); ComparisonResult result = compareLogic.Compare(actual, expected); if (!result.AreEqual) { throw new Exception(result.DifferencesString); } }
public void SimpleObject() { String str = @">| Name | Value | Key | CreatedOn | | Marrow | 13.07 | 27 | 2018-03-15 |" ; var parser = new MarrowParser(); var struct1 = parser.Parse <Struct1>(str); Assert.AreEqual("Marrow", struct1.Name, "Name parsing failed"); Assert.AreEqual(13.07, struct1.Value, "Value parsing failed"); Assert.AreEqual(27, struct1.Key, "Key parsing failed"); Assert.AreEqual(new DateTime(2018, 03, 15), struct1.CreatedOn, "CreatedOn parsing failed"); }
public void SimpleObjectWithSubObjects() { String str = @">| Name1 | Value1 | | Marrow | 13.07 | >| strcutProp1 | Name2 | Value2 | | | SubMarrow | 0 | " ; var parser = new MarrowParser(); var struct1 = parser.Parse <Struct1>(str); Assert.AreEqual("Marrow", struct1.Name1, "Name parsing failed"); Assert.AreEqual(13.07, struct1.Value1, "Value parsing failed"); Assert.AreEqual("SubMarrow", struct1.strcutProp1.Name2, "strcutProp1.Value parsing failed"); Assert.AreEqual(0, struct1.strcutProp1.Value2, "strcutProp1.Value parsing failed"); }
public void TestSimpleConfig() { String str = @">| Name | Value | Key | CreatedOn | | Marrow | 13.07 | 27 | 2018-03-15 |" ; var parser = new MarrowParser(); parser.ConfigureClass <Struct1>() .ConfigureProperty(s => s.Key); var struct1 = parser.Parse <Struct1>(str); Assert.AreEqual("Marrow", struct1.Name, "Name parsing failed"); Assert.AreEqual(13.07, struct1.Value, "Value parsing failed"); Assert.AreEqual(27, struct1.Key, "Key parsing failed"); Assert.AreEqual(new DateTime(2018, 03, 15), struct1.CreatedOn, "CreatedOn parsing failed"); }
public void MultyLineSubPropData() { String str = @">| Name1 | Value1 | | Marrow | 13.07 | >| EnumStrcutProp1 | Name2 | Value2 | | | SubMarrow1 | 4 | | | SubMarrow2 | 5 | | NULL | -12 | | "" | -.43 | " ; var parser = new MarrowParser(); var actual = parser.Parse <List <Struct1> >(str); var expected = new List <Struct1> { new Struct1 { Name1 = "Marrow", Value1 = 13.07, EnumStrcutProp1 = new List <Struct2> { new Struct2 { Name2 = "SubMarrow1", Value2 = 4 }, new Struct2 { Name2 = "SubMarrow2", Value2 = 5 }, } }, new Struct1 { Value1 = -12 }, new Struct1 { Name1 = String.Empty, Value1 = -0.43 } }; CompareLogic compareLogic = new CompareLogic(); compareLogic.Config.IgnoreCollectionOrder = true; ComparisonResult result = compareLogic.Compare(actual, expected); if (!result.AreEqual) { throw new Exception(result.DifferencesString); } }