public void InvokeMgSeeding_Returns_If_All_Scripts_Are_Applied() { ConfigManagerMock.ConfigReturns(null); DbMock.SeedingTableExists(true); ConfigManagerMock.SeedersDirectory("migrations/seeders"); FileManagerMock.GetAllFilesInFolder(new[] { "migrations/one.sql", "migrations/two.sql" }); DbMock.GetAppliedSeeders(new Seed[] { new() { SeedId = "one.sql" }, new() { SeedId = "two.sql" } });
public void InvokeMgSeeding_Throws_If_Seeders_Table_Does_Not_Exist_And_CreateTableIfNotExist_Is_False() { ConfigManagerMock.SeedersDirectory("migrations"); ConfigManagerMock.ConfigReturns(null); DbMock.SeedingTableExists(false); var command = new InvokeMgSeeding(GetMockedDependencies()) { Database = "database", Host = "host", Port = 1111, Schema = "public", Username = "******" }; Assert.Throws <Exception>(() => command.Invoke()?.OfType <bool>()?.First()); }
public void InvokeMgSeeding_Returns_If_No_Scripts_Found() { ConfigManagerMock.ConfigReturns(null); DbMock.SeedingTableExists(true); FileManagerMock.GetAllFilesInFolder(Array.Empty <string>()); ConfigManagerMock.SeedersDirectory("migrations/seeders"); var command = new InvokeMgSeeding(GetMockedDependencies()) { Database = "database", Host = "host", Port = 1111, Schema = "public", Username = "******" }; var result = command.Invoke()?.OfType <MgResult>()?.First(); Assert.False(result.Successful); }
public void InvokeMgSeeding_Creates_Seeders_Table_If_CreateTableIfNotExist_Is_True() { ConfigManagerMock.ConfigReturns(null); ConfigManagerMock.SeedersDirectory("migrations/seeders"); DbMock.SeedingTableExists(false); DbMock.CreateSeedersTable(1); FileManagerMock.GetAllFilesInFolder(Array.Empty <string>()); ConfigManagerMock.SeedersDirectory("migrations/seeders"); var command = new InvokeMgSeeding(GetMockedDependencies()) { Database = "database", Host = "host", Port = 1111, Schema = "public", Username = "******", CreateTableIfNotExist = true }; command.Invoke()?.OfType <string>()?.ToArray(); DbMock.VerifyCreateSeedersTable(Times.Once()); }
public void NewMgSeeder_Creates_Seeds_Directory_If_Not_Exists() { var seedPath = Path.Join("migrations", "seeders"); ConfigManagerMock.SeedersDirectory(seedPath); FileManagerMock.DirectoryExists(seedPath, false); FileManagerMock.CreateDirectory(seedPath); FileManagerMock.GetFilePrefix("test_prefix"); FileManagerMock.GetFormattedName("file_name"); FileManagerMock.FileExists("migrations/seeders/test_prefix_file_name.sql", false); FileManagerMock.CreateFile("migrations/seeders/test_prefix_file_name.sql"); var command = new NewMgSeeder(GetMockedDependencies()) { Name = "This is my migration" }; var result = command.Invoke()?.OfType <string>().First(); Assert.NotNull(result); Assert.Contains(seedPath, result); FileManagerMock.VerifyCreateDirectory(seedPath, Times.Once()); FileManagerMock.VerifyCreateFile("migrations/seeders/test_prefix_file_name.sql", Times.Once()); }