public async stt::Task MutateFeedsAsync() { moq::Mock <FeedService.FeedServiceClient> mockGrpcClient = new moq::Mock <FeedService.FeedServiceClient>(moq::MockBehavior.Strict); MutateFeedsRequest request = new MutateFeedsRequest { CustomerId = "customer_id3b3724cb", Operations = { new FeedOperation(), }, }; MutateFeedsResponse expectedResponse = new MutateFeedsResponse { Results = { new MutateFeedResult(), }, PartialFailureError = new gr::Status(), }; mockGrpcClient.Setup(x => x.MutateFeedsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <MutateFeedsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); FeedServiceClient client = new FeedServiceClientImpl(mockGrpcClient.Object, null); MutateFeedsResponse responseCallSettings = await client.MutateFeedsAsync(request.CustomerId, request.Operations, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); MutateFeedsResponse responseCancellationToken = await client.MutateFeedsAsync(request.CustomerId, request.Operations, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task MutateFeedsAsync2() { Mock <FeedService.FeedServiceClient> mockGrpcClient = new Mock <FeedService.FeedServiceClient>(MockBehavior.Strict); MutateFeedsRequest request = new MutateFeedsRequest { CustomerId = "customerId-1772061412", Operations = { }, }; MutateFeedsResponse expectedResponse = new MutateFeedsResponse(); mockGrpcClient.Setup(x => x.MutateFeedsAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <MutateFeedsResponse>(Task.FromResult(expectedResponse), null, null, null, null)); FeedServiceClient client = new FeedServiceClientImpl(mockGrpcClient.Object, null); MutateFeedsResponse response = await client.MutateFeedsAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async Task MutateFeedsAsync() { Mock <FeedService.FeedServiceClient> mockGrpcClient = new Mock <FeedService.FeedServiceClient>(MockBehavior.Strict); MutateFeedsRequest expectedRequest = new MutateFeedsRequest { CustomerId = "customerId-1772061412", Operations = { }, PartialFailure = true, ValidateOnly = false, }; MutateFeedsResponse expectedResponse = new MutateFeedsResponse(); mockGrpcClient.Setup(x => x.MutateFeedsAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <MutateFeedsResponse>(Task.FromResult(expectedResponse), null, null, null, null)); FeedServiceClient client = new FeedServiceClientImpl(mockGrpcClient.Object, null); string customerId = "customerId-1772061412"; IEnumerable <FeedOperation> operations = new List <FeedOperation>(); bool partialFailure = true; bool validateOnly = false; MutateFeedsResponse response = await client.MutateFeedsAsync(customerId, operations, partialFailure, validateOnly); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }