public void IndexSet_IsEqual_DifferentNonCountedFields_True() { IndexComparer.BusinessObjects.IndexSet isp3 = new IndexComparer.BusinessObjects.IndexSet(); isp3.ServerName = "Server 1"; isp3.DatabaseName = "Database 1"; isp3.SchemaName = "dbo"; isp3.TableName = "Table1"; isp3.IndexName = "Index3"; isp3.IndexType = "NONCLUSTERED"; isp3.IndexIsUnique = true; isp3.Columns = "SomeColumn,SomeColumn2"; isp3.IncludedColumns = "SomeColumn4,SomeColumn3"; isp3.HasFilter = true; isp3.FilterDefinition = "(ID < 500)"; IndexComparer.BusinessObjects.IndexSet iss4 = new IndexComparer.BusinessObjects.IndexSet(); iss4.ServerName = "Server 1"; iss4.DatabaseName = "Database 1"; iss4.SchemaName = "dbo"; iss4.TableName = "Table1"; iss4.IndexName = "Index3"; iss4.IndexType = "HEAP"; Assert.IsTrue(isp3.Equals(iss4)); Assert.AreEqual(isp3.GetHashCode(), iss4.GetHashCode()); Assert.IsFalse(isp3.TotallyEquals(iss4)); }
public void IndexSet_UQ_CI_IsEqual_False() { IndexComparer.BusinessObjects.IndexSet isp3 = new IndexComparer.BusinessObjects.IndexSet(); isp3.ServerName = "Server 1"; isp3.DatabaseName = "Database 1"; isp3.SchemaName = "dbo"; isp3.TableName = "Table1"; isp3.IndexName = "Index3"; isp3.IndexType = "CLUSTERED"; isp3.IndexIsUnique = true; isp3.IsKeyConstraint = true; isp3.KeyConstraintType = "PK"; isp3.Columns = "SomeColumn,SomeColumn2"; isp3.IncludedColumns = "SomeColumn4,SomeColumn3"; isp3.HasFilter = true; isp3.FilterDefinition = "(ID < 500)"; IndexComparer.BusinessObjects.IndexSet iss4 = new IndexComparer.BusinessObjects.IndexSet(); iss4.ServerName = "Server 1"; iss4.DatabaseName = "Database 1"; iss4.SchemaName = "dbo"; iss4.TableName = "Table1"; iss4.IndexName = "Index3"; iss4.IndexType = "CLUSTERED"; iss4.IndexIsUnique = true; iss4.Columns = "SomeColumn,SomeColumn2"; iss4.IncludedColumns = "SomeColumn4,SomeColumn3"; iss4.HasFilter = true; iss4.FilterDefinition = "(ID < 500)"; Assert.IsTrue(isp3.Equals(iss4)); //Server, database, schema, table, and index name match. Assert.AreEqual(isp3.GetHashCode(), iss4.GetHashCode()); Assert.IsFalse(isp3.TotallyEquals(iss4)); //Key constraint does NOT match. }
public void IndexSet_UKC_AlterTable_False() { IndexComparer.BusinessObjects.IndexSet isp = new IndexComparer.BusinessObjects.IndexSet(); isp.ServerName = "Server 1"; isp.DatabaseName = "Database 1"; isp.SchemaName = "dbo"; isp.TableName = "Table1"; isp.IndexName = "UKC_Table"; isp.IndexType = "NONCLUSTERED"; isp.IndexIsUnique = true; isp.IsKeyConstraint = false; //Force a negative test. isp.Columns = "SomeColumn,SomeColumn2"; isp.IncludedColumns = "SomeColumn4,SomeColumn3"; isp.HasFilter = true; isp.FilterDefinition = "(ID < 500)"; Assert.IsTrue(isp.CreateScript.Contains("CREATE UNIQUE NONCLUSTERED INDEX")); Assert.IsFalse(isp.CreateScript.Contains("ADD CONSTRAINT")); }
/// <summary> /// Look for indexes which exist in the secondary database but not in the primary. /// </summary> /// <param name="DisplayHeader"></param> /// <param name="ScriptDrops"></param> /// <param name="ScriptCreates"></param> /// <param name="writer"></param> /// <param name="PrimaryServerName"></param> /// <param name="PrimaryDatabaseName"></param> /// <param name="SecondaryServerName"></param> /// <param name="SecondaryDatabaseName"></param> /// <param name="PrimaryResults"></param> /// <param name="SecondaryResults"></param> public static void StreamNotInPrimaryComparison(bool DisplayHeader, bool ScriptDrops, bool ScriptCreates, System.IO.StreamWriter writer, string PrimaryServerName, string PrimaryDatabaseName, string SecondaryServerName, string SecondaryDatabaseName, IEnumerable <IndexSet> PrimaryResults, IEnumerable <IndexSet> SecondaryResults) { if (writer == null) { throw new Exception("No stream available."); } if (DisplayHeader) { writer.WriteLine("================================================================="); writer.WriteLine("====================SECTION 3: NOT IN PRIMARY==================="); writer.WriteLine("================================================================="); } IEnumerable <IndexSet> NotInPrimary = IndexSet.GetNonexistentIndexes(SecondaryResults, PrimaryResults); foreach (IndexSet ix in NotInPrimary) { writer.WriteLine(String.Format("{0} on {1}.{2}", String.IsNullOrWhiteSpace(ix.IndexName) ? "HEAP" : ix.IndexName, ix.SchemaName, ix.TableName)); } writer.WriteLine(String.Empty); if (ScriptDrops) { WriteDropStatements(writer, NotInPrimary); writer.WriteLine(String.Empty); } if (ScriptCreates) { WriteCreateStatements(writer, NotInPrimary); writer.WriteLine(String.Empty); } writer.Flush(); }
public IndexGroup(IndexSet Primary, IndexSet Secondary) { if (Primary == null && Secondary == null) { throw new ApplicationException("At least one index set must be non-null."); } PrimaryIndexSet = Primary; SecondaryIndexSet = Secondary; if (PrimaryIndexSet != null) { SchemaName = PrimaryIndexSet.SchemaName; TableName = PrimaryIndexSet.TableName; IndexName = PrimaryIndexSet.IndexName; } else { SchemaName = SecondaryIndexSet.SchemaName; TableName = SecondaryIndexSet.TableName; IndexName = SecondaryIndexSet.IndexName; } }
public void IndexSet_UQ_NCI_IsEqual_False() { IndexComparer.BusinessObjects.IndexSet isp3 = new IndexComparer.BusinessObjects.IndexSet(); isp3.ServerName = "Server 1"; isp3.DatabaseName = "Database 1"; isp3.SchemaName = "dbo"; isp3.TableName = "Table1"; isp3.IndexName = "Index3"; isp3.IndexType = "NONCLUSTERED"; isp3.IndexIsUnique = true; isp3.IsKeyConstraint = true; isp3.KeyConstraintType = "UQ"; isp3.Columns = "SomeColumn,SomeColumn2"; isp3.IncludedColumns = "SomeColumn4,SomeColumn3"; isp3.HasFilter = true; isp3.FilterDefinition = "(ID < 500)"; IndexComparer.BusinessObjects.IndexSet iss4 = new IndexComparer.BusinessObjects.IndexSet(); iss4.ServerName = "Server 1"; iss4.DatabaseName = "Database 1"; iss4.SchemaName = "dbo"; iss4.TableName = "Table1"; iss4.IndexName = "Index3"; iss4.IndexType = "NONCLUSTERED"; iss4.IndexIsUnique = true; iss4.Columns = "SomeColumn,SomeColumn2"; iss4.IncludedColumns = "SomeColumn4,SomeColumn3"; iss4.HasFilter = true; iss4.FilterDefinition = "(ID < 500)"; Assert.IsTrue(isp3.Equals(iss4)); //Server, database, schema, table, and index name match. Assert.AreEqual(isp3.GetHashCode(), iss4.GetHashCode()); Assert.IsFalse(isp3.TotallyEquals(iss4)); //Key constraint does NOT match. }
public void IndexSet_UKC_AlterTable_True() { IndexComparer.BusinessObjects.IndexSet isp = new IndexComparer.BusinessObjects.IndexSet(); isp.ServerName = "Server 1"; isp.DatabaseName = "Database 1"; isp.SchemaName = "dbo"; isp.TableName = "Table1"; isp.IndexName = "UKC_Table"; isp.IndexType = "NONCLUSTERED"; isp.IndexIsUnique = true; isp.IsKeyConstraint = true; //Unique keys are key constraints isp.KeyConstraintType = "UQ"; //Unique key constraint code isp.Columns = "SomeColumn,SomeColumn2"; isp.IncludedColumns = "SomeColumn4,SomeColumn3"; isp.HasFilter = true; isp.FilterDefinition = "(ID < 500)"; Assert.IsFalse(isp.CreateScript.Contains("CREATE UNIQUE NONCLUSTERED INDEX")); Assert.IsTrue(isp.CreateScript.Contains("ADD CONSTRAINT")); }
public void IndexSet_IsTotallyEqual_IndexTypeDiffers_False() { IndexComparer.BusinessObjects.IndexSet isp3 = new IndexComparer.BusinessObjects.IndexSet(); isp3.ServerName = "Server 1"; isp3.DatabaseName = "Database 1"; isp3.SchemaName = "dbo"; isp3.TableName = "Table1"; isp3.IndexName = "Index3"; isp3.IndexType = "NONCLUSTERED"; isp3.IndexIsUnique = true; isp3.Columns = "SomeColumn,SomeColumn2"; isp3.IncludedColumns = "SomeColumn4,SomeColumn3"; isp3.HasFilter = true; isp3.FilterDefinition = "(ID < 500)"; IndexComparer.BusinessObjects.IndexSet iss4 = new IndexComparer.BusinessObjects.IndexSet(); iss4.ServerName = "Server 1"; iss4.DatabaseName = "Database 1"; iss4.SchemaName = "dbo"; iss4.TableName = "Table1"; iss4.IndexName = "Index3"; iss4.IndexType = "CLUSTERED"; iss4.IndexIsUnique = true; iss4.Columns = "SomeColumn,SomeColumn2"; iss4.IncludedColumns = "SomeColumn4,SomeColumn3"; iss4.HasFilter = true; iss4.FilterDefinition = "(ID < 500)"; Assert.IsTrue(isp3.Equals(iss4)); Assert.AreEqual(isp3.GetHashCode(), iss4.GetHashCode()); Assert.IsFalse(isp3.TotallyEquals(iss4)); }