public async stt::Task PredictRequestObjectAsync() { moq::Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new moq::Mock <PredictionService.PredictionServiceClient>(moq::MockBehavior.Strict); PredictRequest request = new PredictRequest { EndpointAsEndpointName = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"), Instances = { new wkt::Value(), }, Parameters = new wkt::Value(), }; PredictResponse expectedResponse = new PredictResponse { Predictions = { new wkt::Value(), }, DeployedModelId = "deployed_model_idf0bd41af", }; mockGrpcClient.Setup(x => x.PredictAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <PredictResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null); PredictResponse responseCallSettings = await client.PredictAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); PredictResponse responseCancellationToken = await client.PredictAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async stt::Task PredictRequestObjectAsync() { moq::Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new moq::Mock <PredictionService.PredictionServiceClient>(moq::MockBehavior.Strict); PredictRequest request = new PredictRequest { Placement = "placementb440552a", UserEvent = new UserEvent(), PageSize = -226905851, PageToken = "page_tokenf09e5538", Filter = "filtere47ac9b2", ValidateOnly = true, Params = { { "key8a0b6e3c", new wkt::Value() }, }, Labels = { { "key8a0b6e3c", "value60c16320" }, }, }; PredictResponse expectedResponse = new PredictResponse { Results = { new PredictResponse.Types.PredictionResult(), }, AttributionToken = "attribution_token14371a88", MissingIds = { "missing_ids9e3bd4de", }, ValidateOnly = true, }; mockGrpcClient.Setup(x => x.PredictAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <PredictResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null); PredictResponse responseCallSettings = await client.PredictAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); PredictResponse responseCancellationToken = await client.PredictAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task PredictAsync() { Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new Mock <PredictionService.PredictionServiceClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); PredictRequest expectedRequest = new PredictRequest { ModelName = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"), Payload = new ExamplePayload(), Params = { }, }; PredictResponse expectedResponse = new PredictResponse(); mockGrpcClient.Setup(x => x.PredictAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <PredictResponse>(Task.FromResult(expectedResponse), null, null, null, null)); PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null); ModelName name = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"); ExamplePayload payload = new ExamplePayload(); IDictionary <string, string> @params = new Dictionary <string, string>(); PredictResponse response = await client.PredictAsync(name, payload, @params); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task PredictRequestObjectAsync() { moq::Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new moq::Mock <PredictionService.PredictionServiceClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); PredictRequest request = new PredictRequest { ModelName = ModelName.FromProjectLocationModel("[PROJECT]", "[LOCATION]", "[MODEL]"), Payload = new ExamplePayload(), Params = { { "key8a0b6e3c", "value60c16320" }, }, }; PredictResponse expectedResponse = new PredictResponse { Payload = { new AnnotationPayload(), }, Metadata = { { "key8a0b6e3c", "value60c16320" }, }, PreprocessedInput = new ExamplePayload(), }; mockGrpcClient.Setup(x => x.PredictAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <PredictResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null)); PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null); PredictResponse responseCallSettings = await client.PredictAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); PredictResponse responseCancellationToken = await client.PredictAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public async Task PredictAsync2() { Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new Mock <PredictionService.PredictionServiceClient>(MockBehavior.Strict); PredictRequest request = new PredictRequest { ModelName = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"), Payload = new ExamplePayload(), }; PredictResponse expectedResponse = new PredictResponse(); mockGrpcClient.Setup(x => x.PredictAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <PredictResponse>(Task.FromResult(expectedResponse), null, null, null, null)); PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null); PredictResponse response = await client.PredictAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }