Skip to content

Commit

Permalink
WIP: no-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbra committed May 16, 2024
1 parent 5f69746 commit c40d278
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/grate.core/Migration/GrateMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ public async Task Migrate()
changeDropFolder);

Separator(' ');


}

private async Task EnsureConnectionIsOpen(ConnectionType connectionType)
Expand Down
84 changes: 84 additions & 0 deletions unittests/Basic_tests/GrateMigrator_MigrationStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using FluentAssertions;
using grate.Configuration;
using grate.Infrastructure;
using grate.Migration;
using Microsoft.Extensions.Logging;
using NSubstitute;

namespace Basic_tests;

// ReSharper disable once InconsistentNaming
public class GrateMigrator_MigrationStatus
{
private readonly IDbMigrator _dbMigrator = CreateDbMigrator();

private static IDbMigrator CreateDbMigrator()
{
var dbMigrator = Substitute.For<IDbMigrator>();
// Create stuff here that returns some of the scripts as run, some not.
// Then check on the result.
dbMigrator.RunSql()

Check failure on line 20 in unittests/Basic_tests/GrateMigrator_MigrationStatus.cs

View workflow job for this annotation

GitHub Actions / Run tests (Basic_tests)

; expected

Check failure on line 20 in unittests/Basic_tests/GrateMigrator_MigrationStatus.cs

View workflow job for this annotation

GitHub Actions / Analyze Code Security

; expected

Check failure on line 20 in unittests/Basic_tests/GrateMigrator_MigrationStatus.cs

View workflow job for this annotation

GitHub Actions / Analyze Code Security

; expected
return dbMigrator;
}

private readonly GrateConfiguration? _config = new GrateConfiguration();

[Fact]
public void Includes_List_of_ScriptsRun()
{
_dbMigrator.DatabaseName.Returns("server1");
var dbMigrator = new DbMigrator(_dbMigrator, null!, null!, _config);

var grateMigrator = new GrateMigrator(null!, dbMigrator);

grateMigrator.Database.DatabaseName.Should().Be("server1");

var changedDatabase = Substitute.For<IDatabase>();
changedDatabase.DatabaseName.Returns("server2");

var changedMigrator = grateMigrator.WithDatabase(changedDatabase) as GrateMigrator;

grateMigrator.Database.DatabaseName.Should().Be("server1");
changedMigrator!.Database.DatabaseName.Should().Be("server2");
}

[Fact]
public void Includes_IsUptoDate_Flag()
{
_dbMigrator.DatabaseName.Returns("server1");
var dbMigrator = new DbMigrator(_dbMigrator, null!, null!, _config);

var grateMigrator = new GrateMigrator(null!, dbMigrator);

grateMigrator.Database.DatabaseName.Should().Be("server1");

var changedDatabase = Substitute.For<IDatabase>();
changedDatabase.DatabaseName.Returns("server2");

var changedMigrator = grateMigrator.WithDatabase(changedDatabase) as GrateMigrator;

grateMigrator.Database.DatabaseName.Should().Be("server1");
changedMigrator!.Database.DatabaseName.Should().Be("server2");
}


[Fact]
public void Includes_Success_flag()
{
_dbMigrator.DatabaseName.Returns("server1");
var dbMigrator = new DbMigrator(_dbMigrator, null!, null!, _config);

var grateMigrator = new GrateMigrator(null!, dbMigrator);

grateMigrator.Database.DatabaseName.Should().Be("server1");

var changedDatabase = Substitute.For<IDatabase>();
changedDatabase.DatabaseName.Returns("server2");

var changedMigrator = grateMigrator.WithDatabase(changedDatabase) as GrateMigrator;

grateMigrator.Database.DatabaseName.Should().Be("server1");
changedMigrator!.Database.DatabaseName.Should().Be("server2");
}

}

0 comments on commit c40d278

Please sign in to comment.