Refactored archive code into a service so that I can write tests for it.
This commit is contained in:
parent
07fd959b22
commit
6b76c8b211
22 changed files with 146 additions and 49 deletions
37
API.Tests/Services/ArchiveServiceTests.cs
Normal file
37
API.Tests/Services/ArchiveServiceTests.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace API.Tests.Services
|
||||
{
|
||||
public class ArchiveServiceTests
|
||||
{
|
||||
private readonly IArchiveService _archiveService;
|
||||
private readonly ILogger<ArchiveService> _logger = Substitute.For<ILogger<ArchiveService>>();
|
||||
|
||||
private readonly string _testDirectory =
|
||||
Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ArchiveService");
|
||||
|
||||
public ArchiveServiceTests()
|
||||
{
|
||||
_archiveService = new ArchiveService(_logger);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("flat file.zip", false)]
|
||||
[InlineData("file in folder in folder.zip", true)]
|
||||
[InlineData("file in folder.zip", true)]
|
||||
[InlineData("file in folder_alt.zip", true)]
|
||||
public void ArchiveNeedsFlatteningTest(string archivePath, bool expected)
|
||||
{
|
||||
var file = Path.Join(_testDirectory, archivePath);
|
||||
using ZipArchive archive = ZipFile.OpenRead(file);
|
||||
Assert.Equal(expected, _archiveService.ArchiveNeedsFlattening(archive));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue