public async Task GetModelAsync2() { Mock <AutoMl.AutoMlClient> mockGrpcClient = new Mock <AutoMl.AutoMlClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); GetModelRequest request = new GetModelRequest { ModelName = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"), }; Model expectedResponse = new Model { Name = "name2-1052831874", DisplayName = "displayName1615086568", DatasetId = "datasetId-2115646910", Etag = "etag3123477", }; mockGrpcClient.Setup(x => x.GetModelAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Model>(Task.FromResult(expectedResponse), null, null, null, null)); AutoMlClient client = new AutoMlClientImpl(mockGrpcClient.Object, null); Model response = await client.GetModelAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task GetModelRequestObjectAsync() { moq::Mock <AutoMl.AutoMlClient> mockGrpcClient = new moq::Mock <AutoMl.AutoMlClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetModelRequest request = new GetModelRequest { Name = "name1c9368b0", }; Model expectedResponse = new Model { ModelName = ModelName.FromProjectLocationModel("[PROJECT_ID]", "[LOCATION_ID]", "[MODEL_ID]"), DisplayName = "display_name137f65c2", DatasetId = "dataset_id08d366d3", CreateTime = new wkt::Timestamp(), DeploymentState = Model.Types.DeploymentState.Deployed, Etag = "etage8ad7218", UpdateTime = new wkt::Timestamp(), ImageClassificationModelMetadata = new ImageClassificationModelMetadata(), TextClassificationModelMetadata = new TextClassificationModelMetadata(), TranslationModelMetadata = new TranslationModelMetadata(), TextExtractionModelMetadata = new TextExtractionModelMetadata(), ImageObjectDetectionModelMetadata = new ImageObjectDetectionModelMetadata(), TextSentimentModelMetadata = new TextSentimentModelMetadata(), Labels = { { "key8a0b6e3c", "value60c16320" }, }, }; mockGrpcClient.Setup(x => x.GetModelAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Model>(stt::Task.FromResult(expectedResponse), null, null, null, null)); AutoMlClient client = new AutoMlClientImpl(mockGrpcClient.Object, null); Model responseCallSettings = await client.GetModelAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Model responseCancellationToken = await client.GetModelAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }