Skip to content

431: Throw error if database id was not provided #432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Src/Notion.Client/Api/Databases/DatabasesClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
using static Notion.Client.ApiEndpoints;

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

public async Task<Database> RetrieveAsync(string databaseId, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(databaseId))
{
throw new ArgumentNullException(nameof(databaseId));
}

return await _client.GetAsync<Database>(DatabasesApiUrls.Retrieve(databaseId), cancellationToken: cancellationToken);
}

Expand Down
14 changes: 14 additions & 0 deletions Test/Notion.UnitTests/DatabasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,18 @@ var jsonData
formulaPropertyValue.Formula.Date.End.Should().BeNull();
}
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
public async Task RetrieveAsync_throws_argument_null_exception_if_database_id_is_null_or_empty(string databaseId)
{
// Arrange && Act
async Task<Database> Act() => await _client.RetrieveAsync(databaseId);

// Assert
var exception = await Assert.ThrowsAsync<ArgumentNullException>(Act);
Assert.Equal("databaseId", exception.ParamName);
}
}
Loading