public async Task GetStateEntryAsync_CanDeleteState()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

            var task = client.GetStateEntryAsync <Widget>("testStore", "test");

            httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
            entry.Request.RequestUri.ToString().Should().Be(GetStateUrl(3500, "testStore", "test"));

            entry.RespondWithJson(new Widget()
            {
                Size = "small", Color = "yellow",
            });

            var state = await task;

            state.Key.Should().Be("test");
            state.Value.Size.Should().Be("small");
            state.Value.Color.Should().Be("yellow");

            state.Value.Color = "green";
            var task2 = state.DeleteAsync();

            httpClient.Requests.TryDequeue(out entry).Should().BeTrue();
            entry.Request.RequestUri.ToString().Should().Be(DeleteStateUrl(3500, "testStore", "test"));

            entry.Respond(new HttpResponseMessage(HttpStatusCode.OK));
            await task;
        }
        public async Task GetStateEntryAsync_CanReadEmptyState_ReturnsDefault()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

            var task = client.GetStateEntryAsync <Widget>("test");

            httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
            entry.Request.RequestUri.ToString().Should().Be(GetStateUrl(3500, "test"));

            entry.Respond(new HttpResponseMessage(HttpStatusCode.OK));

            var state = await task;

            state.Key.Should().Be("test");
            state.Value.Should().BeNull();
        }
        public async Task GetStateEntryAsync_CanSaveState()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

            var task = client.GetStateEntryAsync <Widget>("test");

            httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
            entry.Request.RequestUri.ToString().Should().Be(GetStateUrl(3500, "test"));

            entry.RespondWithJson(new Widget()
            {
                Size = "small", Color = "yellow",
            });

            var state = await task;

            state.Key.Should().Be("test");
            state.Value.Size.Should().Be("small");
            state.Value.Color.Should().Be("yellow");

            state.Value.Color = "green";
            var task2 = state.SaveAsync();

            httpClient.Requests.TryDequeue(out entry).Should().BeTrue();
            entry.Request.RequestUri.ToString().Should().Be(SaveStateUrl(3500));

            using (var stream = await entry.Request.Content.ReadAsStreamAsync())
            {
                var json = await JsonSerializer.DeserializeAsync <JsonElement>(stream);

                json.ValueKind.Should().Be(JsonValueKind.Array);
                json.GetArrayLength().Should().Be(1);
                json[0].GetProperty("key").GetString().Should().Be("test");

                var value = JsonSerializer.Deserialize <Widget>(json[0].GetProperty("value").GetRawText());
                value.Size.Should().Be("small");
                value.Color.Should().Be("green");
            }

            entry.Respond(new HttpResponseMessage(HttpStatusCode.NoContent));
            await task;
        }
        public async Task GetStateEntryAsync_CanReadState()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

            var task = client.GetStateEntryAsync <Widget>("test");

            httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();
            entry.Request.RequestUri.ToString().Should().Be(GetStateUrl(3500, "test"));

            entry.RespondWithJson(new Widget()
            {
                Size = "small", Color = "yellow",
            });

            var state = await task;

            state.Key.Should().Be("test");
            state.Value.Size.Should().Be("small");
            state.Value.Color.Should().Be("yellow");
        }