Ejemplo n.º 1
0
        public void GetAccessPolicy()
        {
            moq::Mock <AccessContextManager.AccessContextManagerClient> mockGrpcClient = new moq::Mock <AccessContextManager.AccessContextManagerClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAccessPolicyRequest request = new GetAccessPolicyRequest
            {
                AccessPolicyName = AccessPolicyName.FromAccessPolicy("[ACCESS_POLICY]"),
            };
            AccessPolicy expectedResponse = new AccessPolicy
            {
                AccessPolicyName = AccessPolicyName.FromAccessPolicy("[ACCESS_POLICY]"),
                Parent           = "parent7858e4d0",
                Title            = "title17dbd3d5",
                CreateTime       = new wkt::Timestamp(),
                UpdateTime       = new wkt::Timestamp(),
                Etag             = "etage8ad7218",
            };

            mockGrpcClient.Setup(x => x.GetAccessPolicy(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            AccessContextManagerClient client = new AccessContextManagerClientImpl(mockGrpcClient.Object, null);
            AccessPolicy response             = client.GetAccessPolicy(request.Name);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Ejemplo n.º 2
0
        public async stt::Task GetAccessPolicyRequestObjectAsync()
        {
            moq::Mock <AccessContextManager.AccessContextManagerClient> mockGrpcClient = new moq::Mock <AccessContextManager.AccessContextManagerClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetAccessPolicyRequest request = new GetAccessPolicyRequest
            {
                AccessPolicyName = AccessPolicyName.FromAccessPolicy("[ACCESS_POLICY]"),
            };
            AccessPolicy expectedResponse = new AccessPolicy
            {
                AccessPolicyName = AccessPolicyName.FromAccessPolicy("[ACCESS_POLICY]"),
                Parent           = "parent7858e4d0",
                Title            = "title17dbd3d5",
                CreateTime       = new wkt::Timestamp(),
                UpdateTime       = new wkt::Timestamp(),
                Etag             = "etage8ad7218",
            };

            mockGrpcClient.Setup(x => x.GetAccessPolicyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <AccessPolicy>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            AccessContextManagerClient client = new AccessContextManagerClientImpl(mockGrpcClient.Object, null);
            AccessPolicy responseCallSettings = await client.GetAccessPolicyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            AccessPolicy responseCancellationToken = await client.GetAccessPolicyAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }