Beispiel #1
0
        public void ClientStreaming_MoreRequests_Success()
        {
            var resultTask    = asyncCall.ClientStreamingCallAsync();
            var requestStream = new ClientRequestStream <string, string>(asyncCall);

            var writeTask = requestStream.WriteAsync("request1");

            fakeCall.SendCompletionCallback.OnSendCompletion(true);
            writeTask.Wait();

            var writeTask2 = requestStream.WriteAsync("request2");

            fakeCall.SendCompletionCallback.OnSendCompletion(true);
            writeTask2.Wait();

            var completeTask = requestStream.CompleteAsync();

            fakeCall.SendCompletionCallback.OnSendCompletion(true);
            completeTask.Wait();

            fakeCall.UnaryResponseClientCallback.OnUnaryResponseClient(true,
                                                                       new ClientSideStatus(Status.DefaultSuccess, new Metadata()),
                                                                       CreateResponsePayload(),
                                                                       new Metadata());

            AssertUnaryResponseSuccess(asyncCall, fakeCall, resultTask);
        }
Beispiel #2
0
        public void ClientStreaming_CompleteAfterReceivingStatusSucceeds()
        {
            var resultTask    = asyncCall.ClientStreamingCallAsync();
            var requestStream = new ClientRequestStream <string, string>(asyncCall);

            fakeCall.UnaryResponseClientCallback.OnUnaryResponseClient(true,
                                                                       new ClientSideStatus(Status.DefaultSuccess, new Metadata()),
                                                                       CreateResponsePayload(),
                                                                       new Metadata());

            AssertUnaryResponseSuccess(asyncCall, fakeCall, resultTask);
            Assert.DoesNotThrowAsync(async() => await requestStream.CompleteAsync());
        }
Beispiel #3
0
        public void DuplexStreaming_CompleteAfterReceivingStatusSuceeds()
        {
            asyncCall.StartDuplexStreamingCall();
            var requestStream  = new ClientRequestStream <string, string>(asyncCall);
            var responseStream = new ClientResponseStream <string, string>(asyncCall);

            var readTask = responseStream.MoveNext();

            fakeCall.ReceivedMessageCallback.OnReceivedMessage(true, null);
            fakeCall.ReceivedStatusOnClientCallback.OnReceivedStatusOnClient(true, new ClientSideStatus(Status.DefaultSuccess, new Metadata()));

            AssertStreamingResponseSuccess(asyncCall, fakeCall, readTask);

            Assert.DoesNotThrowAsync(async() => await requestStream.CompleteAsync());
        }
Beispiel #4
0
        public void ClientStreaming_WriteAfterCompleteThrowsInvalidOperationException()
        {
            var resultTask    = asyncCall.ClientStreamingCallAsync();
            var requestStream = new ClientRequestStream <string, string>(asyncCall);

            requestStream.CompleteAsync();

            Assert.Throws(typeof(InvalidOperationException), () => requestStream.WriteAsync("request1"));

            fakeCall.SendCompletionCallback.OnSendCompletion(true);

            fakeCall.UnaryResponseClientCallback.OnUnaryResponseClient(true,
                                                                       new ClientSideStatus(Status.DefaultSuccess, new Metadata()),
                                                                       CreateResponsePayload(),
                                                                       new Metadata());

            AssertUnaryResponseSuccess(asyncCall, fakeCall, resultTask);
        }
Beispiel #5
0
        public void DuplexStreaming_NoRequestNoResponse_Success()
        {
            asyncCall.StartDuplexStreamingCall();
            var requestStream  = new ClientRequestStream <string, string>(asyncCall);
            var responseStream = new ClientResponseStream <string, string>(asyncCall);

            var writeTask1 = requestStream.CompleteAsync();

            fakeCall.SendCompletionHandler(true);
            Assert.DoesNotThrowAsync(async() => await writeTask1);

            var readTask = responseStream.MoveNext();

            fakeCall.ReceivedMessageHandler(true, null);
            fakeCall.ReceivedStatusOnClientHandler(true, new ClientSideStatus(Status.DefaultSuccess, new Metadata()));

            AssertStreamingResponseSuccess(asyncCall, fakeCall, readTask);
        }
