fix build
This commit is contained in:
@@ -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<IUmbracoDatabaseFactory>().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<MigrationContext> logger = Mock.Of<ILogger<MigrationContext>>();
|
||||
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<ILogger<MigrationContext>>();
|
||||
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<ILogger<MigrationContext>>();
|
||||
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<ILogger<MigrationContext>>();
|
||||
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<ILogger<MigrationContext>>();
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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<MigrationContext> _logger = Mock.Of<ILogger<MigrationContext>>();
|
||||
private readonly ILogger<MigrationContext> _logger = Mock.Of<ILogger<MigrationContext>>();
|
||||
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
|
||||
|
||||
@@ -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<IUmbracoDatabase>(), Mock.Of<ILogger<MigrationContext>>());
|
||||
|
||||
[Test]
|
||||
public void RunGoodMigration()
|
||||
{
|
||||
var migrationContext =
|
||||
new MigrationContext(Mock.Of<IUmbracoDatabase>(), Mock.Of<ILogger<MigrationContext>>());
|
||||
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<IUmbracoDatabase>(), Mock.Of<ILogger<MigrationContext>>());
|
||||
var migrationContext = GetMigrationContext();
|
||||
IMigration migration = new BadMigration1(migrationContext);
|
||||
Assert.Throws<IncompleteMigrationExpressionException>(() => migration.Migrate());
|
||||
}
|
||||
@@ -80,8 +86,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations
|
||||
[Test]
|
||||
public void DetectBadMigration2()
|
||||
{
|
||||
var migrationContext =
|
||||
new MigrationContext(Mock.Of<IUmbracoDatabase>(), Mock.Of<ILogger<MigrationContext>>());
|
||||
var migrationContext = GetMigrationContext();
|
||||
IMigration migration = new BadMigration2(migrationContext);
|
||||
Assert.Throws<IncompleteMigrationExpressionException>(() => migration.Migrate());
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Migrations
|
||||
TestMigration.MigrateCount = 0;
|
||||
TestPostMigration.MigrateCount = 0;
|
||||
|
||||
new MigrationContext(database, s_loggerFactory.CreateLogger<MigrationContext>());
|
||||
new MigrationContext(plan, database, s_loggerFactory.CreateLogger<MigrationContext>());
|
||||
|
||||
var upgrader = new Upgrader(plan);
|
||||
IMigrationPlanExecutor executor = GetMigrationPlanExecutor(scopeProvider, builder);
|
||||
|
||||
Reference in New Issue
Block a user