public async stt::Task SetIamPolicyAsync() { 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); SetIamPolicyServiceAttachmentRequest request = new SetIamPolicyServiceAttachmentRequest { Region = "regionedb20d96", Resource = "resource164eab96", Project = "projectaa6ff846", RegionSetPolicyRequestResource = new RegionSetPolicyRequest(), }; Policy expectedResponse = new Policy { Etag = "etage8ad7218", Rules = { new Rule(), }, AuditConfigs = { new AuditConfig(), }, Version = 271578922, Bindings = { new Binding(), }, IamOwned = false, }; mockGrpcClient.Setup(x => x.SetIamPolicyAsync(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.SetIamPolicyAsync(request.Project, request.Region, request.Resource, request.RegionSetPolicyRequestResource, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Policy responseCancellationToken = await client.SetIamPolicyAsync(request.Project, request.Region, request.Resource, request.RegionSetPolicyRequestResource, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
public void SetIamPolicy() { 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); SetIamPolicyServiceAttachmentRequest request = new SetIamPolicyServiceAttachmentRequest { Region = "regionedb20d96", Resource = "resource164eab96", Project = "projectaa6ff846", RegionSetPolicyRequestResource = new RegionSetPolicyRequest(), }; Policy expectedResponse = new Policy { Etag = "etage8ad7218", Rules = { new Rule(), }, AuditConfigs = { new AuditConfig(), }, Version = 271578922, Bindings = { new Binding(), }, IamOwned = false, }; mockGrpcClient.Setup(x => x.SetIamPolicy(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse); ServiceAttachmentsClient client = new ServiceAttachmentsClientImpl(mockGrpcClient.Object, null); Policy response = client.SetIamPolicy(request.Project, request.Region, request.Resource, request.RegionSetPolicyRequestResource); xunit::Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }