From e8201a09effd9465e13f866068b2173266fef91c Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 11 Jun 2021 12:08:09 -0600 Subject: [PATCH] fix build --- .../SqlServerSyntaxProviderTests.cs | 43 ++++++++++--------- .../Migrations/AlterMigrationTests.cs | 26 +++++++---- .../Migrations/MigrationTests.cs | 17 +++++--- .../Migrations/PostMigrationTests.cs | 2 +- 4 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SyntaxProvider/SqlServerSyntaxProviderTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SyntaxProvider/SqlServerSyntaxProviderTests.cs index 800b702888..a90d357b0e 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SyntaxProvider/SqlServerSyntaxProviderTests.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/SyntaxProvider/SqlServerSyntaxProviderTests.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Diagnostics; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -6,6 +6,7 @@ using Moq; using NPoco; using NUnit.Framework; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.Migrations; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Infrastructure.Migrations.Expressions.Common.Expressions; using Umbraco.Cms.Infrastructure.Migrations.Expressions.Create.Index; @@ -26,6 +27,20 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Synta public class SqlServerSyntaxProviderTests : UmbracoIntegrationTest { private ISqlContext SqlContext => GetRequiredService().SqlContext; + private SqlServerSyntaxProvider GetSqlSyntax() => new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); + private class TestPlan : MigrationPlan + { + public TestPlan() : base("Test") + { + } + } + private MigrationContext GetMigrationContext(out TestDatabase db) + { + ILogger logger = Mock.Of>(); + SqlServerSyntaxProvider sqlSyntax = GetSqlSyntax(); + db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); + return new MigrationContext(new TestPlan(), db, logger); + } [UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerTest)] [Test] @@ -80,19 +95,19 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void Format_SqlServer_NonClusteredIndexDefinition_AddsNonClusteredDirective() { - var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); + SqlServerSyntaxProvider sqlSyntax = GetSqlSyntax(); var indexDefinition = CreateIndexDefinition(); indexDefinition.IndexType = IndexTypes.NonClustered; var actual = sqlSyntax.Format(indexDefinition); - Assert.AreEqual("CREATE NONCLUSTERED INDEX [IX_A] ON [TheTable] ([A])", actual); + Assert.AreEqual("CREATE NONCLUSTERED INDEX [IX_A] ON [TheTable] ([A])", actual); } [Test] public void Format_SqlServer_NonClusteredIndexDefinition_UsingIsClusteredFalse_AddsClusteredDirective() { - var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); + SqlServerSyntaxProvider sqlSyntax = GetSqlSyntax(); var indexDefinition = CreateIndexDefinition(); indexDefinition.IndexType = IndexTypes.Clustered; @@ -104,10 +119,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_NonClustered_CreatesNonClusteredIndex() { - var logger = Mock.Of>(); - var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); - var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); - var context = new MigrationContext(db, logger); + var context = GetMigrationContext(out var db); var createExpression = new CreateIndexExpression(context) { @@ -125,10 +137,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_Unique_CreatesUniqueNonClusteredIndex() { - var logger = Mock.Of>(); - var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); - var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); - var context = new MigrationContext(db, logger); + var context = GetMigrationContext(out var db); var createExpression = new CreateIndexExpression(context) { @@ -146,10 +155,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_Unique_CreatesUniqueNonClusteredIndex_Multi_Columnn() { - var logger = Mock.Of>(); - var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); - var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); - var context = new MigrationContext(db, logger); + var context = GetMigrationContext(out var db); var createExpression = new CreateIndexExpression(context) { @@ -167,10 +173,7 @@ WHERE (([umbracoNode].[nodeObjectType] = @0))) x)".Replace(Environment.NewLine, [Test] public void CreateIndexBuilder_SqlServer_Clustered_CreatesClusteredIndex() { - var logger = Mock.Of>(); - var sqlSyntax = new SqlServerSyntaxProvider(Options.Create(new GlobalSettings())); - var db = new TestDatabase(DatabaseType.SqlServer2005, sqlSyntax); - var context = new MigrationContext(db, logger); + var context = GetMigrationContext(out var db); var createExpression = new CreateIndexExpression(context) { diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/AlterMigrationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/AlterMigrationTests.cs index bfe11a9878..bd54ca1b33 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/AlterMigrationTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/AlterMigrationTests.cs @@ -7,6 +7,7 @@ using System.Linq; using Microsoft.Extensions.Logging; using Moq; using NUnit.Framework; +using Umbraco.Cms.Core.Migrations; using Umbraco.Cms.Infrastructure.Migrations; using Umbraco.Cms.Tests.Common.TestHelpers; using Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations.Stubs; @@ -16,14 +17,24 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations [TestFixture] public class AlterMigrationTests { - private readonly ILogger _logger = Mock.Of>(); + private readonly ILogger _logger = Mock.Of>(); + private class TestPlan : MigrationPlan + { + public TestPlan() : base("Test") + { + } + } + private MigrationContext GetMigrationContext(out TestDatabase db) + { + db = new TestDatabase(); + return new MigrationContext(new TestPlan(), db, _logger); + } [Test] public void Drop_Foreign_Key() { // Arrange - var database = new TestDatabase(); - var context = new MigrationContext(database, _logger); + var context = GetMigrationContext(out var database); var stub = new DropForeignKeyMigrationStub(context); // Act @@ -44,8 +55,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations [Test] public void CreateColumn() { - var database = new TestDatabase(); - var context = new MigrationContext(database, _logger); + var context = GetMigrationContext(out var database); var migration = new CreateColumnMigration(context); migration.Migrate(); @@ -74,8 +84,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations [Test] public void AlterColumn() { - var database = new TestDatabase(); - var context = new MigrationContext(database, _logger); + var context = GetMigrationContext(out var database); var migration = new AlterColumnMigration(context); migration.Migrate(); @@ -110,8 +119,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations public void Can_Get_Up_Migration_From_MigrationStub() { // Arrange - var database = new TestDatabase(); - var context = new MigrationContext(database, _logger); + var context = GetMigrationContext(out var database); var stub = new AlterUserTableMigrationStub(context); // Act diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs index f118de46e0..8a14ae689e 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/MigrationTests.cs @@ -59,11 +59,18 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations #endif } + private class TestPlan : MigrationPlan + { + public TestPlan() : base("Test") + { + } + } + private MigrationContext GetMigrationContext() => new MigrationContext(new TestPlan(), Mock.Of(), Mock.Of>()); + [Test] public void RunGoodMigration() { - var migrationContext = - new MigrationContext(Mock.Of(), Mock.Of>()); + var migrationContext = GetMigrationContext(); IMigration migration = new GoodMigration(migrationContext); migration.Migrate(); } @@ -71,8 +78,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations [Test] public void DetectBadMigration1() { - var migrationContext = - new MigrationContext(Mock.Of(), Mock.Of>()); + var migrationContext = GetMigrationContext(); IMigration migration = new BadMigration1(migrationContext); Assert.Throws(() => migration.Migrate()); } @@ -80,8 +86,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations [Test] public void DetectBadMigration2() { - var migrationContext = - new MigrationContext(Mock.Of(), Mock.Of>()); + var migrationContext = GetMigrationContext(); IMigration migration = new BadMigration2(migrationContext); Assert.Throws(() => migration.Migrate()); } diff --git a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs index 3952dea607..2400f2560c 100644 --- a/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs +++ b/src/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Migrations/PostMigrationTests.cs @@ -113,7 +113,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations TestMigration.MigrateCount = 0; TestPostMigration.MigrateCount = 0; - new MigrationContext(database, s_loggerFactory.CreateLogger()); + new MigrationContext(plan, database, s_loggerFactory.CreateLogger()); var upgrader = new Upgrader(plan); IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, builder);