public async stt::Task GetIamPolicyResourceNamesAsync()
        {
            moq::Mock <ContainerAnalysis.ContainerAnalysisClient> mockGrpcClient = new moq::Mock <ContainerAnalysis.ContainerAnalysisClient>(moq::MockBehavior.Strict);
            gciv::GetIamPolicyRequest request = new gciv::GetIamPolicyRequest
            {
                ResourceAsResourceName = new gax::UnparsedResourceName("a/wildcard/resource"),
            };
            gciv::Policy expectedResponse = new gciv::Policy
            {
                Version  = 271578922,
                Etag     = proto::ByteString.CopyFromUtf8("etage8ad7218"),
                Bindings =
                {
                    new gciv::Binding(),
                },
            };

            mockGrpcClient.Setup(x => x.GetIamPolicyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <gciv::Policy>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            ContainerAnalysisClient client = new ContainerAnalysisClientImpl(mockGrpcClient.Object, null);
            gciv::Policy            responseCallSettings = await client.GetIamPolicyAsync(request.ResourceAsResourceName, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            gciv::Policy responseCancellationToken = await client.GetIamPolicyAsync(request.ResourceAsResourceName, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemplo n.º 2
0
        public async Task GetIamPolicyAsync2()
        {
            Mock <ContainerAnalysis.ContainerAnalysisClient> mockGrpcClient = new Mock <ContainerAnalysis.ContainerAnalysisClient>(MockBehavior.Strict);
            GetIamPolicyRequest request = new GetIamPolicyRequest
            {
                ResourceAsResourceName = IamResourceNameOneof.From(new NoteName("[PROJECT]", "[NOTE]")),
            };
            Policy expectedResponse = new Policy
            {
                Version = 351608024,
                Etag    = ByteString.CopyFromUtf8("21"),
            };

            mockGrpcClient.Setup(x => x.GetIamPolicyAsync(request, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Policy>(Task.FromResult(expectedResponse), null, null, null, null));
            ContainerAnalysisClient client = new ContainerAnalysisClientImpl(mockGrpcClient.Object, null);
            Policy response = await client.GetIamPolicyAsync(request);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }