public void TestProcessNullTag() { var processor = new TableProcessor(); processor.DataReader = this.dataReader; processor.Process(); }
public void TestProcessNullReader() { var processor = new TableProcessor { TableTag = this.GetTableTag() }; processor.Process(); }
public void TestUploadOfTableWithDateFieldsThatAreReservedWords() { TableProcessor tp = new TableProcessor(); const String tableName = "SGIBKHDR"; tp.Process(VfpConnectionString, tableName, SqlConnectionString, tableName); TestContext.WriteLine("TestUploadOfTableWithDateFieldsThatAreReservedWords complete"); }
public void Generate(XElement startTableElement, XElement endTableElement, DataReader dataReader) { var coreParser = new CoreTableParser(true); var tag = coreParser.Parse(startTableElement, endTableElement); var processor = new TableProcessor() { DataReader = dataReader, TableTag = tag }; processor.Process(); }
public void TestUploadWithAsciiZero() { const String tableName = "IN_WATRM"; Helper.ExecuteSqlNonQuery(SqlConnectionString, "DELETE FROM " + tableName); TableProcessor tp = new TableProcessor(); tp.Process(VfpConnectionString, tableName, SqlConnectionString, tableName); DataTable dt = Helper.GetSqlDataTable(SqlConnectionString, "select charindex(char(0),cast(background as varchar(max))) from " + tableName); foreach (DataRow row in dt.Rows) { Assert.IsTrue(Convert.ToInt32(row[0]) > 0); } }
public void TestBasicUpload() { const String tableName = "IN_MSG"; String getCountCommandString = "SELECT COUNT(*) FROM " + tableName; int vfpRowCount = Convert.ToInt32(Helper.GetOleDbScaler(VfpConnectionString, getCountCommandString)); int vfpNonDeletedRowCount = Convert.ToInt32(Helper.GetOleDbScaler(VfpConnectionString, getCountCommandString + " WHERE NOT DELETED()")); int vfpDeletedRowCount = Convert.ToInt32(Helper.GetOleDbScaler(VfpConnectionString, getCountCommandString + " WHERE DELETED()")); Assert.IsTrue(vfpNonDeletedRowCount > 0, "Expected 1 or more non-deleted rows"); Assert.IsTrue(vfpDeletedRowCount > 0, "Expected 1 or more deleted rows"); // Clear out the SQL table Helper.ExecuteSqlNonQuery(SqlConnectionString, "DELETE FROM " + tableName); Assert.AreEqual(0, (int)Helper.GetSqlScaler(SqlConnectionString, getCountCommandString)); // Import from VFP TableProcessor tp = new TableProcessor(); tp.Process(bogusVfpConnectionString, tableName, SqlConnectionString, tableName); // Make sure rowcounts are correct int actualRowCount = Convert.ToInt32(Helper.GetSqlScaler(SqlConnectionString, getCountCommandString)); int expectedRowCount = Convert.ToInt32(Helper.GetOleDbScaler(VfpConnectionString, getCountCommandString)); Assert.AreEqual(actualRowCount, expectedRowCount); // Check handling of Deleted() int sqlDeletedRowCount = Convert.ToInt32(Helper.GetSqlScaler(SqlConnectionString, getCountCommandString + String.Format(" WHERE {0} = 1", Constants.DILayer.DeletedColumnName))); Assert.AreEqual(sqlDeletedRowCount, vfpDeletedRowCount); // Check for nullDates String nullDateRowCountCmdStr = getCountCommandString + " WHERE mscldate is null or msBegin is null or msDate is null"; int nullDateRowCount = Convert.ToInt32(Helper.GetSqlScaler(SqlConnectionString, nullDateRowCountCmdStr)); Assert.IsTrue(nullDateRowCount > 0); // Check for non nullDates nullDateRowCountCmdStr = getCountCommandString + " WHERE mscldate is not null or msBegin is not null or msDate is not null"; nullDateRowCount = Convert.ToInt32(Helper.GetSqlScaler(SqlConnectionString, nullDateRowCountCmdStr)); Assert.IsTrue(nullDateRowCount > 0); }
public void TestUploadOfTableWithConversionActions() { const String tableName = "IN_SPBL"; String triggerName = tableName + "_PackageDetail_CurrentVersions_Rebuild"; string currentVersionsTable = tableName + "_PackageDetail_CurrentVersions"; String pkgDetailProc = tableName + "_GetPackageDetail"; List <String> dropCmds = new List <String>(); StringBuilder sb = new StringBuilder(); sb.AppendLine("IF EXISTS(SELECT* FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[{0}]'))"); sb.AppendLine("DROP TRIGGER {0}"); dropCmds.Add(String.Format(sb.ToString(), triggerName)); sb.Clear(); sb.AppendLine("IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '{0}')"); sb.AppendLine("DROP TABLE {0}"); dropCmds.Add(String.Format(sb.ToString(), currentVersionsTable)); sb.Clear(); sb.AppendLine("IF EXISTS(SELECT name FROM sysobjects WHERE Name = '{0}' AND[Type] = 'P')"); sb.AppendLine("DROP PROCEDURE {0}"); dropCmds.Add(String.Format(sb.ToString(), pkgDetailProc)); foreach (String dropCmd in dropCmds) { Helper.ExecuteSqlNonQuery(SqlConnectionString, dropCmd); } ITableProcessor tblProc = new TableProcessor(new DiTableOrDefaultBatchSizeProvider(VfpConnectionString)); tblProc.Process(VfpConnectionString, tableName, SqlConnectionString, tableName); // Make sure table exists int rowCount = (int)Helper.GetSqlScaler(SqlConnectionString, "SELECT COUNT(*) FROM " + currentVersionsTable); Assert.IsTrue(rowCount > 0); }
public void TestProcessItemIfCells() { XElement root; using (var docStream = AssemblyResourceHelper.GetResourceStream(this, "TableItemIfsTest.xml")) { var document = XDocument.Load(docStream); root = document.Root.Element(WordMl.BodyName); } var tableTag = this.GetTableTag(root); XDocument data; using (var docStream = AssemblyResourceHelper.GetResourceStream(this, "TableItemIfsData.xml")) { data = XDocument.Load(docStream); } Func <XElement, IEnumerable <TableElement> > MakeTableElementCallback = element => { var cells = element.Descendants(WordMl.TableCellName).ToList(); ICollection <TableElement> tableElements = new Collection <TableElement>(); foreach (var cell in cells) { var cellTags = cell.Descendants(WordMl.SdtName).ToList(); var firtsIf = new TableElement { IsIndex = false, IsItem = false, IsItemIf = true, StartTag = cellTags[0], EndTag = cellTags[2], Expression = cellTags[0].Value, TagElements = new TableElement[] { new TableElement { IsIndex = false, IsItemIf = false, IsItem = true, StartTag = cellTags[1], Expression = cellTags[1].Value, } } }; var secondIf = new TableElement { IsIndex = false, IsItem = false, IsItemIf = true, StartTag = cellTags[3], EndTag = cellTags[5], Expression = cellTags[3].Value, TagElements = new TableElement[] { new TableElement { IsIndex = false, IsItemIf = false, IsItem = true, StartTag = cellTags[4], Expression = cellTags[4].Value, } } }; tableElements.Add(firtsIf); tableElements.Add(secondIf); } return(tableElements); }; tableTag.MakeTableElementCallback = MakeTableElementCallback; var tableProcessor = new TableProcessor { TableTag = tableTag, DataReader = DataReaderFactory.CreateReader(data) }; tableProcessor.Process(); var expectedTableStructure = new[] { new[] { "#", "Certificate", "Date" }, new[] { string.Empty, string.Empty, "Issue", "Expiration" }, new[] { "1", "2", "3", "4" }, new[] { "row1 - value1", "row1 - value2", "row1 - value3", "row1 - value4" }, new[] { "row2 - value1", "row2 - value2", "row2 - value3", "row2 - value4" }, new[] { "row3 - value1", "row3 - value2", "row3 - value3", "row3 - value4" }, new[] { "row4 - value1", "row4 - value2", "row4 - value3", "row4 - value4" }, new[] { "row5 - value1", "row5 - value2", "row5 - value3", "row5 - value4" }, new[] { "This", "row", "stays", "untouched" }, }; var rows = tableTag.Table.Elements(WordMl.TableRowName).ToList(); Assert.AreEqual(expectedTableStructure.Count(), rows.Count()); int rowIndex = 0; foreach (var row in rows) { var expectedRow = expectedTableStructure[rowIndex]; var cellsInRow = row.Elements(WordMl.TableCellName).ToList(); Assert.AreEqual(expectedRow.Count(), cellsInRow.Count()); int cellIndex = 0; foreach (var cell in cellsInRow) { Assert.AreEqual(expectedRow[cellIndex], cell.Value); cellIndex++; } rowIndex++; } /* * var tagsBetween = * tableTag.TagTable.ElementsAfterSelf().Where(element => element.IsBefore(tableTag.TagContent)); * Assert.IsFalse(tagsBetween.Any()); * * tagsBetween = * tableTag.TagEndContent.ElementsAfterSelf().Where(element => element.IsBefore(tableTag.TagEndTable)); * Assert.IsFalse(tagsBetween.Any());*/ this.ValidateTagsRemoved(root); }
public void TestProcessWithStaticCells() { XElement root; using (var docStream = AssemblyResourceHelper.GetResourceStream(this, "TableProcessorWithStaticCellsTest.xml")) { var document = XDocument.Load(docStream); root = document.Root.Element(WordMl.BodyName); } var tableTag = this.GetTableTag(root); Func <XElement, IEnumerable <TableElement> > MakeTableElementCallback = element => { var tags = element.Descendants(WordMl.SdtName).ToList(); var index = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemindex")); var issueDate = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemtext") && e.Element(WordMl.SdtContentName).Value == "./IssueDate"); IEnumerable <TableElement> tableElements = new TableElement[] { new TableElement { IsIndex = true, IsItem = false, IsItemIf = false, StartTag = index, }, new TableElement { IsItem = true, IsIndex = false, IsItemIf = false, StartTag = issueDate, Expression = "./IssueDate" }, }; return(tableElements); }; tableTag.MakeTableElementCallback = MakeTableElementCallback; var tableProcessor = new TableProcessor { TableTag = tableTag, DataReader = this.dataReader }; tableProcessor.Process(); var expectedTableStructure = new[] { new[] { "#", "Certificate", "Date" }, new[] { string.Empty, string.Empty, "Issue", "Expiration" }, new[] { "1", "2", "3", "4" }, new[] { "1", "First static text", "01.04.2014", "Second static text" }, new[] { "2", "First static text", "01.03.2014", "Second static text" }, new[] { "3", "First static text", "01.01.2011", "Second static text" }, new[] { "This", "row", "stays", "untouched" }, }; var rows = tableTag.Table.Elements(WordMl.TableRowName).ToList(); Assert.AreEqual(expectedTableStructure.Count(), rows.Count()); int rowIndex = 0; foreach (var row in rows) { var expectedRow = expectedTableStructure[rowIndex]; var cellsInRow = row.Elements(WordMl.TableCellName).ToList(); Assert.AreEqual(expectedRow.Count(), cellsInRow.Count()); int cellIndex = 0; foreach (var cell in cellsInRow) { Assert.AreEqual(expectedRow[cellIndex], cell.Value); cellIndex++; } rowIndex++; } this.ValidateTagsRemoved(root); }
public void TestProcess() { var tableTag = this.GetTableTag(); Func <XElement, IEnumerable <TableElement> > MakeTableElementCallback = element => { var tags = element.Descendants(WordMl.SdtName).ToList(); var index = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemindex")); var subject = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemtext") && e.Element(WordMl.SdtContentName).Value == "./Subject"); var issueDate = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemtext") && e.Element(WordMl.SdtContentName).Value == "./IssueDate"); var expireDate = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemtext") && e.Element(WordMl.SdtContentName).Value == "./ExpireDate"); var itemIf = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("itemif")); var endItemIf = tags.Find( e => e.Element(WordMl.SdtPrName) .Element(WordMl.TagName) .Attribute(WordMl.ValAttributeName) .Value.ToLower() .Equals("enditemif")); IEnumerable <TableElement> tableElements = new TableElement[] { new TableElement { IsIndex = true, IsItem = false, IsItemIf = false, StartTag = index, }, new TableElement { IsItemIf = true, IsIndex = false, IsItem = false, StartTag = itemIf, EndTag = endItemIf, Expression = "./HasSubject", TagElements = new TableElement[] { new TableElement { IsItem = true, IsIndex = false, IsItemIf = false, StartTag = subject, Expression = "./Subject" } } }, new TableElement { IsItem = true, IsIndex = false, IsItemIf = false, StartTag = issueDate, Expression = "./IssueDate" }, new TableElement { IsItem = true, IsIndex = false, IsItemIf = false, StartTag = expireDate, Expression = "./ExpireDate" } }; return(tableElements); }; tableTag.MakeTableElementCallback = MakeTableElementCallback; var tableProcessor = new TableProcessor { TableTag = tableTag, DataReader = this.dataReader }; tableProcessor.Process(); Assert.IsFalse(this.documentRoot.Elements(WordMl.SdtName).Any(element => element.IsSdt())); var expectedTableStructure = new[] { new[] { "#", "Certificate", "Date" }, new[] { string.Empty, string.Empty, "Issue", "Expiration" }, new[] { "1", "2", "3", "4" }, new[] { "1", "Subject1", "01.04.2014", "01.10.2015" }, new[] { "2", "Subject2", "01.03.2014", "01.09.2015" }, new[] { "3", "Subject3", "01.01.2011", "01.01.2012" }, new[] { "This", "row", "stays", "untouched" }, }; var rows = tableTag.Table.Elements(WordMl.TableRowName).ToList(); Assert.AreEqual(expectedTableStructure.Count(), rows.Count()); int rowIndex = 0; foreach (var row in rows) { var expectedRow = expectedTableStructure[rowIndex]; var cellsInRow = row.Elements(WordMl.TableCellName).ToList(); Assert.AreEqual(expectedRow.Count(), cellsInRow.Count()); int cellIndex = 0; foreach (var cell in cellsInRow) { Assert.AreEqual(expectedRow[cellIndex], cell.Value); cellIndex++; } rowIndex++; } /* * var tagsBetween = * tableTag.TagTable.ElementsAfterSelf().Where(element => element.IsBefore(tableTag.TagContent)); * Assert.IsFalse(tagsBetween.Any()); * * tagsBetween = * tableTag.TagEndContent.ElementsAfterSelf().Where(element => element.IsBefore(tableTag.TagEndTable)); * Assert.IsFalse(tagsBetween.Any());*/ this.ValidateTagsRemoved(this.documentRoot); }