@@ -11,7 +11,7 @@ public class ComponentApplicationStateTest
1111 public void InitializeExistingState_SetupsState ( )
1212 {
1313 // Arrange
14- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
14+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
1515 var existingState = new Dictionary < string , byte [ ] >
1616 {
1717 [ "MyState" ] = JsonSerializer . SerializeToUtf8Bytes ( new byte [ ] { 1 , 2 , 3 , 4 } )
@@ -29,7 +29,7 @@ public void InitializeExistingState_SetupsState()
2929 public void InitializeExistingState_ThrowsIfAlreadyInitialized ( )
3030 {
3131 // Arrange
32- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
32+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
3333 var existingState = new Dictionary < string , byte [ ] >
3434 {
3535 [ "MyState" ] = new byte [ ] { 1 , 2 , 3 , 4 }
@@ -41,11 +41,25 @@ public void InitializeExistingState_ThrowsIfAlreadyInitialized()
4141 Assert . Throws < InvalidOperationException > ( ( ) => applicationState . InitializeExistingState ( existingState ) ) ;
4242 }
4343
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+
4458 [ Fact ]
4559 public void TryRetrieveState_ReturnsStateWhenItExists ( )
4660 {
4761 // Arrange
48- var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , new List < PersistComponentStateRegistration > ( ) ) ;
62+ var applicationState = new PersistentComponentState ( new Dictionary < string , byte [ ] > ( ) , [ ] ) ;
4963 var existingState = new Dictionary < string , byte [ ] >
5064 {
5165 [ "MyState" ] = JsonSerializer . SerializeToUtf8Bytes ( new byte [ ] { 1 , 2 , 3 , 4 } )
@@ -65,7 +79,7 @@ public void PersistState_SavesDataToTheStoreAsync()
6579 {
6680 // Arrange
6781 var currentState = new Dictionary < string , byte [ ] > ( ) ;
68- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
82+ var applicationState = new PersistentComponentState ( currentState , [ ] )
6983 {
7084 PersistingState = true
7185 } ;
@@ -84,7 +98,7 @@ public void PersistState_ThrowsForDuplicateKeys()
8498 {
8599 // Arrange
86100 var currentState = new Dictionary < string , byte [ ] > ( ) ;
87- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
101+ var applicationState = new PersistentComponentState ( currentState , [ ] )
88102 {
89103 PersistingState = true
90104 } ;
@@ -101,7 +115,7 @@ public void PersistAsJson_SerializesTheDataToJsonAsync()
101115 {
102116 // Arrange
103117 var currentState = new Dictionary < string , byte [ ] > ( ) ;
104- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
118+ var applicationState = new PersistentComponentState ( currentState , [ ] )
105119 {
106120 PersistingState = true
107121 } ;
@@ -120,7 +134,7 @@ public void PersistAsJson_NullValueAsync()
120134 {
121135 // Arrange
122136 var currentState = new Dictionary < string , byte [ ] > ( ) ;
123- var applicationState = new PersistentComponentState ( currentState , new List < PersistComponentStateRegistration > ( ) )
137+ var applicationState = new PersistentComponentState ( currentState , [ ] )
124138 {
125139 PersistingState = true
126140 } ;
@@ -140,7 +154,7 @@ public void TryRetrieveFromJson_DeserializesTheDataFromJson()
140154 var myState = new byte [ ] { 1 , 2 , 3 , 4 } ;
141155 var serialized = JsonSerializer . SerializeToUtf8Bytes ( myState ) ;
142156 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 [ ] > ( ) , [ ] ) ;
144158
145159 applicationState . InitializeExistingState ( existingState ) ;
146160
@@ -158,7 +172,7 @@ public void TryRetrieveFromJson_NullValue()
158172 // Arrange
159173 var serialized = JsonSerializer . SerializeToUtf8Bytes < byte [ ] > ( null ) ;
160174 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 [ ] > ( ) , [ ] ) ;
162176
163177 applicationState . InitializeExistingState ( existingState ) ;
164178
0 commit comments