2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using Microsoft . AspNetCore . Components . Server . Circuits ;
5
+ using Microsoft . AspNetCore . Http ;
5
6
using Microsoft . Extensions . Caching . Hybrid ;
6
7
using Microsoft . Extensions . DependencyInjection ;
7
8
using Microsoft . Extensions . Logging . Abstractions ;
@@ -13,12 +14,13 @@ namespace Microsoft.AspNetCore.Components.Server.Tests.Circuits;
13
14
public class HybridCacheCircuitPersistenceProviderTest
14
15
{
15
16
[ Fact ]
16
- public async Task PersistCircuitAsync_StoresCircuitState ( )
17
+ public async Task CanPersistAndRestoreState ( )
17
18
{
18
19
// Arrange
19
20
var hybridCache = CreateHybridCache ( ) ;
20
21
var circuitId = TestCircuitIdFactory . CreateTestFactory ( ) . CreateCircuitId ( ) ;
21
- var persistedState = new PersistedCircuitState ( ) {
22
+ var persistedState = new PersistedCircuitState ( )
23
+ {
22
24
RootComponents = [ 1 , 2 , 3 ] ,
23
25
ApplicationState = new Dictionary < string , byte [ ] > {
24
26
{ "key1" , new byte [ ] { 4 , 5 , 6 } } ,
@@ -37,25 +39,6 @@ public async Task PersistCircuitAsync_StoresCircuitState()
37
39
Assert . Equal ( persistedState . ApplicationState , result . ApplicationState ) ;
38
40
}
39
41
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
-
59
42
[ Fact ]
60
43
public async Task RestoreCircuitAsync_ReturnsNull_WhenCircuitDoesNotExist ( )
61
44
{
@@ -78,7 +61,15 @@ public async Task RestoreCircuitAsync_RemovesCircuitFromCache()
78
61
// Arrange
79
62
var hybridCache = CreateHybridCache ( ) ;
80
63
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
+
82
73
var provider = CreateProvider ( hybridCache ) ;
83
74
var cacheKey = circuitId . Secret ;
84
75
@@ -89,7 +80,10 @@ public async Task RestoreCircuitAsync_RemovesCircuitFromCache()
89
80
var result2 = await provider . RestoreCircuitAsync ( circuitId ) ;
90
81
91
82
// 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
+
93
87
Assert . Null ( result2 ) ; // Circuit should be removed after first restore
94
88
}
95
89
0 commit comments