generated from arcus-azure/arcus.github.template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose
OnTeardown
for blob infra (#186)
* pr-fix: correct merge w/ 'main' * feat: expose OnTeardown for blob test infra
- Loading branch information
1 parent
4225c0b
commit e577f63
Showing
10 changed files
with
236 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Arcus.Testing.Tests.Unit/Storage/BlobNameFilterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Bogus; | ||
using Xunit; | ||
|
||
namespace Arcus.Testing.Tests.Unit.Storage | ||
{ | ||
public class BlobNameFilterTests | ||
{ | ||
private static readonly Faker Bogus = new(); | ||
|
||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public void NameEqual_WithoutName_Fails(string name) | ||
{ | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameEqual(name)); | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameEqual(name, Bogus.PickRandom<StringComparison>())); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public void NameContains_WithoutValue_Fails(string value) | ||
{ | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameContains(value)); | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameContains(value, Bogus.PickRandom<StringComparison>())); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public void NameStartsWith_WithoutPrefix_Fails(string prefix) | ||
{ | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameStartsWith(prefix)); | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameStartsWith(prefix, Bogus.PickRandom<StringComparison>())); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public void NameEndsWith_WithoutSuffix_Fails(string suffix) | ||
{ | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameEndsWith(suffix)); | ||
Assert.ThrowsAny<ArgumentException>(() => BlobNameFilter.NameEndsWith(suffix, Bogus.PickRandom<StringComparison>())); | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Arcus.Testing.Tests.Unit/Storage/TemporaryBlobContainerOptionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace Arcus.Testing.Tests.Unit.Storage | ||
{ | ||
public class TemporaryBlobContainerOptionsTests | ||
{ | ||
[Fact] | ||
public void CleanMatchingBlobsOnSetup_WithNullFilters_Fails() | ||
{ | ||
// Arrange | ||
var options = new TemporaryBlobContainerOptions(); | ||
|
||
// Act / Assert | ||
Assert.ThrowsAny<ArgumentException>(() => options.OnSetup.CleanMatchingBlobs(filters: null)); | ||
Assert.ThrowsAny<ArgumentException>(() => options.OnSetup.CleanMatchingBlobs(BlobNameFilter.NameEqual("some-name"), null)); | ||
} | ||
|
||
[Fact] | ||
public void CleanMatchingBlobsOnTeardown_WithNullFilters_Fails() | ||
{ | ||
// Arrange | ||
var options = new TemporaryBlobContainerOptions(); | ||
|
||
// Act / Assert | ||
Assert.ThrowsAny<ArgumentException>(() => options.OnTeardown.CleanMatchingBlobs(filters: null)); | ||
Assert.ThrowsAny<ArgumentException>(() => options.OnTeardown.CleanMatchingBlobs(BlobNameFilter.NameEqual("some-name"), null)); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Arcus.Testing.Tests.Unit/Storage/TemporaryBlobContainerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Xunit; | ||
|
||
namespace Arcus.Testing.Tests.Unit.Storage | ||
{ | ||
public class TemporaryBlobContainerTests | ||
{ | ||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public async Task CreateBlobContainerIfNotExists_WithoutAccountName_Fails(string accountName) | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>(() => TemporaryBlobContainer.CreateIfNotExistsAsync(accountName, "<container-name>", NullLogger.Instance)); | ||
await Assert.ThrowsAnyAsync<ArgumentException>(() => TemporaryBlobContainer.CreateIfNotExistsAsync(accountName, "<container-name>", NullLogger.Instance, configureOptions: opt => { })); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public async Task CreateBlobContainerIfNotExists_WithoutContainerName_Fails(string containerName) | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>(() => TemporaryBlobContainer.CreateIfNotExistsAsync("<account-name>", containerName, NullLogger.Instance)); | ||
await Assert.ThrowsAnyAsync<ArgumentException>(() => TemporaryBlobContainer.CreateIfNotExistsAsync("<account-name>", containerName, NullLogger.Instance, configureOptions: opt => { })); | ||
} | ||
|
||
[Fact] | ||
public async Task CreateBlobContainerIfNotExists_WithoutContainerClient_Fails() | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>(() => TemporaryBlobContainer.CreateIfNotExistsAsync(containerClient: null, NullLogger.Instance)); | ||
await Assert.ThrowsAnyAsync<ArgumentException>(() => TemporaryBlobContainer.CreateIfNotExistsAsync(containerClient: null, NullLogger.Instance, configureOptions: opt => { })); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/Arcus.Testing.Tests.Unit/Storage/TemporaryBlobFileTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Arcus.Testing.Tests.Unit.Storage | ||
{ | ||
public class TemporaryBlobFileTests | ||
{ | ||
[Fact] | ||
public async Task UploadBlobFileIfNotExists_WithoutContainerUri_Fails() | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
blobContainerUri: null, | ||
"<blob-name>", | ||
BinaryData.FromString("<blob-content>"), | ||
NullLogger.Instance)); | ||
|
||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
blobContainerUri: null, | ||
"<blob-name>", | ||
BinaryData.FromString("<blob-content>"), | ||
NullLogger.Instance, | ||
configureOptions: opt => { })); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(Blanks))] | ||
public async Task UploadBlobFileIfNotExistsViaContainerUri_WithoutBlobName_Fails(string blobName) | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
new Uri("https://some-url"), | ||
blobName, | ||
BinaryData.FromString("<blob-content>"), | ||
NullLogger.Instance)); | ||
|
||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
new Uri("https://some-url"), | ||
blobName, | ||
BinaryData.FromString("<blob-content>"), | ||
NullLogger.Instance, | ||
configureOptions: opt => { })); | ||
} | ||
|
||
[Fact] | ||
public async Task UploadBlobFileIfNotExistsViaContainerUri_WithoutBlobContent_Fails() | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
new Uri("https://some-url"), | ||
"<blob-name>", | ||
blobContent: null, | ||
NullLogger.Instance)); | ||
|
||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
new Uri("https://some-url"), | ||
"<blob-name>", | ||
blobContent: null, | ||
NullLogger.Instance, | ||
configureOptions: opt => { })); | ||
} | ||
|
||
[Fact] | ||
public async Task UploadBlobFileIfNotExists_WithoutBlobClient_Fails() | ||
{ | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
blobClient: null, | ||
BinaryData.FromString("<blob-content>"), | ||
NullLogger.Instance)); | ||
|
||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
blobClient: null, | ||
BinaryData.FromString("<blob-content>"), | ||
NullLogger.Instance, | ||
configureOptions: opt => { })); | ||
} | ||
|
||
[Fact] | ||
public async Task UploadBlobFileIfNotExistsViaBlobClient_WithoutBlobContent_Fails() | ||
{ | ||
var client = Mock.Of<BlobClient>(); | ||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
client, | ||
blobContent: null, | ||
NullLogger.Instance)); | ||
|
||
await Assert.ThrowsAnyAsync<ArgumentException>( | ||
() => TemporaryBlobFile.UploadIfNotExistsAsync( | ||
client, | ||
blobContent: null, | ||
NullLogger.Instance, | ||
opt => { })); | ||
} | ||
} | ||
} |