public void SearchDomains() { moq::Mock <Domains.DomainsClient> mockGrpcClient = new moq::Mock <Domains.DomainsClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); SearchDomainsRequest request = new SearchDomainsRequest { Query = "queryf0c71c1b", LocationAsLocationName = gagr::LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"), }; SearchDomainsResponse expectedResponse = new SearchDomainsResponse { RegisterParameters = { new RegisterParameters(), }, }; mockGrpcClient.Setup(x => x.SearchDomains(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); DomainsClient client = new DomainsClientImpl(mockGrpcClient.Object, null); SearchDomainsResponse response = client.SearchDomains(request.Location, request.Query); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task SearchDomainsRequestObjectAsync() { moq::Mock <Domains.DomainsClient> mockGrpcClient = new moq::Mock <Domains.DomainsClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); SearchDomainsRequest request = new SearchDomainsRequest { Query = "queryf0c71c1b", LocationAsLocationName = gagr::LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"), }; SearchDomainsResponse expectedResponse = new SearchDomainsResponse { RegisterParameters = { new RegisterParameters(), }, }; mockGrpcClient.Setup(x => x.SearchDomainsAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <SearchDomainsResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); DomainsClient client = new DomainsClientImpl(mockGrpcClient.Object, null); SearchDomainsResponse responseCallSettings = await client.SearchDomainsAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); SearchDomainsResponse responseCancellationToken = await client.SearchDomainsAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }