forked from bittercoder/Migrator.NET
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Added TableExists and ViewExists Tests #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/Migrator.Tests/Providers/OracleProvider/Base/OracleTransformationProviderTestBase.cs
This file contains hidden or 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,47 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using DotNetProjects.Migrator.Providers; | ||
| using DotNetProjects.Migrator.Providers.Impl.Oracle; | ||
| using DryIoc; | ||
| using Migrator.Tests.Database; | ||
| using Migrator.Tests.Database.Interfaces; | ||
| using Migrator.Tests.Providers.Base; | ||
| using Migrator.Tests.Settings; | ||
| using Migrator.Tests.Settings.Config; | ||
| using Migrator.Tests.Settings.Models; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.OracleProvider.Base; | ||
|
|
||
| public class OracleTransformationProviderTestBase : TransformationProviderSimpleBase | ||
| { | ||
| [SetUp] | ||
| public async Task SetUpAsync() | ||
| { | ||
| using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | ||
| var configReader = new ConfigurationReader(); | ||
|
|
||
| var databaseConnectionConfig = configReader.GetDatabaseConnectionConfigById(DatabaseConnectionConfigIds.OracleId); | ||
|
|
||
| var connectionString = databaseConnectionConfig?.ConnectionString; | ||
|
|
||
| if (string.IsNullOrEmpty(connectionString)) | ||
| { | ||
| throw new IgnoreException($"No Oracle {nameof(DatabaseConnectionConfig.ConnectionString)} is set."); | ||
| } | ||
|
|
||
| DbProviderFactories.RegisterFactory("Oracle.ManagedDataAccess.Client", () => Oracle.ManagedDataAccess.Client.OracleClientFactory.Instance); | ||
|
|
||
| using var container = new Container(); | ||
| container.RegisterDatabaseIntegrationTestService(); | ||
| var databaseIntegrationTestServiceFactory = container.Resolve<IDatabaseIntegrationTestServiceFactory>(); | ||
| var oracleIntegrationTestService = databaseIntegrationTestServiceFactory.Create(DatabaseProviderType.Oracle); | ||
| var databaseInfo = await oracleIntegrationTestService.CreateTestDatabaseAsync(databaseConnectionConfig, cts.Token); | ||
|
|
||
| Provider = new OracleTransformationProvider(new OracleDialect(), databaseInfo.DatabaseConnectionConfig.ConnectionString, null, "default", "Oracle.ManagedDataAccess.Client"); | ||
| Provider.BeginTransaction(); | ||
|
|
||
| AddDefaultTable(); | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/Migrator.Tests/Providers/OracleProvider/OracleTransformationProvider_TableExistsTests.cs
This file contains hidden or 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,42 @@ | ||
| using System.Data; | ||
| using DotNetProjects.Migrator.Framework; | ||
| using Migrator.Tests.Providers.OracleProvider.Base; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.OracleProvider; | ||
|
|
||
| [TestFixture] | ||
| [Category("Oracle")] | ||
| public class OracleTransformationProvider_TableExistsTests : OracleTransformationProviderTestBase | ||
| { | ||
| [Test] | ||
| public void TableExists_TableExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists(testTableName); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TableExists_TableDoesNotExist_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| const string myTableName = "MyTable"; | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists(myTableName); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.False); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
src/Migrator.Tests/Providers/OracleProvider/OracleTransformationProvider_ViewExistsTests.cs
This file contains hidden or 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,45 @@ | ||
| using System.Data; | ||
| using DotNetProjects.Migrator.Framework; | ||
| using Migrator.Tests.Providers.OracleProvider.Base; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.OracleProvider; | ||
|
|
||
| [TestFixture] | ||
| [Category("Oracle")] | ||
| public class OracleTransformationProvider_ViewExistsTests : OracleTransformationProviderTestBase | ||
| { | ||
| [Test] | ||
| public void ViewExists_ViewExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string myViewName = "MyView"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| Provider.ExecuteNonQuery($"CREATE VIEW {myViewName} AS SELECT {propertyName1} FROM {testTableName}"); | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists(myViewName); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ViewExists_ViewDoesNotExist_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| const string myViewName = "MyView"; | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists(myViewName); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.False); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
src/Migrator.Tests/Providers/PostgreSQL/PostgreSQLTransformationProvider_TableExistsTests.cs
This file contains hidden or 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,41 @@ | ||
| using System.Data; | ||
| using DotNetProjects.Migrator.Framework; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.PostgreSQL; | ||
|
|
||
| [TestFixture] | ||
| [Category("Postgre")] | ||
| public class PostgreSQLTransformationProvider_TableExistsTests : PostgreSQLTransformationProviderTestBase | ||
| { | ||
| [Test] | ||
| public void TableExists_TableExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists(testTableName); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TableExists_TableDoesNotExist_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| const string myTableName = "MyTable"; | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists(myTableName); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.False); | ||
| } | ||
| } |
44 changes: 44 additions & 0 deletions
44
src/Migrator.Tests/Providers/PostgreSQL/PostgreSQLTransformationProvider_ViewExistsTests.cs
This file contains hidden or 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,44 @@ | ||
| using System.Data; | ||
| using DotNetProjects.Migrator.Framework; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.PostgreSQL; | ||
|
|
||
| [TestFixture] | ||
| [Category("Postgre")] | ||
| public class PostgreSQLTransformationProvider_ViewExistsTests : PostgreSQLTransformationProviderTestBase | ||
| { | ||
| [Test] | ||
| public void ViewExists_ViewExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string myViewName = "MyView"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| Provider.ExecuteNonQuery($"CREATE VIEW {myViewName} AS SELECT {propertyName1} FROM {testTableName}"); | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists(myViewName); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ViewExists_ViewDoesNotExist_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| const string myViewName = "MyView"; | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists(myViewName); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.False); | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
src/Migrator.Tests/Providers/SQLServer/SQLServerTransformationProvider_TableExists.cs
This file contains hidden or 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,60 @@ | ||
| using System.Data; | ||
| using DotNetProjects.Migrator.Framework; | ||
| using Migrator.Tests.Providers.SQLServer.Base; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.SQLServer; | ||
|
|
||
| [TestFixture] | ||
| [Category("SqlServer")] | ||
| public class SQLServerTransformationProvider_TableExistsTests : SQLServerTransformationProviderTestBase | ||
| { | ||
| [Test] | ||
| public void TableExists_WithSchemaNameTableExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists($"dbo.{testTableName}"); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TableExists_NoSchemaNameTableExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists(testTableName); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TableExists_TableDoesNotExist_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| const string myTableName = "MyTableName"; | ||
|
|
||
| // Act | ||
| var tableExists = Provider.TableExists(myTableName); | ||
|
|
||
| // Assert | ||
| Assert.That(tableExists, Is.False); | ||
| } | ||
| } | ||
66 changes: 66 additions & 0 deletions
66
src/Migrator.Tests/Providers/SQLServer/SQLServerTransformationProvider_ViewExistsTests.cs
This file contains hidden or 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,66 @@ | ||
| using System.Data; | ||
| using DotNetProjects.Migrator.Framework; | ||
| using Migrator.Tests.Providers.SQLServer.Base; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Migrator.Tests.Providers.SQLServer; | ||
|
|
||
| [TestFixture] | ||
| [Category("SqlServer")] | ||
| public class SQLServerTransformationProvider_ViewExistsTests : SQLServerTransformationProviderTestBase | ||
| { | ||
| [Test] | ||
| public void ViewExists_WithSchemaNameViewExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string myViewName = "MyView"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| Provider.ExecuteNonQuery($"CREATE VIEW dbo.{myViewName} AS SELECT {propertyName1} FROM dbo.{testTableName}"); | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists($"dbo.{myViewName}"); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ViewExists_NoSchemaNameViewExists_Returns() | ||
| { | ||
| // Arrange | ||
| const string testTableName = "MyDefaultTestTable"; | ||
| const string myViewName = "MyView"; | ||
| const string propertyName1 = "Color1"; | ||
|
|
||
| Provider.AddTable(testTableName, | ||
| new Column(propertyName1, DbType.Int32) | ||
| ); | ||
|
|
||
| Provider.ExecuteNonQuery($"CREATE VIEW dbo.{myViewName} AS SELECT {propertyName1} FROM dbo.{testTableName}"); | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists(myViewName); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void ViewExists_ViewDoesNotExist_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| const string myViewName = "MyView"; | ||
|
|
||
| // Act | ||
| var viewExists = Provider.ViewExists(myViewName); | ||
|
|
||
| // Assert | ||
| Assert.That(viewExists, Is.False); | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name nicht gleich wie Datei.