Exemplo n.º 1
0
    public async Task RestoreStateAsync_ThrowsOnDoubleInitialization()
    {
        // Arrange
        var state = new Dictionary <string, byte[]>
        {
            ["MyState"] = new byte[] { 0, 1, 2, 3, 4 }
        };
        var store    = new TestStore(state);
        var lifetime = new ComponentStatePersistenceManager(NullLogger <ComponentStatePersistenceManager> .Instance);

        await lifetime.RestoreStateAsync(store);

        // Assert
        await Assert.ThrowsAsync <InvalidOperationException>(() => lifetime.RestoreStateAsync(store));
    }
Exemplo n.º 2
0
    public async Task RestoreStateAsync_InitializesStateWithDataFromTheProvidedStore()
    {
        // Arrange
        var data  = new byte[] { 0, 1, 2, 3, 4 };
        var state = new Dictionary <string, byte[]>
        {
            ["MyState"] = JsonSerializer.SerializeToUtf8Bytes(data)
        };
        var store    = new TestStore(state);
        var lifetime = new ComponentStatePersistenceManager(NullLogger <ComponentStatePersistenceManager> .Instance);

        // Act
        await lifetime.RestoreStateAsync(store);

        // Assert
        Assert.True(lifetime.State.TryTakeFromJson <byte[]>("MyState", out var retrieved));
        Assert.Empty(state);
        Assert.Equal(data, retrieved);
    }