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));
    }
Пример #2
0
 async Task PersistAsJson()
 {
     if (RuntimeInformation.ProcessArchitecture == Architecture.Wasm)
     {
         return;
     }
     foreach (var item in _values)
     {
         _applicationState.PersistAsJson(item.Key, item.Value);
     }
 }
    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 PersistAsJson_SerializesTheDataToJsonAsync()
    {
        // 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));
    }