public async stt::Task ApplyRecommendationAsync() { moq::Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new moq::Mock <RecommendationService.RecommendationServiceClient>(moq::MockBehavior.Strict); ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "customer_id3b3724cb", Operations = { new ApplyRecommendationOperation(), }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse { Results = { new ApplyRecommendationResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.ApplyRecommendationAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ApplyRecommendationResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); ApplyRecommendationResponse responseCallSettings = await client.ApplyRecommendationAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); ApplyRecommendationResponse responseCancellationToken = await client.ApplyRecommendationAsync(request.CustomerId, request.Operations, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task ApplyRecommendationAsync3() { Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict); ApplyRecommendationRequest request = new ApplyRecommendationRequest { CustomerId = "customerId-1772061412", Operations = { }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse(); mockGrpcClient.Setup(x => x.ApplyRecommendationAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <ApplyRecommendationResponse>(Task.FromResult(expectedResponse), null, null, null, null)); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); ApplyRecommendationResponse response = await client.ApplyRecommendationAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task ApplyRecommendationAsync() { Mock <RecommendationService.RecommendationServiceClient> mockGrpcClient = new Mock <RecommendationService.RecommendationServiceClient>(MockBehavior.Strict); ApplyRecommendationRequest expectedRequest = new ApplyRecommendationRequest { CustomerId = "customerId-1772061412", PartialFailure = true, Operations = { }, }; ApplyRecommendationResponse expectedResponse = new ApplyRecommendationResponse(); mockGrpcClient.Setup(x => x.ApplyRecommendationAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <ApplyRecommendationResponse>(Task.FromResult(expectedResponse), null, null, null, null)); RecommendationServiceClient client = new RecommendationServiceClientImpl(mockGrpcClient.Object, null); string customerId = "customerId-1772061412"; bool partialFailure = true; IEnumerable <ApplyRecommendationOperation> operations = new List <ApplyRecommendationOperation>(); ApplyRecommendationResponse response = await client.ApplyRecommendationAsync(customerId, partialFailure, operations); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }