Skip to content

Commit

Permalink
fix IsNew failing test:
Browse files Browse the repository at this point in the history
- resolves todo re inconsistent exception types
- increases test case coverage for possible parameter combinations

there are numerous other methods that need their exception handling changed similarly, in a new PR
  • Loading branch information
Ste1io committed Sep 30, 2023
1 parent bfcdade commit 3b943b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions PetaPoco.Tests.Unit/DatabaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ public void IsNew_GivenInvalidArguments_ShouldThrow()
{
Should.Throw<ArgumentNullException>(() => DB.IsNew(null));
Should.Throw<ArgumentNullException>(() => DB.IsNew(null, null));
Should.Throw<ArgumentNullException>(() => DB.IsNew(null, default));
Should.Throw<ArgumentNullException>(() => DB.IsNew(null, null));
Should.Throw<ArgumentNullException>(() => DB.IsNew("PrimaryKey", null));

Should.Throw<ArgumentException>(() => DB.IsNew(string.Empty, null));
Should.Throw<ArgumentException>(() => DB.IsNew(string.Empty, default));
Should.Throw<ArgumentException>(() => DB.IsNew("MissingId", new { }));

Should.Throw<InvalidOperationException>(() => DB.IsNew(new TransactionLog()));
Expand Down
7 changes: 4 additions & 3 deletions PetaPoco/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2733,11 +2733,12 @@ public bool IsNew(object poco)
}

/// <inheritdoc/>
/// <exception cref="ArgumentException"><paramref name="primaryKeyName"/> is null or empty.</exception>
/// <exception cref="ArgumentNullException"><paramref name="poco"/> is null.</exception>
/// <exception cref="ArgumentException"><paramref name="primaryKeyName"/> is empty.</exception>
/// <exception cref="ArgumentNullException"><paramref name="poco"/> or <paramref name="primaryKeyName"/> is null.</exception>
public bool IsNew(string primaryKeyName, object poco)
{
// TODO: Inconsistent use of `ArgumentNullException` vs `ArgumentException` for null/empty string params.
if (primaryKeyName == null)
throw new ArgumentNullException(nameof(primaryKeyName));
if (string.IsNullOrEmpty(primaryKeyName))
throw new ArgumentException(nameof(primaryKeyName));
if (poco == null)
Expand Down

0 comments on commit 3b943b5

Please sign in to comment.