Skip to content
Open
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
6 changes: 4 additions & 2 deletions src/StateStore/Internal/KeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ internal static class KeyHelper
/// Validates that the key is non-null, non-empty, and non-whitespace.
/// </summary>
/// <param name="key">The key to validate.</param>
/// <exception cref="ArgumentException">Thrown when the key is null, empty, or whitespace.</exception>
/// <exception cref="ArgumentNullException">Thrown when the key is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">Thrown when the key is empty or whitespace.</exception>
public static void ValidateKey(string key)
{
ArgumentNullException.ThrowIfNull(key);
if (string.IsNullOrWhiteSpace(key))
{
ArgumentNullException.ThrowIfNull(key, "State store key must not be null, empty, or whitespace.");
throw new ArgumentException("State store key must not be empty or whitespace.", nameof(key));
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/StateStore.Tests/EdgeCaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public async Task SetAndGet_EmptyArray_SucceedsAsync()
}

[Fact]
public async Task Get_NonExistentKey_ThrowsAsync()
public async Task Get_NonExistentKey_ReturnsDefault_Async()
{
var provider = new InMemoryStorageProvider();
var serializer = new JsonStateSerializer();
var pipeline = new MiddlewarePipeline([], provider);
var store = new StateStoreImplementation(serializer, pipeline);

await Assert.ThrowsAsync<KeyNotFoundException>(async () => await store.GetAsync<int>("does_not_exist", TestContext.Current.CancellationToken));
var result = await store.GetAsync<int>("does_not_exist", TestContext.Current.CancellationToken);

Assert.Equal(0, result);
}
}
2 changes: 1 addition & 1 deletion tests/StateStore.Tests/NullReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task UpsertAsync_NullKey_ThrowsAsync()
var pipeline = new MiddlewarePipeline([], provider);
var store = new StateStoreImplementation(serializer, pipeline);

await Assert.ThrowsAsync<ArgumentNullException>(async () => await store.UpsertAsync<int>("", 1, x => x + 1, TestContext.Current.CancellationToken));
await Assert.ThrowsAsync<ArgumentNullException>(async () => await store.UpsertAsync<int>(null!, 1, x => x + 1, TestContext.Current.CancellationToken));
}

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions tests/StateStore.Tests/StateStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ public async Task SetAsync_WorksWithComplexTypes_Async()
}

[Fact]
public async Task GetAsync_ThrowsArgumentException_ForNullKey_Async()
public async Task GetAsync_ThrowsArgumentNullException_ForNullKey_Async()
{
await Assert.ThrowsAsync<ArgumentException>(() => _store.GetAsync<string>(null!, TestContext.Current.CancellationToken).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => _store.GetAsync<string>(null!, TestContext.Current.CancellationToken).AsTask());
}

[Fact]
Expand All @@ -135,9 +135,9 @@ public async Task GetAsync_ThrowsArgumentException_ForWhitespaceKey_Async()
}

[Fact]
public async Task SetAsync_ThrowsArgumentException_ForNullKey_Async()
public async Task SetAsync_ThrowsArgumentNullException_ForNullKey_Async()
{
await Assert.ThrowsAsync<ArgumentException>(() => _store.SetAsync(null!, "value", TestContext.Current.CancellationToken).AsTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => _store.SetAsync(null!, "value", TestContext.Current.CancellationToken).AsTask());
}

[Fact]
Expand Down