{"action":"created","comment":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/comments/62417150","id":62417150,"diff_hunk":"@@ -12,33 +12,212 @@\n // See the License for the specific language governing permissions and\n // limitations under the License.\n \n+using Google.Apis.Download;\n+using Google.Apis.Storage.v1;\n+using Google.Apis.Storage.v1.Data;\n+using Google.Apis.Upload;\n+using System;\n+using System.IO;\n using System.Linq;\n+using System.Text;\n using Xunit;\n \n namespace Google.Storage.V1.Snippets\n {\n     [Collection(nameof(StorageSnippetFixture))]\n     public class StorageClientSnippets\n     {\n-        private readonly StorageSnippetFixture _fixture;\n+        private readonly StorageSnippetFixture fixture;\n \n         public StorageClientSnippets(StorageSnippetFixture fixture)\n         {\n-            this._fixture = fixture;\n+            this.fixture = fixture;\n         }\n \n         [Fact]\n-        public void ListObjects()\n+        void ListBuckets()\n         {\n-            var bucketId = _fixture.BucketId;\n+            var projectId = fixture.ProjectId;\n+\n+            // <ListBuckets>\n+            var client = StorageClient.Create();\n+\n+            // List all buckets associated with a project\n+            var buckets = client.ListBuckets(projectId);\n+            // </ListBuckets>\n+        }\n+\n+        [Fact]\n+        void CreateBucket()\n+        {\n+            var projectId = fixture.ProjectId;\n+\n+            // <Buckets.Insert>\n+            var client = StorageClient.Create();\n+\n+            // GCS bucket names must be globally unique\n+            var bucketName = Guid.NewGuid().ToString();\n+\n+            // Bucket defined in Google.Apis.Storage.v1.Data namespace\n+            var bucket = client.Service.Buckets.Insert(new Bucket { Name = bucketName }, projectId).Execute();\n+            // </Buckets.Insert>\n+\n+            Assert.Equal(bucketName, bucket.Name);\n+            Assert.True(!string.IsNullOrWhiteSpace(bucket.Id));\n+            client.Service.Buckets.Delete(bucketName).Execute();\n+        }\n+\n+        [Fact]\n+        void ListObjects()\n+        {\n+            var bucketName = fixture.BucketName;\n \n             // <ListObjects>\n             var client = StorageClient.Create();\n-            // List only objects with a name starting with \"Hello\"\n-            var objects = client.ListObjects(bucketId, \"Hello\");\n+\n+            // List only objects with a name starting with \"greet\"\n+            var objects = client.ListObjects(bucketName, \"greet\");\n             // </ListObjects>\n+\n             var names = objects.Select(obj => obj.Name).ToList();\n-            Assert.Contains(_fixture.HelloWorldName, names);\n+            Assert.Contains(fixture.HelloWorldName, names);\n         }\n+\n+        [Fact]\n+        void DownloadFile()\n+        {\n+            var bucketName = fixture.BucketName;\n+            var projectId = fixture.ProjectId;\n+\n+            // <DownloadObject>\n+            var client = StorageClient.Create();\n+            var source = \"greetings/hello.txt\";\n+            var destination = @\".\\hello.txt\";\n+\n+            using (var stream = File.Create(destination))\n+            {\n+                // IDownloadProgress defined in Google.Apis.Download namespace\n+                var progress = new Progress<IDownloadProgress>(\n+                    p => Console.WriteLine($\"bytes: {p.BytesDownloaded}, status: {p.Status}\")\n+                );\n+\n+                // Download source object from bucket to local file system\n+                client.DownloadObject(bucketName, source, stream, null, progress);\n+            }\n+            // </DownloadObject>\n+\n+            // want to show the source path in the snippet to give an idea\n+            // of nested paths, but want to make sure that the pre-uploaded file\n+            // is at the same path as the source since it is duplicated data\n+            Assert.Equal(fixture.HelloWorldName, source);\n+\n+            Assert.Equal(fixture.HelloWorldContent, File.ReadAllText(destination));\n+            File.Delete(destination);\n+        }\n+\n+        [Fact]\n+        void UploadFile()\n+        {\n+            // need to write this at test run instead of fixture creation\n+            // as the DownloadFile test creates and deletes the same file\n+            var local = @\".\\hello.txt\";\n+            File.WriteAllText(local, fixture.HelloWorldContent);\n+            var bucketName = fixture.BucketName;\n+\n+            // <UploadObject>\n+            var client = StorageClient.Create();\n+            var source = @\".\\hello.txt\";\n+            var destination = \"greetings/hello.txt\";\n+            var contentType = \"text/plain\";\n+\n+            using (var stream = File.OpenRead(source))\n+            {\n+                // IUploadProgress defined in Google.Apis.Upload namespace\n+                var progress = new Progress<IUploadProgress>(\n+                  p => Console.WriteLine($\"bytes: {p.BytesSent}, status: {p.Status}\")\n+                );\n+\n+                // ObjectsResource defined in Google.Apis.Storage.v1 namespace\n+                // var acl = ObjectsResource.InsertMediaUpload.PredefinedAclEnum.PublicRead // public\n+                var acl = ObjectsResource.InsertMediaUpload.PredefinedAclEnum.AuthenticatedRead; // private","path":"snippets/Google.Storage.V1.Snippets/StorageClientSnippets.cs","position":138,"original_position":138,"commit_id":"70b8825f7cf959e8c4589a33dcc6630465048fb0","original_commit_id":"70b8825f7cf959e8c4589a33dcc6630465048fb0","user":{"login":"jskeet","id":17011,"avatar_url":"https://avatars.githubusercontent.com/u/17011?v=3","gravatar_id":"","url":"https://api.github.com/users/jskeet","html_url":"https://github.com/jskeet","followers_url":"https://api.github.com/users/jskeet/followers","following_url":"https://api.github.com/users/jskeet/following{/other_user}","gists_url":"https://api.github.com/users/jskeet/gists{/gist_id}","starred_url":"https://api.github.com/users/jskeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jskeet/subscriptions","organizations_url":"https://api.github.com/users/jskeet/orgs","repos_url":"https://api.github.com/users/jskeet/repos","events_url":"https://api.github.com/users/jskeet/events{/privacy}","received_events_url":"https://api.github.com/users/jskeet/received_events","type":"User","site_admin":false},"body":"That would certainly seem like a reasonable output format, but will require more work to implement. (The current extraction is almost entirely from docfx - I just automated attaching the snippets to the prod methods.)\r\n\r\nIf we decide to divorce ourself from the automated extraction of course, that does mean we could do more cunning processing - like \"inlining\" constants to avoid the tension between code duplication and being standalone.","created_at":"2016-05-07T14:37:55Z","updated_at":"2016-05-07T14:37:55Z","html_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet/pull/141#discussion_r62417150","pull_request_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141","_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/comments/62417150"},"html":{"href":"https://github.com/GoogleCloudPlatform/gcloud-dotnet/pull/141#discussion_r62417150"},"pull_request":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141"}}},"pull_request":{"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141","id":69196350,"html_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet/pull/141","diff_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet/pull/141.diff","patch_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet/pull/141.patch","issue_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues/141","number":141,"state":"open","locked":false,"title":"updated storage snippets","user":{"login":"csells","id":2568253,"avatar_url":"https://avatars.githubusercontent.com/u/2568253?v=3","gravatar_id":"","url":"https://api.github.com/users/csells","html_url":"https://github.com/csells","followers_url":"https://api.github.com/users/csells/followers","following_url":"https://api.github.com/users/csells/following{/other_user}","gists_url":"https://api.github.com/users/csells/gists{/gist_id}","starred_url":"https://api.github.com/users/csells/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csells/subscriptions","organizations_url":"https://api.github.com/users/csells/orgs","repos_url":"https://api.github.com/users/csells/repos","events_url":"https://api.github.com/users/csells/events{/privacy}","received_events_url":"https://api.github.com/users/csells/received_events","type":"User","site_admin":false},"body":null,"created_at":"2016-05-06T19:10:52Z","updated_at":"2016-05-07T14:37:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d0060b6abfdc2f99ad90db8a174b460a4e3b1caf","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141/commits","review_comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141/comments","review_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues/141/comments","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/statuses/70b8825f7cf959e8c4589a33dcc6630465048fb0","head":{"label":"csells:master","ref":"master","sha":"70b8825f7cf959e8c4589a33dcc6630465048fb0","user":{"login":"csells","id":2568253,"avatar_url":"https://avatars.githubusercontent.com/u/2568253?v=3","gravatar_id":"","url":"https://api.github.com/users/csells","html_url":"https://github.com/csells","followers_url":"https://api.github.com/users/csells/followers","following_url":"https://api.github.com/users/csells/following{/other_user}","gists_url":"https://api.github.com/users/csells/gists{/gist_id}","starred_url":"https://api.github.com/users/csells/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csells/subscriptions","organizations_url":"https://api.github.com/users/csells/orgs","repos_url":"https://api.github.com/users/csells/repos","events_url":"https://api.github.com/users/csells/events{/privacy}","received_events_url":"https://api.github.com/users/csells/received_events","type":"User","site_admin":false},"repo":{"id":58228609,"name":"gcloud-dotnet","full_name":"csells/gcloud-dotnet","owner":{"login":"csells","id":2568253,"avatar_url":"https://avatars.githubusercontent.com/u/2568253?v=3","gravatar_id":"","url":"https://api.github.com/users/csells","html_url":"https://github.com/csells","followers_url":"https://api.github.com/users/csells/followers","following_url":"https://api.github.com/users/csells/following{/other_user}","gists_url":"https://api.github.com/users/csells/gists{/gist_id}","starred_url":"https://api.github.com/users/csells/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csells/subscriptions","organizations_url":"https://api.github.com/users/csells/orgs","repos_url":"https://api.github.com/users/csells/repos","events_url":"https://api.github.com/users/csells/events{/privacy}","received_events_url":"https://api.github.com/users/csells/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/csells/gcloud-dotnet","description":"Google Cloud Client Library for .NET","fork":true,"url":"https://api.github.com/repos/csells/gcloud-dotnet","forks_url":"https://api.github.com/repos/csells/gcloud-dotnet/forks","keys_url":"https://api.github.com/repos/csells/gcloud-dotnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/csells/gcloud-dotnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/csells/gcloud-dotnet/teams","hooks_url":"https://api.github.com/repos/csells/gcloud-dotnet/hooks","issue_events_url":"https://api.github.com/repos/csells/gcloud-dotnet/issues/events{/number}","events_url":"https://api.github.com/repos/csells/gcloud-dotnet/events","assignees_url":"https://api.github.com/repos/csells/gcloud-dotnet/assignees{/user}","branches_url":"https://api.github.com/repos/csells/gcloud-dotnet/branches{/branch}","tags_url":"https://api.github.com/repos/csells/gcloud-dotnet/tags","blobs_url":"https://api.github.com/repos/csells/gcloud-dotnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/csells/gcloud-dotnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/csells/gcloud-dotnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/csells/gcloud-dotnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/csells/gcloud-dotnet/statuses/{sha}","languages_url":"https://api.github.com/repos/csells/gcloud-dotnet/languages","stargazers_url":"https://api.github.com/repos/csells/gcloud-dotnet/stargazers","contributors_url":"https://api.github.com/repos/csells/gcloud-dotnet/contributors","subscribers_url":"https://api.github.com/repos/csells/gcloud-dotnet/subscribers","subscription_url":"https://api.github.com/repos/csells/gcloud-dotnet/subscription","commits_url":"https://api.github.com/repos/csells/gcloud-dotnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/csells/gcloud-dotnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/csells/gcloud-dotnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/csells/gcloud-dotnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/csells/gcloud-dotnet/contents/{+path}","compare_url":"https://api.github.com/repos/csells/gcloud-dotnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/csells/gcloud-dotnet/merges","archive_url":"https://api.github.com/repos/csells/gcloud-dotnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/csells/gcloud-dotnet/downloads","issues_url":"https://api.github.com/repos/csells/gcloud-dotnet/issues{/number}","pulls_url":"https://api.github.com/repos/csells/gcloud-dotnet/pulls{/number}","milestones_url":"https://api.github.com/repos/csells/gcloud-dotnet/milestones{/number}","notifications_url":"https://api.github.com/repos/csells/gcloud-dotnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/csells/gcloud-dotnet/labels{/name}","releases_url":"https://api.github.com/repos/csells/gcloud-dotnet/releases{/id}","deployments_url":"https://api.github.com/repos/csells/gcloud-dotnet/deployments","created_at":"2016-05-06T18:56:48Z","updated_at":"2016-05-06T18:56:49Z","pushed_at":"2016-05-06T19:10:35Z","git_url":"git://github.com/csells/gcloud-dotnet.git","ssh_url":"git@github.com:csells/gcloud-dotnet.git","clone_url":"https://github.com/csells/gcloud-dotnet.git","svn_url":"https://github.com/csells/gcloud-dotnet","homepage":null,"size":1856,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"GoogleCloudPlatform:master","ref":"master","sha":"ab5d65a817daf8b6959b99ed474e062dde403a83","user":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"repo":{"id":35877412,"name":"gcloud-dotnet","full_name":"GoogleCloudPlatform/gcloud-dotnet","owner":{"login":"GoogleCloudPlatform","id":2810941,"avatar_url":"https://avatars.githubusercontent.com/u/2810941?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCloudPlatform","html_url":"https://github.com/GoogleCloudPlatform","followers_url":"https://api.github.com/users/GoogleCloudPlatform/followers","following_url":"https://api.github.com/users/GoogleCloudPlatform/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCloudPlatform/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCloudPlatform/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCloudPlatform/subscriptions","organizations_url":"https://api.github.com/users/GoogleCloudPlatform/orgs","repos_url":"https://api.github.com/users/GoogleCloudPlatform/repos","events_url":"https://api.github.com/users/GoogleCloudPlatform/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCloudPlatform/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet","description":"Google Cloud Client Library for .NET","fork":false,"url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet","forks_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/forks","keys_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/teams","hooks_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/hooks","issue_events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues/events{/number}","events_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/events","assignees_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/assignees{/user}","branches_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/branches{/branch}","tags_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/tags","blobs_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/statuses/{sha}","languages_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/languages","stargazers_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/stargazers","contributors_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/contributors","subscribers_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/subscribers","subscription_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/subscription","commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/contents/{+path}","compare_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/merges","archive_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/downloads","issues_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues{/number}","pulls_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls{/number}","milestones_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/milestones{/number}","notifications_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/labels{/name}","releases_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/releases{/id}","deployments_url":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/deployments","created_at":"2015-05-19T11:14:02Z","updated_at":"2016-04-12T21:30:36Z","pushed_at":"2016-05-06T19:10:52Z","git_url":"git://github.com/GoogleCloudPlatform/gcloud-dotnet.git","ssh_url":"git@github.com:GoogleCloudPlatform/gcloud-dotnet.git","clone_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet.git","svn_url":"https://github.com/GoogleCloudPlatform/gcloud-dotnet","homepage":null,"size":1902,"stargazers_count":11,"watchers_count":11,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":9,"mirror_url":null,"open_issues_count":16,"forks":9,"open_issues":16,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141"},"html":{"href":"https://github.com/GoogleCloudPlatform/gcloud-dotnet/pull/141"},"issue":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues/141"},"comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/issues/141/comments"},"review_comments":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141/comments"},"review_comment":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/pulls/141/commits"},"statuses":{"href":"https://api.github.com/repos/GoogleCloudPlatform/gcloud-dotnet/statuses/70b8825f7cf959e8c4589a33dcc6630465048fb0"}}}}