Ejemplo n.º 1
0
        public void ExecuteClientStreaming_WhenItMapped_ShouldUpdateResponseMarkup()
        {
            // Arrange
            const string ExpectedMessage = "Unusual Markup Message Client Streaming";

            var clientMock = new Mock <TestService.TestServiceClient>();

            clientMock.Setup(m => m.ClientStreaming(It.IsAny <CallOptions>()))
            .Returns(TestCalls.AsyncClientStreamingCall(
                         new AsyncStreamWriterStub(),
                         Task.FromResult(new HelloResponse {
                Message = ExpectedMessage
            }),
                         Task.FromResult(new Metadata()),
                         () => Status.DefaultSuccess,
                         () => new Metadata(),
                         () => { }));

            host.AddService(clientMock.Object);
            var component = host.AddComponent <TestWrapper>();

            // Act
            component.Find("button.execute.clientStreaming").Click();
            host.WaitForNextRender();
            var markup = component.GetMarkup();

            // Assert
            Assert.Contains(ExpectedMessage, markup);
        }
Ejemplo n.º 2
0
        private AsyncClientStreamingCall<TReq, TResp> MockStreamCall<TReq, TResp>(Task<TResp> replyTask) where TResp : new()
        {
            var mockRequestStream = new Mock<IClientStreamWriter<TReq>>();
            mockRequestStream.Setup(m => m.WriteAsync(It.IsAny<TReq>()))
                .Returns(replyTask);
            
            var call = TestCalls.AsyncClientStreamingCall(mockRequestStream.Object, Task.FromResult(new TResp()),
                Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { });

            return call;
        }
Ejemplo n.º 3
0
        public void ClientBaseClientStreamingCallCanBeMocked()
        {
            var mockClient        = new Moq.Mock <Math.MathClient>();
            var mockRequestStream = new Moq.Mock <IClientStreamWriter <Num> >();

            // Use a factory method provided by Grpc.Core.Testing.TestCalls to create an instance of a call.
            var fakeCall = TestCalls.AsyncClientStreamingCall <Num, Num>(mockRequestStream.Object, Task.FromResult(new Num()), Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { });

            mockClient.Setup(m => m.Sum(null, null, CancellationToken.None)).Returns(fakeCall);
            Assert.AreSame(fakeCall, mockClient.Object.Sum());
        }
Ejemplo n.º 4
0
 /// <inheritdoc />
 public override AsyncClientStreamingCall <TRequest, TResponse> Build() => TestCalls.AsyncClientStreamingCall(_requests, _response, ResponseHeaders, StatusFunc, TrailersFunc, DisposeAction);