public void GetRuntime() { moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient> mockGrpcClient = new moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetRuntimeRequest request = new GetRuntimeRequest { RuntimeName = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"), }; Runtime expectedResponse = new Runtime { RuntimeName = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"), VirtualMachine = new VirtualMachine(), State = Runtime.Types.State.Active, HealthState = Runtime.Types.HealthState.Healthy, AccessConfig = new RuntimeAccessConfig(), SoftwareConfig = new RuntimeSoftwareConfig(), Metrics = new RuntimeMetrics(), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.GetRuntime(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); ManagedNotebookServiceClient client = new ManagedNotebookServiceClientImpl(mockGrpcClient.Object, null); Runtime response = client.GetRuntime(request.Name); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task GetRuntimeRequestObjectAsync() { moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient> mockGrpcClient = new moq::Mock <ManagedNotebookService.ManagedNotebookServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetRuntimeRequest request = new GetRuntimeRequest { RuntimeName = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"), }; Runtime expectedResponse = new Runtime { RuntimeName = RuntimeName.FromProjectLocationRuntime("[PROJECT]", "[LOCATION]", "[RUNTIME]"), VirtualMachine = new VirtualMachine(), State = Runtime.Types.State.Active, HealthState = Runtime.Types.HealthState.Healthy, AccessConfig = new RuntimeAccessConfig(), SoftwareConfig = new RuntimeSoftwareConfig(), Metrics = new RuntimeMetrics(), CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), }; mockGrpcClient.Setup(x => x.GetRuntimeAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Runtime>(stt::Task.FromResult(expectedResponse), null, null, null, null)); ManagedNotebookServiceClient client = new ManagedNotebookServiceClientImpl(mockGrpcClient.Object, null); Runtime responseCallSettings = await client.GetRuntimeAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Runtime responseCancellationToken = await client.GetRuntimeAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }