public void GetHubRequestObject() { moq::Mock <HubService.HubServiceClient> mockGrpcClient = new moq::Mock <HubService.HubServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetHubRequest request = new GetHubRequest { HubName = HubName.FromProjectHub("[PROJECT]", "[HUB]"), }; Hub expectedResponse = new Hub { HubName = HubName.FromProjectHub("[PROJECT]", "[HUB]"), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), Labels = { { "key8a0b6e3c", "value60c16320" }, }, Description = "description2cf9da67", UniqueId = "unique_idee0c0869", State = State.Active, RoutingVpcs = { new RoutingVPC(), }, }; mockGrpcClient.Setup(x => x.GetHub(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); HubServiceClient client = new HubServiceClientImpl(mockGrpcClient.Object, null); Hub response = client.GetHub(request); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task GetHubRequestObjectAsync() { moq::Mock <HubService.HubServiceClient> mockGrpcClient = new moq::Mock <HubService.HubServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetHubRequest request = new GetHubRequest { HubName = HubName.FromProjectHub("[PROJECT]", "[HUB]"), }; Hub expectedResponse = new Hub { HubName = HubName.FromProjectHub("[PROJECT]", "[HUB]"), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), Labels = { { "key8a0b6e3c", "value60c16320" }, }, Description = "description2cf9da67", SpokesAsSpokeNames = { SpokeName.FromProjectLocationSpoke("[PROJECT]", "[LOCATION]", "[SPOKE]"), }, UniqueId = "unique_idee0c0869", State = State.Active, }; mockGrpcClient.Setup(x => x.GetHubAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Hub>(stt::Task.FromResult(expectedResponse), null, null, null, null)); HubServiceClient client = new HubServiceClientImpl(mockGrpcClient.Object, null); Hub responseCallSettings = await client.GetHubAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Hub responseCancellationToken = await client.GetHubAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }