public void DeleteFile() { UploadFileSample uploadFileSample = new UploadFileSample(); DeleteFileSample deleteFileSample = new DeleteFileSample(); ListFilesSample listFilesSample = new ListFilesSample(); uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, "DeleteTest.txt"); deleteFileSample.DeleteFile(_fixture.BucketNameGeneric, "DeleteTest.txt"); var files = listFilesSample.ListFiles(_fixture.BucketNameGeneric).ToList(); Assert.DoesNotContain(files, c => c.Name == "DeleteTest.txt"); }
public void DeleteFileArchivedGeneration() { UploadFileSample uploadFileSample = new UploadFileSample(); ListFilesSample listFilesSample = new ListFilesSample(); BucketEnableVersioningSample bucketEnableVersioningSample = new BucketEnableVersioningSample(); GetMetadataSample getMetadataSample = new GetMetadataSample(); DownloadFileSample downloadFileSample = new DownloadFileSample(); ListFileArchivedGenerationSample listFileArchivedGenerationSample = new ListFileArchivedGenerationSample(); DeleteFileArchivedGenerationSample deleteFileArchivedGenerationSample = new DeleteFileArchivedGenerationSample(); BucketDisableVersioningSample bucketDisableVersioningSample = new BucketDisableVersioningSample(); var objectName = "HelloDeleteFileArchivedGeneration.txt"; // Enable bucket versioning bucketEnableVersioningSample.BucketEnableVersioning(_fixture.BucketNameGeneric); // Uploaded for the first time uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, objectName); // Upload again to archive previous generation. uploadFileSample.UploadFile(_fixture.BucketNameGeneric, "Resources/HelloDownloadCompleteByteRange.txt", objectName); try { var objects = listFileArchivedGenerationSample.ListFileArchivedGeneration(_fixture.BucketNameGeneric); Assert.Equal(2, objects.Count(a => a.Name == objectName)); // Get Generations var testFiles = objects.Where(a => a.Name == objectName).ToList(); long?fileArchivedGeneration = testFiles[0].Generation; long?fileCurrentGeneration = testFiles[1].Generation; // Delete first generation of the file deleteFileArchivedGenerationSample.DeleteFileArchivedGeneration(_fixture.BucketNameGeneric, objectName, fileArchivedGeneration); objects = listFileArchivedGenerationSample.ListFileArchivedGeneration(_fixture.BucketNameGeneric); Assert.Equal(1, objects.Count(a => a.Name == objectName)); // Delete second generation of the file deleteFileArchivedGenerationSample.DeleteFileArchivedGeneration(_fixture.BucketNameGeneric, objectName, fileCurrentGeneration); objects = listFileArchivedGenerationSample.ListFileArchivedGeneration(_fixture.BucketNameGeneric); Assert.Equal(0, objects.Count(a => a.Name == objectName)); } finally { // Disable bucket versioning bucketDisableVersioningSample.BucketDisableVersioning(_fixture.BucketNameGeneric); } }
public void MoveFile() { MoveFileSample moveFileSample = new MoveFileSample(); UploadFileSample uploadFileSample = new UploadFileSample(); GetMetadataSample getMetadataSample = new GetMetadataSample(); uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, "HelloMove.txt"); // Make sure the file doesn't exist until we move it there. Assert.Throws <GoogleApiException>(() => getMetadataSample.GetMetadata(_fixture.BucketNameGeneric, "ByeMove.txt")); moveFileSample.MoveFile(_fixture.BucketNameGeneric, "HelloMove.txt", _fixture.BucketNameGeneric, _fixture.Collect("ByeMove.txt")); var exception = Assert.Throws <GoogleApiException>(() => getMetadataSample.GetMetadata(_fixture.BucketNameGeneric, "HelloMove.txt")); Assert.Equal(System.Net.HttpStatusCode.NotFound, exception.HttpStatusCode); }
public void TestSetTemporaryHold() { SetTemporaryHoldSample setTemporaryHoldSample = new SetTemporaryHoldSample(); ReleaseTemporaryHoldSample releaseTemporaryHoldSample = new ReleaseTemporaryHoldSample(); UploadFileSample uploadFileSample = new UploadFileSample(); GetMetadataSample getMetadataSample = new GetMetadataSample(); uploadFileSample.UploadFile(_bucketFixture.BucketNameRegional, _bucketFixture.FilePath, _bucketFixture.CollectRegionalObject("SetTemporaryHold.txt")); setTemporaryHoldSample.SetTemporaryHold(_bucketFixture.BucketNameRegional, "SetTemporaryHold.txt"); var metadata = getMetadataSample.GetMetadata(_bucketFixture.BucketNameRegional, "SetTemporaryHold.txt"); Assert.True(metadata.TemporaryHold); releaseTemporaryHoldSample.ReleaseTemporaryHold(_bucketFixture.BucketNameRegional, "SetTemporaryHold.txt"); }
public void ListFilesWithPrefix() { ListFilesWithPrefixSample listFilesWithPrefixSample = new ListFilesWithPrefixSample(); UploadFileSample uploadFileSample = new UploadFileSample(); // Upload 4 files. uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect("a/1.txt")); uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect("a/2.txt")); uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect("b/2.txt")); uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect("a/b/3.txt")); var files = listFilesWithPrefixSample.ListFilesWithPrefix(_fixture.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"); }
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 SetObjectMetadata() { GetMetadataSample getMetadataSample = new GetMetadataSample(); UploadFileSample uploadFileSample = new UploadFileSample(); SetObjectMetadataSample setObjectMetadataSample = new SetObjectMetadataSample(); var key = "key-to-add"; var value = "value-to-add"; var objectName = "HelloSetObjectMetadata.txt"; uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect(objectName)); setObjectMetadataSample.SetObjectMetadata(_fixture.BucketNameGeneric, objectName, key, value); var file = getMetadataSample.GetMetadata(_fixture.BucketNameGeneric, objectName); Assert.Contains(file.Metadata, m => m.Key == key && m.Value == value); }
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 DownloadPublicFile() { MakePublicSample makePublicSample = new MakePublicSample(); UploadFileSample uploadFileSample = new UploadFileSample(); DownloadPublicFileSample downloadPublicFileSample = new DownloadPublicFileSample(); uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect("HelloDownloadPublic.txt")); // Make it public makePublicSample.MakePublic(_fixture.BucketNameGeneric, "HelloDownloadPublic.txt"); // Try downloading without creds try { downloadPublicFileSample.DownloadPublicFile(_fixture.BucketNameGeneric, "HelloDownloadPublic.txt", "HelloDownloadPublic.txt"); Assert.Equal(File.ReadAllText(_fixture.FilePath), File.ReadAllText("HelloDownloadPublic.txt")); } finally { File.Delete("HelloDownloadPublic.txt"); } }
public void PrintFileAcl() { PrintFileAclSample printFileAclSample = new PrintFileAclSample(); UploadFileSample uploadFileSample = new UploadFileSample(); AddFileOwnerSample addFileOwnerSample = new AddFileOwnerSample(); string userEmail = _fixture.ServiceAccountEmail; uploadFileSample.UploadFile(_fixture.BucketNameGeneric, _fixture.FilePath, _fixture.Collect("HelloAddObjectOwner.txt")); // print file acl var fileAcl = printFileAclSample.PrintObjectAcl(_fixture.BucketNameGeneric, "HelloAddObjectOwner.txt"); Assert.DoesNotContain(fileAcl, c => c.Email == userEmail); // add file owner addFileOwnerSample.AddFileOwner(_fixture.BucketNameGeneric, "HelloAddObjectOwner.txt", userEmail); // print file acl fileAcl = printFileAclSample.PrintObjectAcl(_fixture.BucketNameGeneric, "HelloAddObjectOwner.txt"); Assert.Contains(fileAcl, c => c.Email == userEmail); }
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 BucketFixture() { ProjectId = Environment.GetEnvironmentVariable("GOOGLE_PROJECT_ID"); if (string.IsNullOrWhiteSpace(ProjectId)) { throw new Exception("You need to set the Environment variable 'GOOGLE_PROJECT_ID' with your Google Cloud Project's project id."); } // create simple bucket CreateBucket(BucketNameGeneric); // create regional bucket CreateRegionalBucketSample createRegionalBucketSample = new CreateRegionalBucketSample(); createRegionalBucketSample.CreateRegionalBucket(ProjectId, BucketNameRegional, TestLocation, StorageClasses.Regional); SleepAfterBucketCreateUpdateDelete(); TempBucketNames.Add(BucketNameRegional); //upload file to BucketName UploadFileSample uploadFileSample = new UploadFileSample(); uploadFileSample.UploadFile(BucketNameGeneric, FilePath, FileName); Collect(FileName); }