public void PersistState_ThrowsForDuplicateKeys() { // Arrange var currentState = new Dictionary <string, byte[]>(); var applicationState = new PersistentComponentState(currentState, new List <Func <Task> >()); applicationState.PersistingState = true; var myState = new byte[] { 1, 2, 3, 4 }; applicationState.PersistAsJson("MyState", myState); // Act & Assert Assert.Throws <ArgumentException>(() => applicationState.PersistAsJson("MyState", myState)); }
public void PersistAsJson_NullValueAsync() { // Arrange var currentState = new Dictionary <string, byte[]>(); var applicationState = new PersistentComponentState(currentState, new List <Func <Task> >()); applicationState.PersistingState = true; // Act applicationState.PersistAsJson <byte[]>("MyState", null); // Assert Assert.True(currentState.TryGetValue("MyState", out var stored)); Assert.Null(JsonSerializer.Deserialize <byte[]>(stored)); }
public void PersistState_SavesDataToTheStoreAsync() { // Arrange var currentState = new Dictionary <string, byte[]>(); var applicationState = new PersistentComponentState(currentState, new List <Func <Task> >()); applicationState.PersistingState = true; var myState = new byte[] { 1, 2, 3, 4 }; // Act applicationState.PersistAsJson("MyState", myState); // Assert Assert.True(currentState.TryGetValue("MyState", out var stored)); Assert.Equal(myState, JsonSerializer.Deserialize <byte[]>(stored)); }