Esempio n. 1
0
        public async Task GetIamPolicyAsync()
        {
            Mock <DatabaseAdmin.DatabaseAdminClient> mockGrpcClient = new Mock <DatabaseAdmin.DatabaseAdminClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            GetIamPolicyRequest expectedRequest = new GetIamPolicyRequest
            {
                Resource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(),
            };
            Policy expectedResponse = new Policy
            {
                Version = 351608024,
                Etag    = ByteString.CopyFromUtf8("21"),
            };

            mockGrpcClient.Setup(x => x.GetIamPolicyAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <Policy>(Task.FromResult(expectedResponse), null, null, null, null));
            DatabaseAdminClient client = new DatabaseAdminClientImpl(mockGrpcClient.Object, null);
            string formattedResource   = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
            Policy response            = await client.GetIamPolicyAsync(formattedResource);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Esempio n. 2
0
        public void SetIamPolicy()
        {
            Mock <DatabaseAdmin.DatabaseAdminClient> mockGrpcClient = new Mock <DatabaseAdmin.DatabaseAdminClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            SetIamPolicyRequest expectedRequest = new SetIamPolicyRequest
            {
                Resource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(),
                Policy   = new Policy(),
            };
            Policy expectedResponse = new Policy
            {
                Version = 351608024,
                Etag    = ByteString.CopyFromUtf8("21"),
            };

            mockGrpcClient.Setup(x => x.SetIamPolicy(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            DatabaseAdminClient client = new DatabaseAdminClientImpl(mockGrpcClient.Object, null);
            string formattedResource   = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
            Policy policy   = new Policy();
            Policy response = client.SetIamPolicy(formattedResource, policy);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
 /// <summary>Snippet for GetIamPolicy</summary>
 public void GetIamPolicy()
 {
     // Snippet: GetIamPolicy(string,CallSettings)
     // Create client
     DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.Create();
     // Initialize request argument(s)
     string formattedResource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
     // Make the request
     Policy response = databaseAdminClient.GetIamPolicy(formattedResource);
     // End snippet
 }
 /// <summary>Snippet for TestIamPermissions</summary>
 public void TestIamPermissions()
 {
     // Snippet: TestIamPermissions(string,IEnumerable<string>,CallSettings)
     // Create client
     DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.Create();
     // Initialize request argument(s)
     string formattedResource         = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
     IEnumerable <string> permissions = new List <string>();
     // Make the request
     TestIamPermissionsResponse response = databaseAdminClient.TestIamPermissions(formattedResource, permissions);
     // End snippet
 }
        /// <summary>Snippet for GetIamPolicyAsync</summary>
        public async Task GetIamPolicyAsync()
        {
            // Snippet: GetIamPolicyAsync(string,CallSettings)
            // Additional: GetIamPolicyAsync(string,CancellationToken)
            // Create client
            DatabaseAdminClient databaseAdminClient = await DatabaseAdminClient.CreateAsync();

            // Initialize request argument(s)
            string formattedResource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
            // Make the request
            Policy response = await databaseAdminClient.GetIamPolicyAsync(formattedResource);

            // End snippet
        }
Esempio n. 6
0
        /// <summary>Snippet for ListSessionsAsync</summary>
        public async Task ListSessionsAsync()
        {
            // Snippet: ListSessionsAsync(string,string,int?,CallSettings)
            // Create client
            SpannerClient spannerClient = await SpannerClient.CreateAsync();

            // Initialize request argument(s)
            string formattedDatabase = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
            // Make the request
            PagedAsyncEnumerable <ListSessionsResponse, Session> response =
                spannerClient.ListSessionsAsync(formattedDatabase);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((Session item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListSessionsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (Session item in page)
                {
                    Console.WriteLine(item);
                }
            });

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int            pageSize   = 10;
            Page <Session> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (Session item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
Esempio n. 7
0
        public async Task TestIamPermissionsAsync()
        {
            Mock <DatabaseAdmin.DatabaseAdminClient> mockGrpcClient = new Mock <DatabaseAdmin.DatabaseAdminClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            TestIamPermissionsRequest expectedRequest = new TestIamPermissionsRequest
            {
                Resource    = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(),
                Permissions = { },
            };
            TestIamPermissionsResponse expectedResponse = new TestIamPermissionsResponse();

            mockGrpcClient.Setup(x => x.TestIamPermissionsAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <TestIamPermissionsResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            DatabaseAdminClient client             = new DatabaseAdminClientImpl(mockGrpcClient.Object, null);
            string formattedResource               = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString();
            IEnumerable <string>       permissions = new List <string>();
            TestIamPermissionsResponse response    = await client.TestIamPermissionsAsync(formattedResource, permissions);

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