public void SaveLoadXmlOptions() { var cbOrig = new DelimitedClassBuilder("Customers", ","); cbOrig.AddField("Field1", typeof(DateTime)); cbOrig.AddField("FieldTwo", typeof(string)); cbOrig.RecordCondition.Condition = RecordCondition.ExcludeIfMatchRegex; cbOrig.RecordCondition.Selector = @"\w*"; cbOrig.IgnoreCommentedLines.CommentMarker = "//"; cbOrig.IgnoreCommentedLines.InAnyPlace = false; cbOrig.IgnoreEmptyLines = true; cbOrig.IgnoreFirstLines = 123; cbOrig.IgnoreLastLines = 456; cbOrig.SealedClass = false; cbOrig.SaveToXml(@"dynamic.xml"); cbOrig.SaveToXml(@"dynamic.xml"); ClassBuilder cb2 = ClassBuilder.LoadFromXml("dynamic.xml"); Assert.AreEqual("Customers", cb2.ClassName); Assert.AreEqual(2, cb2.FieldCount); Assert.AreEqual("Field1", cb2.Fields[0].FieldName); Assert.AreEqual(RecordCondition.ExcludeIfMatchRegex, cb2.RecordCondition.Condition); Assert.AreEqual(@"\w*", cb2.RecordCondition.Selector); Assert.AreEqual("//", cb2.IgnoreCommentedLines.CommentMarker); Assert.AreEqual(false, cb2.IgnoreCommentedLines.InAnyPlace); Assert.AreEqual(false, cb2.SealedClass); Assert.AreEqual(true, cb2.IgnoreEmptyLines); Assert.AreEqual(123, cb2.IgnoreFirstLines); Assert.AreEqual(456, cb2.IgnoreLastLines); }
public void SaveLoadXmlFileDelimited() { var cb = new DelimitedClassBuilder("Customers", ","); cb.IgnoreFirstLines = 1; cb.IgnoreEmptyLines = true; cb.AddField("Field1", typeof(DateTime)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.QuoteMode = QuoteMode.AlwaysQuoted; cb.LastField.FieldNullValue = DateTime.Today; cb.AddField("FieldTwo", typeof(string)); cb.LastField.FieldQuoted = true; cb.LastField.QuoteChar = '"'; cb.AddField("Field333", typeof(int)); cb.SaveToXml(@"dynamic.xml"); var loaded = (DelimitedClassBuilder)ClassBuilder.LoadFromXml(@"dynamic.xml"); Assert.AreEqual("Field1", loaded.FieldByIndex(0).FieldName); Assert.AreEqual("FieldTwo", loaded.FieldByIndex(1).FieldName); Assert.AreEqual("Field333", loaded.FieldByIndex(2).FieldName); Assert.AreEqual("System.DateTime", loaded.FieldByIndex(0).FieldType); Assert.AreEqual("System.String", loaded.FieldByIndex(1).FieldType); Assert.AreEqual("System.Int32", loaded.FieldByIndex(2).FieldType); Assert.AreEqual(QuoteMode.AlwaysQuoted, loaded.FieldByIndex(0).QuoteMode); Assert.AreEqual(false, loaded.FieldByIndex(0).FieldQuoted); Assert.AreEqual('"', loaded.FieldByIndex(1).QuoteChar); Assert.AreEqual(true, loaded.FieldByIndex(1).FieldQuoted); }
public void SaveLoadXmlFileDelimited2() { var cb = new DelimitedClassBuilder("Customers", ","); cb.IgnoreFirstLines = 1; cb.IgnoreEmptyLines = true; cb.AddField("Field1", typeof(DateTime)); cb.LastField.TrimMode = TrimMode.Both; cb.LastField.QuoteMode = QuoteMode.AlwaysQuoted; cb.LastField.FieldNullValue = DateTime.Today; cb.AddField("FieldTwo", typeof(string)); cb.LastField.FieldQuoted = true; cb.LastField.QuoteChar = '"'; cb.AddField("Field333", typeof(int)); cb.SaveToXml(@"dynamic.xml"); mEngine = new FileHelperEngine(ClassBuilder.ClassFromXmlFile("dynamic.xml")); Assert.AreEqual("Customers", mEngine.RecordType.Name); Assert.AreEqual(3, mEngine.RecordType.GetFields().Length); Assert.AreEqual("Field1", mEngine.RecordType.GetFields()[0].Name); }