Пример #1
0
        public async Task GetStateAsync_WrapsJsonException()
        {
            // Configure Client
            var httpClient = new TestHttpClient();
            var daprClient = new DaprClientBuilder()
                             .UseGrpcChannelOptions(new GrpcChannelOptions {
                HttpClient = httpClient
            })
                             .Build();

            // Create Response & Respond
            var task = daprClient.GetStateAsync <Widget>("testStore", "test");

            httpClient.Requests.TryDequeue(out var entry).Should().BeTrue();

            var stateResponse = new Autogenerated.GetStateResponse()
            {
                // Totally NOT valid JSON
                Data = ByteString.CopyFrom(0x5b, 0x7b, 0x5b, 0x7b),
            };

            var streamContent = await GrpcUtils.CreateResponseContent(stateResponse);

            var response = GrpcUtils.CreateResponse(HttpStatusCode.OK, streamContent);

            entry.Completion.SetResult(response);

            var ex = await Assert.ThrowsAsync <DaprException>(async() => await task);

            Assert.IsType <JsonException>(ex.InnerException);
        }
Пример #2
0
        private Autogenerated.GetStateResponse MakeGetStateResponse<T>(T state, string etag = null)
        {
            var data = TypeConverters.ToJsonByteString(state, new JsonSerializerOptions(JsonSerializerDefaults.Web));
            var response = new Autogenerated.GetStateResponse
            {
                Data = data
            };

            if (etag != null)
            {
                response.Etag = etag;
            }

            return response;
        }
Пример #3
0
        private async void SendResponseWithState <T>(T state, TestHttpClient.Entry entry, string etag = null)
        {
            var stateDate     = TypeConverters.ToJsonByteString(state);
            var stateResponse = new Autogenerated.GetStateResponse();

            stateResponse.Data = stateDate;

            if (etag != null)
            {
                stateResponse.Etag = etag;
            }

            var streamContent = await GrpcUtils.CreateResponseContent(stateResponse);

            var response = GrpcUtils.CreateResponse(HttpStatusCode.OK, streamContent);

            entry.Completion.SetResult(response);
        }
Пример #4
0
        public async Task GetStateAndETagAsync_WrapsJsonException()
        {
            await using var client = TestClient.CreateForDaprClient();

            var request = await client.CaptureGrpcRequestAsync(async daprClient =>
            {
                return await daprClient.GetStateAndETagAsync<Widget>("testStore", "test");
            });

            // Create Response & Respond
            var envelope = new Autogenerated.GetStateResponse()
            {
                // Totally NOT valid JSON
                Data = ByteString.CopyFrom(0x5b, 0x7b, 0x5b, 0x7b),
            };
            var ex = await Assert.ThrowsAsync<DaprException>(async () =>
            {
                await request.CompleteWithMessageAsync(envelope);
            });
            Assert.IsType<JsonException>(ex.InnerException);
        }