diff --git a/SqlSchemaCompare.Core/Common/ErrorWriter.cs b/SqlSchemaCompare.Core/Common/ErrorWriter.cs index 6316b4d..e83d828 100644 --- a/SqlSchemaCompare.Core/Common/ErrorWriter.cs +++ b/SqlSchemaCompare.Core/Common/ErrorWriter.cs @@ -13,10 +13,10 @@ public string GetErrors(IEnumerable errorsOrigin, IEnumerable errors, bool origin) + private static StringBuilder GetErrors(IEnumerable errors, bool origin) { StringBuilder errorSchemaStringBuild = new(); - if (errors.Count() > 0) + if (errors.Any()) { if (origin) errorSchemaStringBuild.AppendLine("**************** ORIGIN **************** "); diff --git a/SqlSchemaCompare.Core/DbStructures/View.cs b/SqlSchemaCompare.Core/DbStructures/View.cs index 4880d79..44288c3 100644 --- a/SqlSchemaCompare.Core/DbStructures/View.cs +++ b/SqlSchemaCompare.Core/DbStructures/View.cs @@ -6,7 +6,7 @@ public class View: DbObject { public override DbObjectType DbObjectType => DbObjectType.View; public string Body { get; init; } - public IList Indexes { get; } = new List(); + public IList Indexes { get; } = new List(); public void AddIndex(Index index) => Indexes.Add(index); } } diff --git a/SqlSchemaCompare.Core/UpdateSchemaManager.cs b/SqlSchemaCompare.Core/UpdateSchemaManager.cs index f3b0986..0b000c5 100644 --- a/SqlSchemaCompare.Core/UpdateSchemaManager.cs +++ b/SqlSchemaCompare.Core/UpdateSchemaManager.cs @@ -16,7 +16,7 @@ public UpdateSchemaManager(ISchemaBuilder schemaBuilder) _schemaBuilder = schemaBuilder; } - private List<(DbObjectType DbObjectType, Operation Operation)> OrderItemSchema => new() + private static List<(DbObjectType DbObjectType, Operation Operation)> OrderItemSchema => new() { (DbObjectType.User, Operation.Create), (DbObjectType.User, Operation.Drop), @@ -118,7 +118,7 @@ public string UpdateSchema(IEnumerable sourceObjects, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessView(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { ProcessGenericDbObject(sourceObjects, destinationObjects, resultProcessDbObject); var originDb = sourceObjects.OfType(); @@ -133,7 +133,7 @@ private void ProcessView(IEnumerable sourceObjects, IEnumerable originIndexes, IEnumerable destinationIndexes, ResultProcessDbObject resultProcessDbObject) + private static void ProcessSingleIndex(IEnumerable originIndexes, IEnumerable destinationIndexes, ResultProcessDbObject resultProcessDbObject) { var indexToCreate = CreateDbObjectByName(originIndexes, destinationIndexes, resultProcessDbObject); var indexToDrop = DropDbObjectByName(originIndexes, destinationIndexes) @@ -151,7 +151,7 @@ private void ProcessSingleIndex(IEnumerable originIndexes, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessMember(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType(); @@ -166,7 +166,7 @@ private void ProcessMember(IEnumerable sourceObjects, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessTrigger(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { (var toCreate, var toAlter, _) = ProcessGenericDbObject(sourceObjects, destinationObjects, resultProcessDbObject); @@ -179,7 +179,7 @@ private void ProcessTrigger(IEnumerable sourceObjects, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessUser(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType(); @@ -194,7 +194,7 @@ private void ProcessUser(IEnumerable sourceObjects, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessRole(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType(); @@ -203,7 +203,7 @@ private void ProcessRole(IEnumerable sourceObjects, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessSchema(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType(); @@ -212,7 +212,7 @@ private void ProcessSchema(IEnumerable sourceObjects, IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static void ProcessTable(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType
(); @@ -271,7 +271,7 @@ private void ProcessTable(IEnumerable sourceObjects, IEnumerable columnsToAdd; IList columnsToDrop; @@ -333,13 +333,13 @@ private void ProcessTableColumn(Table table, Table destinationTable, ResultProce resultProcessDbObject.AddOperation(indexToDropAndCreate, Operation.Create); } - private void ProcessDbObjectWithoutAlter(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject + private static void ProcessDbObjectWithoutAlter(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType(); - var toCreate = CreateDbObjectByName(originDb, destinationDb, resultProcessDbObject); - DropDbObjectByName(originDb, destinationDb, resultProcessDbObject); + var toCreate = CreateDbObjectByName(originDb, destinationDb, resultProcessDbObject); + DropDbObjectByName(originDb, destinationDb, resultProcessDbObject); var toAlter = originDb .Except(toCreate) @@ -349,14 +349,14 @@ private void ProcessDbObjectWithoutAlter(IEnumerable sourceObjects, resultProcessDbObject.AddOperation(toAlter, Operation.Create); } - private (List toCreate, List toAlter, List toDrop) ProcessGenericDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) + private static (List toCreate, List toAlter, List toDrop) ProcessGenericDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject { var originDb = sourceObjects.OfType(); var destinationDb = destinationObjects.OfType(); - var toCreate = CreateDbObject(originDb, destinationDb, resultProcessDbObject); - var toDrop = DropDbObject(originDb, destinationDb, resultProcessDbObject); + var toCreate = CreateDbObject(originDb, destinationDb, resultProcessDbObject); + var toDrop = DropDbObject(originDb, destinationDb, resultProcessDbObject); var toAlter = originDb .Except(toCreate) @@ -366,7 +366,7 @@ private void ProcessDbObjectWithoutAlter(IEnumerable sourceObjects, return (toCreate, toAlter, toDrop); } - private List CreateDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject + private static List CreateDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject { var toCreate = sourceObjects .Where(dbObject => sourceObjects @@ -376,7 +376,7 @@ private List CreateDbObject(IEnumerable sourceObjects, IEnumerable d resultProcessDbObject.AddOperation(toCreate, Operation.Create); return toCreate; } - private List CreateDbObjectByName(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject + private static List CreateDbObjectByName(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject { var toCreate = sourceObjects .Where(dbObject => sourceObjects @@ -386,13 +386,13 @@ private List CreateDbObjectByName(IEnumerable sourceObjects, IEnumerabl resultProcessDbObject.AddOperation(toCreate, Operation.Create); return toCreate; } - private List DropDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject + private static List DropDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject { - var toDrop = DropDbObject(sourceObjects, destinationObjects); + var toDrop = DropDbObject(sourceObjects, destinationObjects); resultProcessDbObject.AddOperation(toDrop, Operation.Drop); return toDrop; } - private List DropDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects) where T : DbObject + private static List DropDbObject(IEnumerable sourceObjects, IEnumerable destinationObjects) where T : DbObject { return destinationObjects .Where(dbObject => destinationObjects @@ -402,13 +402,13 @@ private List DropDbObject(IEnumerable sourceObjects, IEnumerable des .ToList(); } - private List DropDbObjectByName(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject + private static List DropDbObjectByName(IEnumerable sourceObjects, IEnumerable destinationObjects, ResultProcessDbObject resultProcessDbObject) where T : DbObject { var toDrop = DropDbObjectByName(sourceObjects, destinationObjects); resultProcessDbObject.AddOperation(toDrop, Operation.Drop); return toDrop; } - private List DropDbObjectByName(IEnumerable sourceObjects, IEnumerable destinationObjects) where T : DbObject + private static List DropDbObjectByName(IEnumerable sourceObjects, IEnumerable destinationObjects) where T : DbObject { return destinationObjects .Where(dbObject => destinationObjects diff --git a/SqlSchemaCompare.Test/TSql/CompareTest.cs b/SqlSchemaCompare.Test/TSql/CompareTest.cs index 566f321..c961298 100644 --- a/SqlSchemaCompare.Test/TSql/CompareTest.cs +++ b/SqlSchemaCompare.Test/TSql/CompareTest.cs @@ -140,8 +140,8 @@ public void DiscardObjects() [Fact] public void DiscardSchema_table() { - string sql1 = -$@"CREATE TABLE [schema].[TableName]( + const string sql1 = +@"CREATE TABLE [schema].[TableName]( [Id] [int] IDENTITY(1,1) NOT NULL, [col1] [char](8) NULL ) ON [db1]