Skip to content

Commit d31b0d2

Browse files
431: Throw error if database id was not provided
1 parent 88664a3 commit d31b0d2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Src/Notion.Client/Api/Databases/DatabasesClient.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading;
1+
using System;
2+
using System.Threading;
23
using System.Threading.Tasks;
34
using static Notion.Client.ApiEndpoints;
45

@@ -15,6 +16,11 @@ public DatabasesClient(IRestClient client)
1516

1617
public async Task<Database> RetrieveAsync(string databaseId, CancellationToken cancellationToken = default)
1718
{
19+
if (string.IsNullOrWhiteSpace(databaseId))
20+
{
21+
throw new ArgumentNullException(nameof(databaseId));
22+
}
23+
1824
return await _client.GetAsync<Database>(DatabasesApiUrls.Retrieve(databaseId), cancellationToken: cancellationToken);
1925
}
2026

Test/Notion.UnitTests/DatabasesClientTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,4 +504,15 @@ var jsonData
504504
formulaPropertyValue.Formula.Date.End.Should().BeNull();
505505
}
506506
}
507+
508+
[Fact]
509+
public async Task RetrieveAsync_throws_argument_null_exception_if_database_id_is_null_or_empty()
510+
{
511+
// Arrange && Act
512+
async Task<Database> Act() => await _client.RetrieveAsync(null);
513+
514+
// Assert
515+
var exception = await Assert.ThrowsAsync<ArgumentNullException>(Act);
516+
Assert.Equal("databaseId", exception.ParamName);
517+
}
507518
}

0 commit comments

Comments
 (0)