Beispiel #6
0
        public void DuplexStreaming_NoRequestNoResponse_Success2()
        {
            asyncCall.StartDuplexStreamingCall();
            var requestStream  = new ClientRequestStream <string, string>(asyncCall);
            var responseStream = new ClientResponseStream <string, string>(asyncCall);

            var writeTask1 = requestStream.CompleteAsync();

            fakeCall.SendCompletionCallback.OnSendCompletion(true);
            Assert.DoesNotThrowAsync(async() => await writeTask1);

            var readTask = responseStream.MoveNext();

            fakeCall.ReceivedMessageCallback.OnReceivedMessage(true, CreateNullResponse());
            fakeCall.ReceivedStatusOnClientCallback.OnReceivedStatusOnClient(true, new ClientSideStatus(Status.DefaultSuccess, new Metadata()));

            fakeCall.ReceivedResponseHeadersCallback.OnReceivedResponseHeaders(true, new Metadata());
            Assert.AreEqual(0, asyncCall.ResponseHeadersAsync.Result.Count);

            AssertStreamingResponseSuccess(asyncCall, fakeCall, readTask);
        }
        public void DuplexStreaming_NoRequestNoResponse_Success()
        {
            asyncCall.StartDuplexStreamingCall();
            var requestStream = new ClientRequestStream<string, string>(asyncCall);
            var responseStream = new ClientResponseStream<string, string>(asyncCall);

            var writeTask1 = requestStream.CompleteAsync();
            fakeCall.SendCompletionHandler(true);
            Assert.DoesNotThrowAsync(async () => await writeTask1);

            var readTask = responseStream.MoveNext();
            fakeCall.ReceivedMessageHandler(true, null);
            fakeCall.ReceivedStatusOnClientHandler(true, new ClientSideStatus(Status.DefaultSuccess, new Metadata()));

            AssertStreamingResponseSuccess(asyncCall, fakeCall, readTask);
        }
        public void ClientStreaming_WriteAfterCompleteThrowsInvalidOperationException()
        {
            var resultTask = asyncCall.ClientStreamingCallAsync();
            var requestStream = new ClientRequestStream<string, string>(asyncCall);

            requestStream.CompleteAsync();

            Assert.Throws(typeof(InvalidOperationException), () => requestStream.WriteAsync("request1"));

            fakeCall.SendCompletionHandler(true);

            fakeCall.UnaryResponseClientHandler(true,
                new ClientSideStatus(Status.DefaultSuccess, new Metadata()),
                CreateResponsePayload(),
                new Metadata());

            AssertUnaryResponseSuccess(asyncCall, fakeCall, resultTask);
        }
        public void ClientStreaming_MoreRequests_Success()
        {
            var resultTask = asyncCall.ClientStreamingCallAsync();
            var requestStream = new ClientRequestStream<string, string>(asyncCall);

            var writeTask = requestStream.WriteAsync("request1");
            fakeCall.SendCompletionHandler(true);
            writeTask.Wait();

            var writeTask2 = requestStream.WriteAsync("request2");
            fakeCall.SendCompletionHandler(true);
            writeTask2.Wait();

            var completeTask = requestStream.CompleteAsync();
            fakeCall.SendCompletionHandler(true);
            completeTask.Wait();

            fakeCall.UnaryResponseClientHandler(true,
                new ClientSideStatus(Status.DefaultSuccess, new Metadata()),
                CreateResponsePayload(),
                new Metadata());

            AssertUnaryResponseSuccess(asyncCall, fakeCall, resultTask);
        }
        public void ClientStreaming_CompleteAfterReceivingStatusSucceeds()
        {
            var resultTask = asyncCall.ClientStreamingCallAsync();
            var requestStream = new ClientRequestStream<string, string>(asyncCall);

            fakeCall.UnaryResponseClientHandler(true,
                new ClientSideStatus(Status.DefaultSuccess, new Metadata()),
                CreateResponsePayload(),
                new Metadata());

            AssertUnaryResponseSuccess(asyncCall, fakeCall, resultTask);
            Assert.DoesNotThrowAsync(async () => await requestStream.CompleteAsync());
        }