public void GetApiResourceNames() { moq::Mock <ApiGatewayService.ApiGatewayServiceClient> mockGrpcClient = new moq::Mock <ApiGatewayService.ApiGatewayServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetApiRequest request = new GetApiRequest { ApiName = ApiName.FromProjectApi("[PROJECT]", "[API]"), }; Api expectedResponse = new Api { ApiName = ApiName.FromProjectApi("[PROJECT]", "[API]"), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), Labels = { { "key8a0b6e3c", "value60c16320" }, }, DisplayName = "display_name137f65c2", ManagedServiceAsManagedServiceName = ManagedServiceName.FromService("[SERVICE]"), State = Api.Types.State.Unspecified, }; mockGrpcClient.Setup(x => x.GetApi(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); ApiGatewayServiceClient client = new ApiGatewayServiceClientImpl(mockGrpcClient.Object, null); Api response = client.GetApi(request.ApiName); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task GetApiResourceNamesAsync() { moq::Mock <ApiGatewayService.ApiGatewayServiceClient> mockGrpcClient = new moq::Mock <ApiGatewayService.ApiGatewayServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetApiRequest request = new GetApiRequest { ApiName = ApiName.FromProjectApi("[PROJECT]", "[API]"), }; Api expectedResponse = new Api { ApiName = ApiName.FromProjectApi("[PROJECT]", "[API]"), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), Labels = { { "key8a0b6e3c", "value60c16320" }, }, DisplayName = "display_name137f65c2", ManagedServiceAsManagedServiceName = ManagedServiceName.FromService("[SERVICE]"), State = Api.Types.State.Unspecified, }; mockGrpcClient.Setup(x => x.GetApiAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Api>(stt::Task.FromResult(expectedResponse), null, null, null, null)); ApiGatewayServiceClient client = new ApiGatewayServiceClientImpl(mockGrpcClient.Object, null); Api responseCallSettings = await client.GetApiAsync(request.ApiName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Api responseCancellationToken = await client.GetApiAsync(request.ApiName, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }