Skip to content

Commit

Permalink
Fixed error with Guid Keys on CRUD operations #292
Browse files Browse the repository at this point in the history
  • Loading branch information
valfrid-ly committed Feb 22, 2022
1 parent dd1b4e4 commit 03029f9
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 23 deletions.
13 changes: 11 additions & 2 deletions DapperExtensions.Test/IntegrationTests/Async/DB2/CrudFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ public void AddsMultipleEntitiesToDatabase()
}

[Test]
[Ignore("DB2 Does not support GUID")]
public void AddsEntityToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
}

[Test]
[Ignore("DB2 Does not support GUID")]
public void AddsMultipleEntitiesToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -233,7 +235,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : DB2BaseAsyncFixture
public class UpdateMethod : DB2BaseAsyncFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -277,10 +279,17 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("barz", m3.Value);
Dispose();
}

[Test]
[Ignore("DB2 Does not support GUID")]
public void UsingGuidKey_UpdatesEntity()
{
throw new NotImplementedException();
}
}

[TestFixture]
public class GetListMethod : DB2BaseAsyncFixture
public class GetListMethod : DB2BaseAsyncFixture, IGetListMethod
{
private void Arrange()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : MySqlBaseAsyncFixture
public class UpdateMethod : MySqlBaseAsyncFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -307,6 +307,25 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("barz", m3.Value);
Dispose();
}

[Test]
public void UsingGuidKey_UpdatesEntity()
{
var a1 = new Animal
{
Name = "Guid Update"
};
Guid id = Db.Insert(a1).Result;

var a2 = Db.Get<Animal>(id).Result;
a2.Name = "Baz";

Db.Update(a2);

var a3 = Db.Get<Animal>(id).Result;
Assert.AreEqual("Baz", a3.Name);
Assert.AreNotEqual(Guid.Empty, a3.Id);
}
}

[TestFixture]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ public void AddsMultipleEntitiesToDatabase()
}

[Test]
[Ignore("GUID support for Oracle not implemented")]
public void AddsEntityToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
}

[Test]
[Ignore("GUID support for Oracle not implemented")]
public void AddsMultipleEntitiesToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -231,7 +233,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : OracleBaseAsyncFixture
public class UpdateMethod : OracleBaseAsyncFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -275,6 +277,13 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("barz", m3.Value);
Dispose();
}

[Test]
[Ignore("GUID support for Oracle not implemented")]
public void UsingGuidKey_UpdatesEntity()
{
throw new NotImplementedException();
}
}

[TestFixture]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : SqlServerBaseAsyncFixture
public class UpdateMethod : SqlServerBaseAsyncFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -281,10 +281,29 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("key", m3.Key2);
Assert.AreEqual("barz", m3.Value);
}

[Test]
public void UsingGuidKey_UpdatesEntity()
{
var a1 = new Animal
{
Name = "Guid Update"
};
Guid id = Db.Insert(a1).Result;

var a2 = Db.Get<Animal>(id).Result;
a2.Name = "Baz";

Db.Update(a2);

var a3 = Db.Get<Animal>(id).Result;
Assert.AreEqual("Baz", a3.Name);
Assert.AreNotEqual(Guid.Empty, a3.Id);
}
}

[TestFixture]
public class GetListMethod : SqlServerBaseAsyncFixture
public class GetListMethod : SqlServerBaseAsyncFixture, IGetListMethod
{
private void Arrange()
{
Expand Down
25 changes: 22 additions & 3 deletions DapperExtensions.Test/IntegrationTests/Async/Sqlite/CrudFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using System.Data.SQLite;
using System.Linq;
using System.Threading.Tasks;
using Animal = DapperExtensions.Test.Data.Common.Animal;
//using Animal = DapperExtensions.Test.Data.Common.Animal;
using Multikey = DapperExtensions.Test.Data.Sqlite.Multikey;
using Person = DapperExtensions.Test.Data.Common.Person;
//using Person = DapperExtensions.Test.Data.Common.Person;

namespace DapperExtensions.Test.IntegrationTests.Async.Sqlite
{
Expand Down Expand Up @@ -242,7 +242,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : SqliteBaseAsyncFixture
public class UpdateMethod : SqliteBaseAsyncFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -284,6 +284,25 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("key", m3.Key2);
Assert.AreEqual("barz", m3.Value);
}

[Test]
public void UsingGuidKey_UpdatesEntity()
{
var a1 = new Animal
{
Name = "Guid Update"
};
Guid id = Db.Insert(a1).Result;

var a2 = Db.Get<Animal>(id).Result;
a2.Name = "Baz";

Db.Update(a2);

var a3 = Db.Get<Animal>(id).Result;
Assert.AreEqual("Baz", a3.Name);
Assert.AreNotEqual(Guid.Empty, a3.Id);
}
}

[TestFixture]
Expand Down
13 changes: 11 additions & 2 deletions DapperExtensions.Test/IntegrationTests/DB2/CrudFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ public void AddsMultipleEntitiesToDatabase()
}

