Exemplo n.º 1
0
        public async Task GetStateAsync_ThrowsForNonSuccess()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

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

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

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

            await FluentActions.Awaiting(async() => await task).Should().ThrowAsync <HttpRequestException>();
        }
Exemplo n.º 2
0
        public async Task GetStateAsync_CanReadEmptyState_ReturnsDefault()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

            var task = client.GetStateAsync <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.Should().BeNull();
        }
        public async Task GetStateAsync_WithBaseAddress_GeneratesCorrectUrl()
        {
            var httpClient = new TestHttpClient()
            {
                BaseAddress = new Uri($"http://{DaprDefaultEndpoint}:5000"),
            };
            var client = new StateHttpClient(httpClient, new JsonSerializerOptions());

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

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

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

            await task;
        }
Exemplo n.º 4
0
        public async Task GetStateAsync_CanReadState()
        {
            var httpClient = new TestHttpClient();
            var client     = new StateHttpClient(httpClient, new JsonSerializerOptions());

            var task = client.GetStateAsync <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.Size.Should().Be("small");
            state.Color.Should().Be("yellow");
        }