public void GetTagKey() { moq::Mock <TagKeys.TagKeysClient> mockGrpcClient = new moq::Mock <TagKeys.TagKeysClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetTagKeyRequest request = new GetTagKeyRequest { TagKeyName = TagKeyName.FromTagKey("[TAG_KEY]"), }; TagKey expectedResponse = new TagKey { TagKeyName = TagKeyName.FromTagKey("[TAG_KEY]"), Parent = "parent7858e4d0", ShortName = "short_namec7ba9846", NamespacedName = "namespaced_namea4453147", Description = "description2cf9da67", CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), Etag = "etage8ad7218", }; mockGrpcClient.Setup(x => x.GetTagKey(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); TagKeysClient client = new TagKeysClientImpl(mockGrpcClient.Object, null); TagKey response = client.GetTagKey(request.Name); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public async stt::Task GetTagKeyRequestObjectAsync() { moq::Mock <TagKeys.TagKeysClient> mockGrpcClient = new moq::Mock <TagKeys.TagKeysClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetTagKeyRequest request = new GetTagKeyRequest { TagKeyName = TagKeyName.FromTagKey("[TAG_KEY]"), }; TagKey expectedResponse = new TagKey { TagKeyName = TagKeyName.FromTagKey("[TAG_KEY]"), Parent = "parent7858e4d0", ShortName = "short_namec7ba9846", NamespacedName = "namespaced_namea4453147", Description = "description2cf9da67", CreateTime = new wkt::Timestamp(), UpdateTime = new wkt::Timestamp(), Etag = "etage8ad7218", }; mockGrpcClient.Setup(x => x.GetTagKeyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <TagKey>(stt::Task.FromResult(expectedResponse), null, null, null, null)); TagKeysClient client = new TagKeysClientImpl(mockGrpcClient.Object, null); TagKey responseCallSettings = await client.GetTagKeyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); TagKey responseCancellationToken = await client.GetTagKeyAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }