Skip to content

Commit

Permalink
Start unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loic-sharma committed Nov 4, 2018
1 parent 7f18fd9 commit 4a7c1b8
Show file tree
Hide file tree
Showing 6 changed files with 457 additions and 18 deletions.
1 change: 1 addition & 0 deletions tests/BaGet.Core.Tests/BaGet.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
Expand Down
18 changes: 0 additions & 18 deletions tests/BaGet.Core.Tests/FilePackageStorageServiceTests.cs

This file was deleted.

141 changes: 141 additions & 0 deletions tests/BaGet.Core.Tests/Services/FilePackageStorageServiceTests.cs
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);
}
}
}
}
61 changes: 61 additions & 0 deletions tests/BaGet.Core.Tests/Services/IndexingServiceTests.cs
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 tests/BaGet.Core.Tests/Services/PackageDeletionServiceTests.cs
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();
}
}
}
Loading

0 comments on commit 4a7c1b8

Please sign in to comment.