Skip to content

Commit 5523b8b

Browse files
committed
Fix tests
1 parent aea8fca commit 5523b8b

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

src/Components/Server/test/Circuits/HybridCacheCircuitPersistenceProviderTest.cs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Components.Server.Circuits;
5+
using Microsoft.AspNetCore.Http;
56
using Microsoft.Extensions.Caching.Hybrid;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Extensions.Logging.Abstractions;
@@ -13,12 +14,13 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits;
1314
public class HybridCacheCircuitPersistenceProviderTest
1415
{
1516
[Fact]
16-
public async Task PersistCircuitAsync_StoresCircuitState()
17+
public async Task CanPersistAndRestoreState()
1718
{
1819
// Arrange
1920
var hybridCache = CreateHybridCache();
2021
var circuitId = TestCircuitIdFactory.CreateTestFactory().CreateCircuitId();
21-
var persistedState = new PersistedCircuitState() {
22+
var persistedState = new PersistedCircuitState()
23+
{
2224
RootComponents = [1, 2, 3],
2325
ApplicationState = new Dictionary<string, byte[]> {
2426
{ "key1", new byte[] { 4, 5, 6 } },
@@ -37,25 +39,6 @@ public async Task PersistCircuitAsync_StoresCircuitState()
3739
Assert.Equal(persistedState.ApplicationState, result.ApplicationState);
3840
}
3941

40-
[Fact]
41-
public async Task RestoreCircuitAsync_ReturnsPersistedState_WhenCircuitExists()
42-
{
43-
// Arrange
44-
var hybridCache = CreateHybridCache();
45-
var circuitId = TestCircuitIdFactory.CreateTestFactory().CreateCircuitId();
46-
var persistedState = new PersistedCircuitState();
47-
var provider = CreateProvider(hybridCache);
48-
var cacheKey = circuitId.Secret;
49-
50-
await provider.PersistCircuitAsync(circuitId, persistedState);
51-
52-
// Act
53-
var result = await provider.RestoreCircuitAsync(circuitId);
54-
55-
// Assert
56-
Assert.Same(persistedState, result);
57-
}
58-
5942
[Fact]
6043
public async Task RestoreCircuitAsync_ReturnsNull_WhenCircuitDoesNotExist()
6144
{
@@ -78,7 +61,15 @@ public async Task RestoreCircuitAsync_RemovesCircuitFromCache()
7861
// Arrange
7962
var hybridCache = CreateHybridCache();
8063
var circuitId = TestCircuitIdFactory.CreateTestFactory().CreateCircuitId();
81-
var persistedState = new PersistedCircuitState();
64+
var persistedState = new PersistedCircuitState()
65+
{
66+
RootComponents = [1, 2, 3],
67+
ApplicationState = new Dictionary<string, byte[]> {
68+
{ "key1", new byte[] { 4, 5, 6 } },
69+
{ "key2", new byte[] { 7, 8, 9 } }
70+
}
71+
};
72+
8273
var provider = CreateProvider(hybridCache);
8374
var cacheKey = circuitId.Secret;
8475

@@ -89,7 +80,10 @@ public async Task RestoreCircuitAsync_RemovesCircuitFromCache()
8980
var result2 = await provider.RestoreCircuitAsync(circuitId);
9081

9182
// Assert
92-
Assert.Same(persistedState, result1);
83+
Assert.NotNull(result1);
84+
Assert.Equal(persistedState.RootComponents, result1.RootComponents);
85+
Assert.Equal(persistedState.ApplicationState, result1.ApplicationState);
86+
9387
Assert.Null(result2); // Circuit should be removed after first restore
9488
}
9589

0 commit comments

Comments
 (0)