public async stt::Task GetIamPolicyAsync() { moq::Mock <ServiceAttachments.ServiceAttachmentsClient> mockGrpcClient = new moq::Mock <ServiceAttachments.ServiceAttachmentsClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClientForRegionOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetIamPolicyServiceAttachmentRequest request = new GetIamPolicyServiceAttachmentRequest { Region = "regionedb20d96", Resource = "resource164eab96", Project = "projectaa6ff846", }; Policy expectedResponse = new Policy { Etag = "etage8ad7218", Rules = { new Rule(), }, AuditConfigs = { new AuditConfig(), }, Version = 271578922, Bindings = { new Binding(), }, IamOwned = false, }; mockGrpcClient.Setup(x => x.GetIamPolicyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Policy>(stt::Task.FromResult(expectedResponse), null, null, null, null)); ServiceAttachmentsClient client = new ServiceAttachmentsClientImpl(mockGrpcClient.Object, null); Policy responseCallSettings = await client.GetIamPolicyAsync(request.Project, request.Region, request.Resource, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Policy responseCancellationToken = await client.GetIamPolicyAsync(request.Project, request.Region, request.Resource, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void GetIamPolicy() { moq::Mock <ServiceAttachments.ServiceAttachmentsClient> mockGrpcClient = new moq::Mock <ServiceAttachments.ServiceAttachmentsClient>(moq::MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClientForRegionOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object); GetIamPolicyServiceAttachmentRequest request = new GetIamPolicyServiceAttachmentRequest { Region = "regionedb20d96", Resource = "resource164eab96", Project = "projectaa6ff846", }; Policy expectedResponse = new Policy { Etag = "etage8ad7218", Rules = { new Rule(), }, AuditConfigs = { new AuditConfig(), }, Version = 271578922, Bindings = { new Binding(), }, IamOwned = false, }; mockGrpcClient.Setup(x => x.GetIamPolicy(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); ServiceAttachmentsClient client = new ServiceAttachmentsClientImpl(mockGrpcClient.Object, null); Policy response = client.GetIamPolicy(request.Project, request.Region, request.Resource); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }