Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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

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.

{
[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);
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ public override bool ViewExists(string viewName)
// This is not clean! Usually you should use schema as well as this query will find views in other tables as well!

using var cmd = CreateCommand();
using var reader = ExecuteQuery(cmd, $"SELECT OBJECT_ID('{viewName}', 'V')");
cmd.CommandText = $"SELECT OBJECT_ID(@FullViewName, 'V')";

var parameter = cmd.CreateParameter();
parameter.ParameterName = "@FullViewName";
parameter.Value = viewName;
cmd.Parameters.Add(parameter);

var result = cmd.ExecuteScalar();

Expand Down
Loading