@@ -11,7 +11,7 @@ public class ComponentApplicationStateTest
11
11
public void InitializeExistingState_SetupsState ( )
12
12
{
13
13
// Arrange
14
- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
14
+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
15
15
var existingState = new Dictionary < string , byte [ ] >
16
16
{
17
17
[ "MyState" ] = JsonSerializer . SerializeToUtf8Bytes ( new byte [ ] { 1 , 2 , 3 , 4 } )
@@ -29,7 +29,7 @@ public void InitializeExistingState_SetupsState()
29
29
public void InitializeExistingState_ThrowsIfAlreadyInitialized ( )
30
30
{
31
31
// Arrange
32
- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
32
+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
33
33
var existingState = new Dictionary < string , byte [ ] >
34
34
{
35
35
[ "MyState" ] = new byte [ ] { 1 , 2 , 3 , 4 }
@@ -41,11 +41,25 @@ public void InitializeExistingState_ThrowsIfAlreadyInitialized()
41
41
Assert . Throws < InvalidOperationException > ( ( ) => applicationState . InitializeExistingState ( existingState ) ) ;
42
42
}
43
43
44
+ [ Fact ]
45
+ public void RegisterOnPersisting_ThrowsIfCalledDuringOnPersisting ( )
46
+ {
47
+ // Arrange
48
+ var currentState = new Dictionary < string , byte [ ] > ( ) ;
49
+ var applicationState = new PersistentComponentState ( currentState , [ ] )
50
+ {
51
+ PersistingState = true
52
+ } ;
53
+
54
+ // Act & Assert
55
+ Assert . Throws < InvalidOperationException > ( ( ) => applicationState . RegisterOnPersisting ( ( ) => Task . CompletedTask ) ) ;
56
+ }
57
+
44
58
[ Fact ]
45
59
public void TryRetrieveState_ReturnsStateWhenItExists ( )
46
60
{
47
61
// Arrange
48
- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
62
+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
49
63
var existingState = new Dictionary < string , byte [ ] >
50
64
{
51
65
[ "MyState" ] = JsonSerializer . SerializeToUtf8Bytes ( new byte [ ] { 1 , 2 , 3 , 4 } )
@@ -65,7 +79,7 @@ public void PersistState_SavesDataToTheStoreAsync()
65
79
{
66
80
// Arrange
67
81
var currentState = new Dictionary < string , byte [ ] > ( ) ;
68
- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
82
+ var applicationState = new PersistentComponentState ( currentState , [ ] )
69
83
{
70
84
PersistingState = true
71
85
} ;
@@ -84,7 +98,7 @@ public void PersistState_ThrowsForDuplicateKeys()
84
98
{
85
99
// Arrange
86
100
var currentState = new Dictionary < string , byte [ ] > ( ) ;
87
- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
101
+ var applicationState = new PersistentComponentState ( currentState , [ ] )
88
102
{
89
103
PersistingState = true
90
104
} ;
@@ -101,7 +115,7 @@ public void PersistAsJson_SerializesTheDataToJsonAsync()
101
115
{
102
116
// Arrange
103
117
var currentState = new Dictionary < string , byte [ ] > ( ) ;
104
- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
118
+ var applicationState = new PersistentComponentState ( currentState , [ ] )
105
119
{
106
120
PersistingState = true
107
121
} ;
@@ -120,7 +134,7 @@ public void PersistAsJson_NullValueAsync()
120
134
{
121
135
// Arrange
122
136
var currentState = new Dictionary < string , byte [ ] > ( ) ;
123
- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
137
+ var applicationState = new PersistentComponentState ( currentState , [ ] )
124
138
{
125
139
PersistingState = true
126
140
} ;
@@ -140,7 +154,7 @@ public void TryRetrieveFromJson_DeserializesTheDataFromJson()
140
154
var myState = new byte [ ] { 1 , 2 , 3 , 4 } ;
141
155
var serialized = JsonSerializer . SerializeToUtf8Bytes ( myState ) ;
142
156
var existingState = new Dictionary < string , byte [ ] > ( ) { [ "MyState" ] = serialized } ;
143
- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
157
+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
144
158
145
159
applicationState . InitializeExistingState ( existingState ) ;
146
160
@@ -158,7 +172,7 @@ public void TryRetrieveFromJson_NullValue()
158
172
// Arrange
159
173
var serialized = JsonSerializer . SerializeToUtf8Bytes < byte [ ] > ( null ) ;
160
174
var existingState = new Dictionary < string , byte [ ] > ( ) { [ "MyState" ] = serialized } ;
161
- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
175
+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
162
176
163
177
applicationState . InitializeExistingState ( existingState ) ;
164
178
0 commit comments