forked from loic-sharma/BaGet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f18fd9
commit 4a7c1b8
Showing
6 changed files
with
457 additions
and
18 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 was deleted.
Oops, something went wrong.
141 changes: 141 additions & 0 deletions
141
tests/BaGet.Core.Tests/Services/FilePackageStorageServiceTests.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,141 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using BaGet.Core.Services; | ||
using Xunit; | ||
|
||
namespace BaGet.Core.Tests.Services | ||
{ | ||
public class FilePackageStorageServiceTests | ||
{ | ||
public class SavePackageContentAsync : FactsBase | ||
{ | ||
[Fact] | ||
public async Task ThrowsIfPackageStreamIsNull() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task ThrowsIfNuspecStreamIsNull() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task DoesNotThrowIfReadmeStreamIsNull() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task SavesContent() | ||
{ | ||
// TODO: Should lowercase id/version | ||
// TODO: Should normalize version | ||
// TODO: Test that a directory was created for the package | ||
// TODO: Verify content. | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task DoesNotThrowIfContentAlreadyExistsAndContentsMatch() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task ThrowsIfContentAlreadyExistsButContentsDoNotMatch() | ||
{ | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
public class GetPackageStreamAsync : FactsBase | ||
{ | ||
[Fact] | ||
public async Task ThrowsIfDoesntExist() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetsStream() | ||
{ | ||
// TODO: Should lowercase id/version | ||
// TODO: Should normalize version | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
public class GetNuspecStreamAsync : FactsBase | ||
{ | ||
[Fact] | ||
public async Task ThrowsIfDoesntExist() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetsStream() | ||
{ | ||
// TODO: Should lowercase id/version | ||
// TODO: Should normalize version | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
public class GetReadmeStreamAsync : FactsBase | ||
{ | ||
[Fact] | ||
public async Task ThrowsIfDoesntExist() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetsStream() | ||
{ | ||
// TODO: Should lowercase id/version | ||
// TODO: Should normalize version | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
public class DeleteAsync : FactsBase | ||
{ | ||
[Fact] | ||
public async Task DoesNotThrowIfPackagePathDoesNotExist() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(false, false, false)] | ||
[InlineData(false, false, true)] | ||
[InlineData(false, true, false)] | ||
[InlineData(false, true, true)] | ||
[InlineData(true, false, false)] | ||
[InlineData(true, false, true)] | ||
[InlineData(true, true, false)] | ||
[InlineData(true, true, true)] | ||
public async Task DeletesAnyExistingContent(bool packageExists, bool nuspecExists, bool readmeExists) | ||
{ | ||
// TODO: Should lowercase id/version | ||
// TODO: Should normalize version | ||
await Task.Yield(); | ||
} | ||
} | ||
|
||
public class FactsBase | ||
{ | ||
protected readonly string _storePath; | ||
protected readonly FilePackageStorageService _target; | ||
|
||
public FactsBase() | ||
{ | ||
_storePath = Path.Combine(Path.GetTempPath(), System.Guid.NewGuid().ToString("N")); | ||
_target = new FilePackageStorageService(_storePath); | ||
} | ||
} | ||
} | ||
} |
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,61 @@ | ||
using System.Threading.Tasks; | ||
using BaGet.Core.Services; | ||
using Microsoft.Extensions.Logging; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace BaGet.Core.Tests.Services | ||
{ | ||
public class IndexingServiceTests | ||
{ | ||
private readonly Mock<IPackageService> _packages; | ||
private readonly Mock<IPackageStorageService> _storage; | ||
private readonly Mock<ISearchService> _search; | ||
private readonly IndexingService _target; | ||
|
||
public IndexingServiceTests() | ||
{ | ||
_packages = new Mock<IPackageService>(); | ||
_storage = new Mock<IPackageStorageService>(); | ||
_search = new Mock<ISearchService>(); | ||
|
||
_target = new IndexingService( | ||
_packages.Object, | ||
_storage.Object, | ||
_search.Object, | ||
Mock.Of<ILogger<IndexingService>>()); | ||
} | ||
|
||
// TODO: Add malformed package tests | ||
|
||
[Fact] | ||
public async Task WhenPackageAlreadyExists_ReturnsPackageAlreadyExists() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenDatabaseAddFailsBecausePackageAlreadyExists_ReturnsPackageAlreadyExists() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task IndexesPackage() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task WhenPackageHasNoReadme_SavesNullReadmeStream() | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Fact] | ||
public async Task ThrowsWhenStorageSaveThrows() | ||
{ | ||
await Task.Yield(); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
tests/BaGet.Core.Tests/Services/PackageDeletionServiceTests.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,53 @@ | ||
using System.Threading.Tasks; | ||
using BaGet.Core.Configuration; | ||
using BaGet.Core.Services; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace BaGet.Core.Tests.Services | ||
{ | ||
public class PackageDeletionServiceTests | ||
{ | ||
private readonly Mock<IPackageService> _packages; | ||
private readonly Mock<IPackageStorageService> _storage; | ||
|
||
private readonly BaGetOptions _options; | ||
private readonly PackageDeletionService _target; | ||
|
||
public PackageDeletionServiceTests() | ||
{ | ||
_packages = new Mock<IPackageService>(); | ||
_storage = new Mock<IPackageStorageService>(); | ||
_options = new BaGetOptions(); | ||
|
||
var optionsSnapshot = new Mock<IOptionsSnapshot<BaGetOptions>>(); | ||
optionsSnapshot.Setup(o => o.Value).Returns(_options); | ||
|
||
_target = new PackageDeletionService( | ||
_packages.Object, | ||
_storage.Object, | ||
optionsSnapshot.Object, | ||
Mock.Of<ILogger<PackageDeletionService>>()); | ||
} | ||
|
||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public async Task WhenUnlist_ReturnsTrueOnlyIfPackageExists(bool packageExists) | ||
{ | ||
await Task.Yield(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
|
||
public async Task WhenHardDelete_ReturnsTrueOnlyIfPackageExists(bool packageExists) | ||
{ | ||
// TODO: Test that hard delete ALWAYS removes from storage, regardless of packageExists | ||
await Task.Yield(); | ||
} | ||
} | ||
} |
Oops, something went wrong.