Permalink
Browse files

Teach IsNew() about decimal primary key

  • Loading branch information...
asherber authored and pleb committed Oct 30, 2018
1 parent 96ca8c8 commit 226a41d9434c7fc939f90f47e040e2a50bf31359
Showing with 6 additions and 0 deletions.
  1. +4 −0 PetaPoco.Tests.Unit/DatabaseTests.cs
  2. +2 −0 PetaPoco/Database.cs
@@ -165,6 +165,7 @@ public void IsNew_GivenTransientEntity_ShoudlBeTrue()
DB.IsNew(new GenericIdEntity<ulong>()).ShouldBeTrue();
DB.IsNew(new GenericIdEntity<string>()).ShouldBeTrue();
DB.IsNew(new GenericIdEntity<ComplexPrimaryKey>()).ShouldBeTrue();
DB.IsNew(new GenericIdEntity<decimal>()).ShouldBeTrue();
}
[Fact]
@@ -180,6 +181,7 @@ public void IsNew_GivenNonTransientEntity_ShouldBeFalse()
DB.IsNew(new GenericIdEntity<ulong>() { Id = 1 }).ShouldBeFalse();
DB.IsNew(new GenericIdEntity<string>() { Id = "ID-1" }).ShouldBeFalse();
DB.IsNew(new GenericIdEntity<ComplexPrimaryKey> { Id = new ComplexPrimaryKey() }).ShouldBeFalse();
DB.IsNew(new GenericIdEntity<decimal>() { Id = 1.0M }).ShouldBeFalse();
}
[Fact]
@@ -195,6 +197,7 @@ public void IsNew_GivenTransientEntityAndPrimaryKeyName_ShouldBeTrue()
DB.IsNew("Id", new GenericNoMapsIdEntity<ulong>()).ShouldBeTrue();
DB.IsNew("Id", new GenericNoMapsIdEntity<string>()).ShouldBeTrue();
DB.IsNew("Id", new GenericNoMapsIdEntity<ComplexPrimaryKey>()).ShouldBeTrue();
DB.IsNew("Id", new GenericNoMapsIdEntity<decimal>()).ShouldBeTrue();
}
[Fact]
@@ -210,6 +213,7 @@ public void IsNew_GivenNonTransientEntityAndPrimaryKeyName_ShouldBeFalse()
DB.IsNew("id", new GenericNoMapsIdEntity<ulong>() { Id = 1 }).ShouldBeFalse();
DB.IsNew("id", new GenericNoMapsIdEntity<string>() { Id = "ID-1" }).ShouldBeFalse();
DB.IsNew("id", new GenericNoMapsIdEntity<ComplexPrimaryKey> { Id = new ComplexPrimaryKey() }).ShouldBeFalse();
DB.IsNew("id", new GenericNoMapsIdEntity<decimal>() { Id = 1.0M }).ShouldBeFalse();
}
[ExplicitColumns]
@@ -1855,6 +1855,8 @@ protected virtual bool IsNew(string primaryKeyName, PocoData pd, object poco)
return (short) pk == default(short);
if (type == typeof(ushort))
return (ushort) pk == default(ushort);
if (type == typeof(decimal))
return (decimal) pk == default(decimal);
// Create a default instance and compare
return pk == Activator.CreateInstance(pk.GetType());

0 comments on commit 226a41d

Please sign in to comment.