public async stt::Task GetLocationViewAsync() { moq::Mock <LocationViewService.LocationViewServiceClient> mockGrpcClient = new moq::Mock <LocationViewService.LocationViewServiceClient>(moq::MockBehavior.Strict); GetLocationViewRequest request = new GetLocationViewRequest { ResourceNameAsLocationViewName = gagvr::LocationViewName.FromCustomerLocationView("[CUSTOMER]", "[LOCATION_VIEW]"), }; gagvr::LocationView expectedResponse = new gagvr::LocationView { ResourceNameAsLocationViewName = gagvr::LocationViewName.FromCustomerLocationView("[CUSTOMER]", "[LOCATION_VIEW]"), }; mockGrpcClient.Setup(x => x.GetLocationViewAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gagvr::LocationView>(stt::Task.FromResult(expectedResponse), null, null, null, null)); LocationViewServiceClient client = new LocationViewServiceClientImpl(mockGrpcClient.Object, null); gagvr::LocationView responseCallSettings = await client.GetLocationViewAsync(request.ResourceName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); Assert.AreEqual(expectedResponse, responseCallSettings); gagvr::LocationView responseCancellationToken = await client.GetLocationViewAsync(request.ResourceName, st::CancellationToken.None); Assert.AreEqual(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task GetLocationViewAsync2() { Mock <LocationViewService.LocationViewServiceClient> mockGrpcClient = new Mock <LocationViewService.LocationViewServiceClient>(MockBehavior.Strict); GetLocationViewRequest request = new GetLocationViewRequest { ResourceName = new LocationViewName("[CUSTOMER]", "[LOCATION_VIEW]").ToString(), }; LocationView expectedResponse = new LocationView { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetLocationViewAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LocationView>(Task.FromResult(expectedResponse), null, null, null, null)); LocationViewServiceClient client = new LocationViewServiceClientImpl(mockGrpcClient.Object, null); LocationView response = await client.GetLocationViewAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }