-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / Run tests (Basic_tests)
Check failure on line 20 in unittests/Basic_tests/GrateMigrator_MigrationStatus.cs GitHub Actions / Analyze Code Security
|
||
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"); | ||
} | ||
|
||
} |