using System; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using SyncEngine.Access; using SyncEngine.Configuration; using SyncEngine.SqlServer; namespace SyncEngine.Tests { [TestClass] public class AccessIndexGrouperTests { [TestMethod] public void GroupRows_BuildsCompositeIndexWithOrderedColumns() { var tableSet = new HashSet { "tblProduct" }; var rows = new[] { new AccessIndexGrouper.MsysIndexRow { TableName = "tblProduct", IndexName = "PrimaryKey", ColumnName = "lngProductID", ColumnOrder = 1, PrimaryKey = true, Unique = true } }; var indexes = AccessIndexGrouper.GroupRows(rows, tableSet); Assert.AreEqual(1, indexes.Count); Assert.IsTrue(indexes[0].IsPrimary); Assert.AreEqual("lngProductID", indexes[0].Columns[0]); } [TestMethod] public void GroupRows_OrdersCompositeColumnsByColumnOrder() { var tableSet = new HashSet { "tblLine" }; var rows = new[] { new AccessIndexGrouper.MsysIndexRow { TableName = "tblLine", IndexName = "ByRef", ColumnName = "refB", ColumnOrder = 2, PrimaryKey = false, Unique = true }, new AccessIndexGrouper.MsysIndexRow { TableName = "tblLine", IndexName = "ByRef", ColumnName = "refA", ColumnOrder = 1, PrimaryKey = false, Unique = true } }; var indexes = AccessIndexGrouper.GroupRows(rows, tableSet); Assert.AreEqual(1, indexes.Count); CollectionAssert.AreEqual(new[] { "refA", "refB" }, (System.Collections.ICollection)indexes[0].Columns); } [TestMethod] public void GroupRows_SkipsTablesOutsideScope() { var tableSet = new HashSet { "tblProduct" }; var rows = new[] { new AccessIndexGrouper.MsysIndexRow { TableName = "adn", IndexName = "PrimaryKey", ColumnName = "id", ColumnOrder = 1, PrimaryKey = true } }; var indexes = AccessIndexGrouper.GroupRows(rows, tableSet); Assert.AreEqual(0, indexes.Count); } } }