public void DeleteAsync_NullUri() { var storage = new AzureBlobStorage(Configuration); storage .Awaiting(s => s.DeleteAsync(null)) .Should().Throw <ArgumentNullException>(); }
public void PutAsync_NullStream() { var storage = new AzureBlobStorage(Configuration); storage .Awaiting(s => s.PutAsync(null, ".dat")) .Should().Throw <ArgumentNullException>(); }
public void DeleteAsync_NotMyUri() { var storage = new AzureBlobStorage(Configuration); var uri = new Uri("some://other/base/file.txt"); storage .Awaiting(s => s.DeleteAsync(uri)) .Should().Throw <ArgumentException>(); }
public void DeleteAsync_RelativeUri() { var storage = new AzureBlobStorage(Configuration); var uri = new Uri("relative/file.txt", UriKind.Relative); storage .Awaiting(s => s.DeleteAsync(uri)) .Should().Throw <ArgumentException>(); }
public async Task DeleteAsync_DoesNotExist() { var storage = new AzureBlobStorage(Configuration); var uri = new Uri(storage.BaseUri, "a/b/file.txt"); var result = await storage.DeleteAsync(uri); result.Should().BeFalse(); }
public void PutAsync_UnreadableStream() { var storage = new AzureBlobStorage(Configuration); var stream = Mock.Of <Stream>(s => s.CanRead == false); storage .Awaiting(s => s.PutAsync(stream, ".dat")) .Should().Throw <ArgumentException>(); }
public void GetAsync_NotFound() { var storage = new AzureBlobStorage(Configuration); var uri = new Uri(storage.BaseUri, "does/not/exist.txt"); async Task <string> GetAsync() => await ReadUtf8Async(await storage.GetAsync(uri)); Awaiting(GetAsync).Should() .Throw <RequestFailedException>() .Which.Status.Should().Be(404); }
public async Task GetAsync() { var storage = new AzureBlobStorage(Configuration); var uri = new Uri(storage.BaseUri, "a/file.txt"); await WriteBlobAsync("a/file.txt"); using var stream = await storage.GetAsync(uri); var text = await ReadUtf8Async(stream); text.Should().Be(TestText); }
public async Task DeleteAsync_Exists() { var storage = new AzureBlobStorage(Configuration); var uri = new Uri(storage.BaseUri, "a/b/file.txt"); await WriteBlobAsync("a/b/file.txt"); await WriteBlobAsync("a/other.txt"); (await BlobExistsAsync("a/b/file.txt")) .Should().BeTrue("blob should exist prior to deletion"); var result = await storage.DeleteAsync(uri); result.Should().BeTrue(); (await BlobExistsAsync("a/b/file.txt")) .Should().BeFalse("blob should have been deleted"); (await BlobExistsAsync("a/other.txt")) .Should().BeTrue("other blob should NOT have been deleted"); }
public async Task PutAsync(string extension) { var storage = new AzureBlobStorage(Configuration); Uri uri; using (var stream = new MemoryStream(TestBytes)) uri = await storage.PutAsync(stream, extension); uri.Should().NotBeNull(); uri.Should().Match <Uri>(u => storage.BaseUri.IsBaseOf(u)); uri.AbsolutePath.Should().MatchRegex( @"^/[0-9]{4}/[0-9]{4}/[0-9]{8}_[0-9]{6}_[0-9a-fA-F]{8}\.txt$" ); var name = GetBlobName(uri, storage); var text = await ReadBlobAsync(name); text.Should().Be(TestText); }
private static string GetBlobName(Uri uri, AzureBlobStorage storage) { return(uri.ToRelative(storage.BaseUri).ToString()); }