public void TestUploadFileRequesterPays() { var downloadFileRequesterPaysSample = new DownloadFileRequesterPaysSample(); UploadFileRequesterPaysSample uploadFileRequesterPaysSample = new UploadFileRequesterPaysSample(); // Upload file request pays. uploadFileRequesterPaysSample.UploadFileRequesterPays(_bucketFixture.ProjectId, _bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("HelloUploadObjectRequesterPays.txt")); // Download file request pays. downloadFileRequesterPaysSample.DownloadFileRequesterPays(_bucketFixture.ProjectId, _bucketFixture.BucketNameGeneric, "HelloUploadObjectRequesterPays.txt", "HelloUploadObjectRequesterPays2.txt"); Assert.Equal(File.ReadAllText(_bucketFixture.FilePath), File.ReadAllText("HelloUploadObjectRequesterPays2.txt")); File.Delete("HelloUploadObjectRequesterPays2.txt"); }
public void TestUploadEncryptedFile() { DownloadEncryptedFileSample downloadEncryptedFileSample = new DownloadEncryptedFileSample(); UploadEncryptedFileSample uploadEncryptedFileSample = new UploadEncryptedFileSample(); GenerateEncryptionKeySample generateEncryptionKeySample = new GenerateEncryptionKeySample(); var key = generateEncryptionKeySample.GenerateEncryptionKey(); // upload with key uploadEncryptedFileSample.UploadEncryptedFile(key, _bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("HelloEncryptUpload.txt")); //download with key downloadEncryptedFileSample.DownloadEncryptedFile(key, _bucketFixture.BucketNameGeneric, "HelloEncryptUpload.txt", "Hello-downloaded.txt"); Assert.Equal(File.ReadAllText(_bucketFixture.FilePath), File.ReadAllText("Hello-downloaded.txt")); File.Delete("Hello-downloaded.txt"); }
public async Task DownloadByteRangeAsync() { UploadFileSample uploadFileSample = new UploadFileSample(); DownloadByteRangeAsyncSample downloadByteRangeSample = new DownloadByteRangeAsyncSample(); uploadFileSample.UploadFile( _bucketFixture.BucketNameGeneric, "Resources/HelloDownloadCompleteByteRange.txt", _bucketFixture.Collect("HelloDownloadCompleteByteRange.txt")); await downloadByteRangeSample.DownloadByteRangeAsync( _bucketFixture.BucketNameGeneric, "HelloDownloadCompleteByteRange.txt", 0, 20, "HelloDownloadCompleteByteRange.txt_0-20"); var downloadedString = Encoding.UTF8.GetString(File.ReadAllBytes("HelloDownloadCompleteByteRange.txt_0-20")); Assert.Equal("\uFEFFHello Download Com", downloadedString); File.Delete("HelloDownloadCompleteByteRange.txt_0-20"); }
public void MakePublic() { MakePublicSample makePublicSample = new MakePublicSample(); UploadFileSample uploadFileSample = new UploadFileSample(); GetMetadataSample getMetadataSample = new GetMetadataSample(); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("HelloMakePublic.txt")); var metadata = getMetadataSample.GetMetadata(_bucketFixture.BucketNameGeneric, "HelloMakePublic.txt"); Assert.NotNull(metadata.MediaLink); // Before making the file public, fetching the medialink should throw an exception. WebClient webClient = new WebClient(); Assert.Throws <WebException>(() => webClient.DownloadString(metadata.MediaLink)); // Make it public and try fetching again. var medialink = makePublicSample.MakePublic(_bucketFixture.BucketNameGeneric, "HelloMakePublic.txt"); var text = webClient.DownloadString(medialink); Assert.Equal(File.ReadAllText(_bucketFixture.FilePath), text); }
public void UploadFile() { UploadFileSample uploadFileSample = new UploadFileSample(); ListFilesSample listFilesSample = new ListFilesSample(); // upload file uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("UploadTest.txt")); var files = listFilesSample.ListFiles(_bucketFixture.BucketNameGeneric); Assert.Contains(files, c => c.Name == "UploadTest.txt"); }
public void TestSetEventBasedHold() { ReleaseEventBasedHoldSample releaseEventBasedHoldSample = new ReleaseEventBasedHoldSample(); SetEventBasedHoldSample setEventBasedHoldSample = new SetEventBasedHoldSample(); UploadFileSample uploadFileSample = new UploadFileSample(); GetMetadataSample getMetadataSample = new GetMetadataSample(); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("SetEventBasedHold.txt")); // Set event based hold. setEventBasedHoldSample.SetEventBasedHold(_bucketFixture.BucketNameGeneric, "SetEventBasedHold.txt"); var metadata = getMetadataSample.GetMetadata(_bucketFixture.BucketNameGeneric, "SetEventBasedHold.txt"); Assert.True(metadata.EventBasedHold); // Release event based hold. releaseEventBasedHoldSample.ReleaseEventBasedHold(_bucketFixture.BucketNameGeneric, "SetEventBasedHold.txt"); }
public void TestPrintFileAclForUser() { PrintFileAclForUserSample printFileAclForUserSample = new PrintFileAclForUserSample(); UploadFileSample uploadFileSample = new UploadFileSample(); AddFileOwnerSample addFileOwnerSample = new AddFileOwnerSample(); string userEmail = _bucketFixture.ServiceAccountEmail; uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("HelloAddObjectOwnerForUser.txt")); // add file owner addFileOwnerSample.AddFileOwner(_bucketFixture.BucketNameGeneric, "HelloAddObjectOwnerForUser.txt", userEmail); // Make sure we print-acl-for-user shows us the user, but not all the ACLs. var fileAclForUser = printFileAclForUserSample.PrintFileAclForUser(_bucketFixture.BucketNameGeneric, "HelloAddObjectOwnerForUser.txt", userEmail); Assert.All(fileAclForUser, c => Assert.Equal(c.Email, userEmail)); }
public void PrintFileAcl() { PrintFileAclSample printFileAclSample = new PrintFileAclSample(); UploadFileSample uploadFileSample = new UploadFileSample(); AddFileOwnerSample addFileOwnerSample = new AddFileOwnerSample(); string userEmail = _bucketFixture.ServiceAccountEmail; uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("HelloAddObjectOwner.txt")); // print file acl var fileAcl = printFileAclSample.PrintObjectAcl(_bucketFixture.BucketNameGeneric, "HelloAddObjectOwner.txt"); Assert.DoesNotContain(fileAcl, c => c.Email == userEmail); // add file owner addFileOwnerSample.AddFileOwner(_bucketFixture.BucketNameGeneric, "HelloAddObjectOwner.txt", userEmail); // print file acl fileAcl = printFileAclSample.PrintObjectAcl(_bucketFixture.BucketNameGeneric, "HelloAddObjectOwner.txt"); Assert.Contains(fileAcl, c => c.Email == userEmail); }
public void ListFiles() { ListFilesSample listFilesSample = new ListFilesSample(); UploadFileSample uploadFileSample = new UploadFileSample(); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("HelloListObjectsTest.txt")); var files = listFilesSample.ListFiles(_bucketFixture.BucketNameGeneric); Assert.Contains(files, c => c.Name == "HelloListObjectsTest.txt"); }
public void MoveFile() { MoveFileSample moveFileSample = new MoveFileSample(); UploadFileSample uploadFileSample = new UploadFileSample(); GetMetadataSample getMetadataSample = new GetMetadataSample(); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, "HelloMove.txt"); // Make sure the file doesn't exist until we move it there. Assert.Throws <GoogleApiException>(() => getMetadataSample.GetMetadata(_bucketFixture.BucketNameGeneric, "ByeMove.txt")); moveFileSample.MoveFile(_bucketFixture.BucketNameGeneric, "HelloMove.txt", _bucketFixture.BucketNameGeneric, _bucketFixture.Collect("ByeMove.txt")); var exception = Assert.Throws <GoogleApiException>(() => getMetadataSample.GetMetadata(_bucketFixture.BucketNameGeneric, "HelloMove.txt")); Assert.Equal(System.Net.HttpStatusCode.NotFound, exception.HttpStatusCode); }
public void ListFilesWithPrefix() { ListFilesWithPrefixSample listFilesWithPrefixSample = new ListFilesWithPrefixSample(); UploadFileSample uploadFileSample = new UploadFileSample(); // Upload 4 files. uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("a/1.txt")); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("a/2.txt")); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("b/2.txt")); uploadFileSample.UploadFile(_bucketFixture.BucketNameGeneric, _bucketFixture.FilePath, _bucketFixture.Collect("a/b/3.txt")); var files = listFilesWithPrefixSample.ListFilesWithPrefix(_bucketFixture.BucketNameGeneric, "a/", null).ToList(); Assert.Contains(files, c => c.Name == "a/1.txt"); Assert.Contains(files, c => c.Name == "a/2.txt"); Assert.Contains(files, c => c.Name == "a/b/3.txt"); }