[Test]
[Ignore("DB2 Does not support GUID")]
public void AddsEntityToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
}

[Test]
[Ignore("DB2 Does not support GUID")]
public void AddsMultipleEntitiesToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -148,7 +150,7 @@ public void UsingKey_ReturnsEntityWithRelations()
}

[TestFixture]
public class DeleteMethod : DB2BaseFixture
public class DeleteMethod : DB2BaseFixture, IDeleteMethod
{
[Test]
public void UsingKey_DeletesFromDatabase()
Expand Down Expand Up @@ -225,7 +227,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : DB2BaseFixture
public class UpdateMethod : DB2BaseFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -269,6 +271,13 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("barz", m3.Value);
Dispose();
}

[Test]
[Ignore("DB2 Does not support GUID")]
public void UsingGuidKey_UpdatesEntity()
{
throw new NotImplementedException();
}
}

[TestFixture]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DapperExtensions.Test.IntegrationTests.Interfaces
{
public interface IGetListMethod
{
void UsingNullPredicate_ReturnsAll();
void UsingObject_ReturnsMatching();
void UsingPredicate_ReturnsMatching();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace DapperExtensions.Test.IntegrationTests.Interfaces
{
public interface IUpdateMethod
{
void UsingCompositeKey_UpdatesEntity();
void UsingKey_UpdatesEntity();
void UsingGuidKey_UpdatesEntity();
}
}
23 changes: 21 additions & 2 deletions DapperExtensions.Test/IntegrationTests/MySql/CrudFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void UsingKey_ReturnsEntityWithRelations()
}

[TestFixture]
public class DeleteMethod : MySqlBaseFixture
public class DeleteMethod : MySqlBaseFixture, IDeleteMethod
{
private void PersonArrange()
{
Expand Down Expand Up @@ -240,7 +240,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : MySqlBaseFixture
public class UpdateMethod : MySqlBaseFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -284,6 +284,25 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("barz", m3.Value);
Dispose();
}

[Test]
public void UsingGuidKey_UpdatesEntity()
{
var a1 = new Animal
{
Name = "Guid Update"
};
Guid id = Db.Insert(a1);

var a2 = Db.Get<Animal>(id);
a2.Name = "Baz";

Db.Update(a2);

var a3 = Db.Get<Animal>(id);
Assert.AreEqual("Baz", a3.Name);
Assert.AreNotEqual(Guid.Empty, a3.Id);
}
}

[TestFixture]
Expand Down
14 changes: 11 additions & 3 deletions DapperExtensions.Test/IntegrationTests/Oracle/CrudFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ public void AddsMultipleEntitiesToDatabase()
}

[Test]
[Ignore("GUID support for Oracle not implemented")]
public void AddsEntityToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
}

[Test]
[Ignore("GUID support for Oracle not implemented")]
public void AddsMultipleEntitiesToDatabase_WithPassedInGuid()
{
throw new NotImplementedException();
Expand Down Expand Up @@ -145,7 +147,7 @@ public void UsingKey_ReturnsEntityWithRelations()
}

[TestFixture]
public class DeleteMethod : OracleBaseFixture
public class DeleteMethod : OracleBaseFixture, IDeleteMethod
{
[Test]
public void UsingKey_DeletesFromDatabase()
Expand Down Expand Up @@ -223,7 +225,7 @@ public void UsingObject_DeletesRows()
}

[TestFixture]
public class UpdateMethod : OracleBaseFixture
public class UpdateMethod : OracleBaseFixture, IUpdateMethod
{
[Test]
public void UsingKey_UpdatesEntity()
Expand Down Expand Up @@ -251,7 +253,6 @@ public void UsingKey_UpdatesEntity()
}

[Test]
//[Ignore] // TODO add MultiKey support for oracle
public void UsingCompositeKey_UpdatesEntity()
{
Multikey m1 = new Multikey { Key2 = "key", Value = "bar" };
Expand All @@ -268,6 +269,13 @@ public void UsingCompositeKey_UpdatesEntity()
Assert.AreEqual("barz", m3.Value);
Dispose();
}

[Test]
[Ignore("GUID support for Oracle not implemented")]
public void UsingGuidKey_UpdatesEntity()
{
throw new NotImplementedException();
}
}

[TestFixture]
Expand Down
Loading

0 comments on commit 03029f9

Please sign in to comment.