Skip to content

Commit

Permalink
Added tests and upgraded to version 2.6.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-ordonez-mdevs committed Feb 25, 2021
1 parent e4f9901 commit 44cf1ee
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/Paradigm.ORM.Data.Cassandra/CqlDatabaseConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public bool IsOpen()
/// </returns>
public IDatabaseTransaction CreateTransaction()
{
if (!this.IsOpen())
this.Open();

return this.CreateTransaction(IsolationLevel.Serializable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<Authors>Miracle Devs</Authors>
<Company>Miracle Devs</Company>
<Product>Paradigm.ORM</Product>
Expand Down
3 changes: 3 additions & 0 deletions src/Paradigm.ORM.Data.MySql/MySqlDatabaseConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public bool IsOpen()
/// </returns>
public IDatabaseTransaction CreateTransaction()
{
if (!this.IsOpen())
this.Open();

return this.CreateTransaction(IsolationLevel.Serializable);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Paradigm.ORM.Data.MySql/Paradigm.ORM.Data.MySql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryType>git</RepositoryType>
<Authors>Miracle Devs</Authors>
<Company>Miracle Devs</Company>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<Product>Paradigm.ORM</Product>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Miracle Devs</Company>
<Copyright>Miracle Devs</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<Product>Paradigm.ORM</Product>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public bool IsOpen()
/// </returns>
public IDatabaseTransaction CreateTransaction()
{
if (!this.IsOpen())
this.Open();

return this.CreateTransaction(IsolationLevel.Serializable);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/MiracleDevs/Paradigm.ORM.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<Product>Paradigm.ORM</Product>
</PropertyGroup>

Expand Down
3 changes: 3 additions & 0 deletions src/Paradigm.ORM.Data.SqlServer/SqlDatabaseConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ public bool IsOpen()
/// </returns>
public IDatabaseTransaction CreateTransaction()
{
if (!this.IsOpen())
this.Open();

return this.CreateTransaction(IsolationLevel.Serializable);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Paradigm.ORM.Data/Paradigm.ORM.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RepositoryType>git</RepositoryType>
<Authors>Miracle Devs</Authors>
<Company>Miracle Devs</Company>
<Version>2.6.0</Version>
<Version>2.6.1</Version>
<Product>Paradigm.ORM</Product>
</PropertyGroup>

Expand Down
8 changes: 4 additions & 4 deletions src/Paradigm.ORM.Tests/Fixtures/ConnectionStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{
public class ConnectionStrings
{
public const string Cql = "Contact Points=localhost;Port=9042;Default Keyspace=test;Username=root";
public const string Cql = "Contact Points=127.0.0.1;Port=9042;Default Keyspace=test;Username=root";

public const string MySql = "Server=localhost;Database=test;User=root;Password=Paradigm_Test_1234;Connection Timeout=3600;Allow User Variables=True;POOLING=true";
public const string MySql = "Server=127.0.0.1;Database=test;User=root;Password=Paradigm_Test_1234;Connection Timeout=3600;Allow User Variables=True;POOLING=true";

public const string PSql = "Server=localhost;User Id=postgres;Password=Paradigm_Test_1234;Timeout=3;Database=test";
public const string PSql = "Server=127.0.0.1;User Id=postgres;Password=Paradigm_Test_1234;Timeout=3;Database=test";

public const string MsSql = "Server=localhost;User=sa;Password=Paradigm_Test_1234;Connection Timeout=3600";
public const string MsSql = "Server=127.0.0.1;User=sa;Password=Paradigm_Test_1234;Connection Timeout=3600";
}
}
132 changes: 132 additions & 0 deletions src/Paradigm.ORM.Tests/Tests/TransactionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Paradigm.ORM.Data.ValueProviders;
using Paradigm.ORM.Tests.Fixtures;
using Paradigm.ORM.Tests.Fixtures.MySql;
using Paradigm.ORM.Tests.Fixtures.PostgreSql;
using Paradigm.ORM.Tests.Fixtures.Sql;
using Paradigm.ORM.Tests.Fixtures.Cql;
using NUnit.Framework;
using Paradigm.ORM.Data.Mappers;


namespace Paradigm.ORM.Tests.Tests
{
[TestFixture]
public class TransactionTest
{
[Order(1)]
[TestCase(typeof(MySqlCrudCommandFixture))]
[TestCase(typeof(SqlCrudCommandFixture))]
[TestCase(typeof(PostgreSqlCrudCommandFixture))]
public void ShouldCreateATransaction(Type fixtureType)
{
var fixture = Activator.CreateInstance(fixtureType) as CrudCommandFixtureBase;

fixture.CreateDatabase();
fixture.CreateTables();

var insertCommandBuilder = fixture.Connector.GetCommandBuilderFactory().CreateInsertCommandBuilder(fixture.GetParentDescriptor());
var entityToInsert = fixture.CreateNewEntity();
var valueProvider = new ClassValueProvider(fixture.Connector, new List<object> { entityToInsert });
valueProvider.MoveNext();
var insertCommand = insertCommandBuilder.GetCommand(valueProvider);

using (var transaction = fixture.Connector.CreateTransaction())
{
if (fixtureType == typeof(CqlCrudCommandFixture))
insertCommand.ExecuteNonQuery().Should().Be(-1);
else
insertCommand.ExecuteNonQuery().Should().Be(1);
}

fixture.DropDatabase();
}

[Order(2)]
[TestCase(typeof(MySqlCrudCommandFixture))]
[TestCase(typeof(SqlCrudCommandFixture))]
[TestCase(typeof(PostgreSqlCrudCommandFixture))]
public void ShouldCommitATransaction(Type fixtureType)
{
var fixture = Activator.CreateInstance(fixtureType) as CrudCommandFixtureBase;

fixture.CreateDatabase();
fixture.CreateTables();

var insertCommandBuilder = fixture.Connector.GetCommandBuilderFactory().CreateInsertCommandBuilder(fixture.GetParentDescriptor());
var selectCommandBuilder = fixture.Connector.GetCommandBuilderFactory().CreateSelectCommandBuilder(fixture.GetParentDescriptor());
var entityToInsert = fixture.CreateNewEntity();
var valueProvider = new ClassValueProvider(fixture.Connector, new List<object> { entityToInsert });
valueProvider.MoveNext();
var insertCommand = insertCommandBuilder.GetCommand(valueProvider);
var selectCommand = selectCommandBuilder.GetCommand();

using (var transaction = fixture.Connector.CreateTransaction())
{
if (fixtureType == typeof(CqlCrudCommandFixture))
insertCommand.ExecuteNonQuery().Should().Be(-1);
else
insertCommand.ExecuteNonQuery().Should().Be(1);

transaction.Commit();
}

using (var reader = selectCommand.ExecuteReader())
{
reader.Should().NotBeNull();

var mapper = new DatabaseReaderMapper(fixture.Connector, fixture.GetParentDescriptor());
var results = mapper.Map(reader);

results.Should().NotBeNull().And.HaveCount(1);
}

fixture.DropDatabase();
}

[Order(3)]
[TestCase(typeof(MySqlCrudCommandFixture))]
[TestCase(typeof(SqlCrudCommandFixture))]
[TestCase(typeof(PostgreSqlCrudCommandFixture))]
public void ShouldRollbackATransaction(Type fixtureType)
{
var fixture = Activator.CreateInstance(fixtureType) as CrudCommandFixtureBase;

fixture.CreateDatabase();
fixture.CreateTables();

var insertCommandBuilder = fixture.Connector.GetCommandBuilderFactory().CreateInsertCommandBuilder(fixture.GetParentDescriptor());
var selectCommandBuilder = fixture.Connector.GetCommandBuilderFactory().CreateSelectCommandBuilder(fixture.GetParentDescriptor());
var entityToInsert = fixture.CreateNewEntity();
var valueProvider = new ClassValueProvider(fixture.Connector, new List<object> { entityToInsert });
valueProvider.MoveNext();
var insertCommand = insertCommandBuilder.GetCommand(valueProvider);
var selectCommand = selectCommandBuilder.GetCommand();

using (var transaction = fixture.Connector.CreateTransaction())
{
if (fixtureType == typeof(CqlCrudCommandFixture))
insertCommand.ExecuteNonQuery().Should().Be(-1);
else
insertCommand.ExecuteNonQuery().Should().Be(1);

transaction.Rollback();
}

using (var reader = selectCommand.ExecuteReader())
{
reader.Should().NotBeNull();

var mapper = new DatabaseReaderMapper(fixture.Connector, fixture.GetParentDescriptor());
var results = mapper.Map(reader);

results.Should().NotBeNull().And.HaveCount(0);
}

fixture.DropDatabase();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Namespace Tests.MySql
<TestInitialize()>
Public Sub Initialize()

Connector = New MySqlDatabaseConnector("Server=localhost;Database=test;User=root;Password=Paradigm_Test_1234;Connection Timeout=3600")
Connector = New MySqlDatabaseConnector("Server=127.0.0.1;Database=test;User=root;Password=Paradigm_Test_1234;Connection Timeout=3600")
Connector.Open()

Connector.ExecuteNonQuery("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Namespace Tests.MySql
<TestInitialize()>
Public Sub Initialize()

Connector = New MySqlDatabaseConnector("Server=localhost;Database=test;User=root;Password=Paradigm_Test_1234;Connection Timeout=3600")
Connector = New MySqlDatabaseConnector("Server=127.0.0.1;Database=test;User=root;Password=Paradigm_Test_1234;Connection Timeout=3600")
Connector.Open()

Connector.ExecuteNonQuery("
Expand Down

0 comments on commit 44cf1ee

Please sign in to comment.