diff --git a/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs index a3a39076926..8eff702d214 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Migrations/MigrationsSqlServerTest.cs @@ -17,9 +17,6 @@ namespace Microsoft.EntityFrameworkCore.Migrations; public class MigrationsSqlServerTest : MigrationsTestBase { - protected static string EOL - => Environment.NewLine; - public MigrationsSqlServerTest(MigrationsSqlServerFixture fixture, ITestOutputHelper testOutputHelper) : base(fixture) { diff --git a/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs b/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs index 1b7c452edf9..656cc822af5 100644 --- a/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs +++ b/test/EFCore.SqlServer.Tests/Migrations/SqlServerHistoryRepositoryTest.cs @@ -8,26 +8,20 @@ namespace Microsoft.EntityFrameworkCore.Migrations; public class SqlServerHistoryRepositoryTest { - private static string EOL - => Environment.NewLine; - [ConditionalFact] public void GetCreateScript_works() { var sql = CreateHistoryRepository().GetCreateScript(); Assert.Equal( - "CREATE TABLE [__EFMigrationsHistory] (" - + EOL - + " [MigrationId] nvarchar(150) NOT NULL," - + EOL - + " [ProductVersion] nvarchar(32) NOT NULL," - + EOL - + " CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])" - + EOL - + ");" - + EOL, - sql); +""" +CREATE TABLE [__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) +); + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -36,19 +30,15 @@ public void GetCreateScript_works_with_schema() var sql = CreateHistoryRepository("my").GetCreateScript(); Assert.Equal( - "IF SCHEMA_ID(N'my') IS NULL EXEC(N'CREATE SCHEMA [my];');" - + EOL - + "CREATE TABLE [my].[__EFMigrationsHistory] (" - + EOL - + " [MigrationId] nvarchar(150) NOT NULL," - + EOL - + " [ProductVersion] nvarchar(32) NOT NULL," - + EOL - + " CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])" - + EOL - + ");" - + EOL, - sql); +""" +IF SCHEMA_ID(N'my') IS NULL EXEC(N'CREATE SCHEMA [my];'); +CREATE TABLE [my].[__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) +); + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -57,23 +47,17 @@ public void GetCreateIfNotExistsScript_works() var sql = CreateHistoryRepository().GetCreateIfNotExistsScript(); Assert.Equal( - "IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL" - + EOL - + "BEGIN" - + EOL - + " CREATE TABLE [__EFMigrationsHistory] (" - + EOL - + " [MigrationId] nvarchar(150) NOT NULL," - + EOL - + " [ProductVersion] nvarchar(32) NOT NULL," - + EOL - + " CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])" - + EOL - + " );" - + EOL - + "END;" - + EOL, - sql); +""" +IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL +BEGIN + CREATE TABLE [__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -82,25 +66,18 @@ public void GetCreateIfNotExistsScript_works_with_schema() var sql = CreateHistoryRepository("my").GetCreateIfNotExistsScript(); Assert.Equal( - "IF OBJECT_ID(N'[my].[__EFMigrationsHistory]') IS NULL" - + EOL - + "BEGIN" - + EOL - + " IF SCHEMA_ID(N'my') IS NULL EXEC(N'CREATE SCHEMA [my];');" - + EOL - + " CREATE TABLE [my].[__EFMigrationsHistory] (" - + EOL - + " [MigrationId] nvarchar(150) NOT NULL," - + EOL - + " [ProductVersion] nvarchar(32) NOT NULL," - + EOL - + " CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])" - + EOL - + " );" - + EOL - + "END;" - + EOL, - sql); +""" +IF OBJECT_ID(N'[my].[__EFMigrationsHistory]') IS NULL +BEGIN + IF SCHEMA_ID(N'my') IS NULL EXEC(N'CREATE SCHEMA [my];'); + CREATE TABLE [my].[__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -109,8 +86,11 @@ public void GetDeleteScript_works() var sql = CreateHistoryRepository().GetDeleteScript("Migration1"); Assert.Equal( - "DELETE FROM [__EFMigrationsHistory]" + EOL + "WHERE [MigrationId] = N'Migration1';" + EOL, - sql); +""" +DELETE FROM [__EFMigrationsHistory] +WHERE [MigrationId] = N'Migration1'; + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -120,8 +100,11 @@ public void GetInsertScript_works() new HistoryRow("Migration1", "7.0.0")); Assert.Equal( - "INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])" + EOL + "VALUES (N'Migration1', N'7.0.0');" + EOL, - sql); +""" +INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion]) +VALUES (N'Migration1', N'7.0.0'); + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -130,8 +113,10 @@ public void GetBeginIfNotExistsScript_works() var sql = CreateHistoryRepository().GetBeginIfNotExistsScript("Migration1"); Assert.Equal( - "IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'Migration1')" + EOL + "BEGIN", - sql); +""" +IF NOT EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'Migration1') +BEGIN +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -140,8 +125,10 @@ public void GetBeginIfExistsScript_works() var sql = CreateHistoryRepository().GetBeginIfExistsScript("Migration1"); Assert.Equal( - "IF EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'Migration1')" + EOL + "BEGIN", - sql); +""" +IF EXISTS(SELECT * FROM [__EFMigrationsHistory] WHERE [MigrationId] = N'Migration1') +BEGIN +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -149,7 +136,11 @@ public void GetEndIfScript_works() { var sql = CreateHistoryRepository().GetEndIfScript(); - Assert.Equal("END;" + EOL, sql); + Assert.Equal( +""" +END; + +""", sql, ignoreLineEndingDifferences: true); } private static IHistoryRepository CreateHistoryRepository(string schema = null) diff --git a/test/EFCore.Sqlite.Tests/Migrations/SqliteHistoryRepositoryTest.cs b/test/EFCore.Sqlite.Tests/Migrations/SqliteHistoryRepositoryTest.cs index 1eaac2b1bd0..15329834da4 100644 --- a/test/EFCore.Sqlite.Tests/Migrations/SqliteHistoryRepositoryTest.cs +++ b/test/EFCore.Sqlite.Tests/Migrations/SqliteHistoryRepositoryTest.cs @@ -8,24 +8,19 @@ namespace Microsoft.EntityFrameworkCore.Migrations; public class SqliteHistoryRepositoryTest { - private static string EOL - => Environment.NewLine; - [ConditionalFact] public void GetCreateScript_works() { var sql = CreateHistoryRepository().GetCreateScript(); Assert.Equal( - "CREATE TABLE \"__EFMigrationsHistory\" (" - + EOL - + " \"MigrationId\" TEXT NOT NULL CONSTRAINT \"PK___EFMigrationsHistory\" PRIMARY KEY," - + EOL - + " \"ProductVersion\" TEXT NOT NULL" - + EOL - + ");" - + EOL, - sql); +""" +CREATE TABLE "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL +); + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -34,15 +29,13 @@ public void GetCreateIfNotExistsScript_works() var sql = CreateHistoryRepository().GetCreateIfNotExistsScript(); Assert.Equal( - "CREATE TABLE IF NOT EXISTS \"__EFMigrationsHistory\" (" - + EOL - + " \"MigrationId\" TEXT NOT NULL CONSTRAINT \"PK___EFMigrationsHistory\" PRIMARY KEY," - + EOL - + " \"ProductVersion\" TEXT NOT NULL" - + EOL - + ");" - + EOL, - sql); +""" +CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( + "MigrationId" TEXT NOT NULL CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY, + "ProductVersion" TEXT NOT NULL +); + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -51,8 +44,11 @@ public void GetDeleteScript_works() var sql = CreateHistoryRepository().GetDeleteScript("Migration1"); Assert.Equal( - "DELETE FROM \"__EFMigrationsHistory\"" + EOL + "WHERE \"MigrationId\" = 'Migration1';" + EOL, - sql); +""" +DELETE FROM "__EFMigrationsHistory" +WHERE "MigrationId" = 'Migration1'; + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact] @@ -62,11 +58,11 @@ public void GetInsertScript_works() new HistoryRow("Migration1", "7.0.0")); Assert.Equal( - "INSERT INTO \"__EFMigrationsHistory\" (\"MigrationId\", \"ProductVersion\")" - + EOL - + "VALUES ('Migration1', '7.0.0');" - + EOL, - sql); +""" +INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") +VALUES ('Migration1', '7.0.0'); + +""", sql, ignoreLineEndingDifferences: true); } [ConditionalFact]