Exemplo n.º 1
0
		public void SaveLoadXmlFileDelimited2()
		{
			DelimitedClassBuilder 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(@"runtime.xml");
			
			engine = new FileHelperEngine(ClassBuilder.ClassFromXmlFile("runtime.xml"));

			Assert.AreEqual("Customers", engine.RecordType.Name);
			Assert.AreEqual(3, engine.RecordType.GetFields().Length);
			Assert.AreEqual("Field1", engine.RecordType.GetFields()[0].Name);
		}
Exemplo n.º 2
0
		public void SaveLoadXmlOptions()
		{
			DelimitedClassBuilder 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(@"runtime.xml");
			cbOrig = null;
			
			ClassBuilder cb2 = ClassBuilder.LoadFromXml("runtime.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 );

		}
Exemplo n.º 3
0
		public void SaveLoadXmlFileDelimited()
		{
			DelimitedClassBuilder 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(@"runtime.xml");
			
			DelimitedClassBuilder loaded = (DelimitedClassBuilder) ClassBuilder.LoadFromXml(@"runtime.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);
		}