-
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.
Merge branch 'master' of github.com:Maksasj/hoo
- Loading branch information
Showing
13 changed files
with
236 additions
and
115 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,189 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using AutoFixture; | ||
using AutoFixture.AutoMoq; | ||
using AutoFixture.Kernel; | ||
using Hoo.Service.Controllers; | ||
using HooService.Common; | ||
Check failure on line 6 in Hoo.UnitTests/Controllers/FileControllerTests.cs GitHub Actions / build
|
||
using Moq; | ||
using NUnit.Framework.Internal; | ||
using Hoo.Service.Services; | ||
using Microsoft.Extensions.Logging; | ||
using Hoo.Service.Models; | ||
using NUnit.Framework.Legacy; | ||
using Microsoft.AspNetCore.Rewrite; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Hoo.UnitTests.Controllers | ||
{ | ||
public class FileControllerTests | ||
{ | ||
private IFixture _fixture; | ||
private Mock<IFileProviderService> _fileProviderServiceStub; | ||
Check failure on line 21 in Hoo.UnitTests/Controllers/FileControllerTests.cs GitHub Actions / build
|
||
private Mock<IFileThumbnailProviderService> _fileThumbnailProviderServiceStub; | ||
|
||
private FileThumbnailModel _fileThumbnailModelStub; | ||
private Guid _fileIdStub; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_fixture = new Fixture(); | ||
_fixture.Customize(new AutoMoqCustomization()); | ||
|
||
_fileProviderServiceStub = _fixture.Freeze<Mock<IFileProviderService>>(); | ||
_fileThumbnailProviderServiceStub = _fixture.Freeze<Mock<IFileThumbnailProviderService>>(); | ||
|
||
_fileThumbnailModelStub = _fixture.Create<FileThumbnailModel>(); | ||
_fileIdStub = _fixture.Create<Guid>(); | ||
} | ||
|
||
[Theory] | ||
public async Task GetFiles_FileProviderService_ExecutedOnce() | ||
{ | ||
// Arrange | ||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
// Act | ||
var _ = await fileControllerSut.GetFiles(); | ||
|
||
// Assert | ||
_fileProviderServiceStub.Verify(mock => mock.GetFilesAsync(), Times.Once); | ||
} | ||
|
||
[Theory] | ||
public async Task GetFileCount_FileProviderService_ExecutedOnce() | ||
{ | ||
// Arrange | ||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
// Act | ||
var _ = await fileControllerSut.GetFileCount(); | ||
|
||
// Assert | ||
_fileProviderServiceStub.Verify(mock => mock.GetFilesAsync(), Times.Once); | ||
} | ||
|
||
[Theory] | ||
public async Task GetFiles_GetFirstPage_ReturnsValidPage() | ||
{ | ||
// Arrange | ||
var files = Enumerable.Repeat(_fixture.Create<FileItemModel>(), 100).ToArray(); | ||
|
||
_fileProviderServiceStub.Setup(mock => mock.GetFilesAsync()).ReturnsAsync(files); | ||
|
||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
// Act | ||
var result = await fileControllerSut.GetFiles(); | ||
|
||
// Assert | ||
ClassicAssert.IsInstanceOf<OkObjectResult>(result); | ||
var actualResult = ((result as OkObjectResult).Value) as FileItemPageResponseModel; | ||
|
||
ClassicAssert.AreEqual(0, actualResult.PageIndex); | ||
ClassicAssert.AreEqual(100, actualResult.ItemCount); | ||
ClassicAssert.AreEqual(files, actualResult.Files); | ||
} | ||
|
||
[Test] | ||
public void Test1() | ||
[Theory] | ||
public async Task GetFiles_GetFirstPage_ReturnsOnlyFirstPage() | ||
{ | ||
// Arrange | ||
var files = Enumerable.Repeat(_fixture.Create<FileItemModel>(), 10000).ToArray(); | ||
|
||
_fileProviderServiceStub.Setup(mock => mock.GetFilesAsync()).ReturnsAsync(files); | ||
|
||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
// Act | ||
var result = await fileControllerSut.GetFiles(); | ||
|
||
// Assert | ||
ClassicAssert.IsInstanceOf<OkObjectResult>(result); | ||
var actualResult = ((result as OkObjectResult).Value) as FileItemPageResponseModel; | ||
|
||
ClassicAssert.AreEqual(0, actualResult.PageIndex); | ||
ClassicAssert.AreEqual(100, actualResult.ItemCount); | ||
ClassicAssert.AreEqual(files.Take(100), actualResult.Files); | ||
} | ||
|
||
[Theory] | ||
[TestCase(1, 100)] | ||
[TestCase(3, 25)] | ||
[TestCase(99, 100)] | ||
[TestCase(999, 100)] | ||
public async Task GetFiles_GetAnyPage_ReturnsOnlyRequestedPage(int pageIndex, int itemsPerPage) | ||
{ | ||
// Arrange | ||
var files = Enumerable.Repeat(_fixture.Create<FileItemModel>(), 10000).ToArray(); | ||
var expected = files.Skip(pageIndex * itemsPerPage).Take(itemsPerPage); | ||
|
||
_fileProviderServiceStub.Setup(mock => mock.GetFilesAsync()).ReturnsAsync(files); | ||
|
||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
// Act | ||
var result = await fileControllerSut.GetFiles(pageIndex, itemsPerPage); | ||
|
||
// Assert | ||
ClassicAssert.IsInstanceOf<OkObjectResult>(result); | ||
var actualResult = ((result as OkObjectResult).Value) as FileItemPageResponseModel; | ||
|
||
ClassicAssert.AreEqual(pageIndex, actualResult.PageIndex); | ||
ClassicAssert.AreEqual(expected.Count(), actualResult.ItemCount); | ||
ClassicAssert.AreEqual(expected, actualResult.Files); | ||
} | ||
|
||
[Theory] | ||
public async Task GetFileThumbnail_FileThumbnailProviderService_ExecutedOnce() | ||
{ | ||
// Arrange | ||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
_fileThumbnailProviderServiceStub.Setup(mock => mock.GetFileThumbnailAsync(It.IsAny<Guid>())) | ||
.ReturnsAsync(_fileThumbnailModelStub); | ||
|
||
// Act | ||
var _ = await fileControllerSut.GetFileThumbnail(_fileIdStub); | ||
|
||
// Assert | ||
_fileThumbnailProviderServiceStub.Verify(mock => mock.GetFileThumbnailAsync(It.IsAny<Guid>()), Times.Once); | ||
} | ||
|
||
[Theory] | ||
public async Task GetFileThumbnail_ReturnsExpectedValue() | ||
{ | ||
// Arrange | ||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
_fileThumbnailProviderServiceStub.Setup(mock => mock.GetFileThumbnailAsync(_fileIdStub)) | ||
.ReturnsAsync(_fileThumbnailModelStub); | ||
|
||
// Act | ||
var result = await fileControllerSut.GetFileThumbnail(_fileIdStub); | ||
|
||
// Assert | ||
ClassicAssert.IsInstanceOf<OkObjectResult>(result); | ||
var actualResult = ((result as OkObjectResult).Value) as FileThumbnailResponseModel; | ||
|
||
ClassicAssert.AreEqual(_fileThumbnailModelStub.FileId, actualResult.FileId); | ||
ClassicAssert.AreEqual(_fileThumbnailModelStub.ThumbnailUrl, actualResult.ThumbnailUrl); | ||
} | ||
|
||
[Theory] | ||
public async Task GetFileThumbnail_FileDoesNotExist_ReturnsNull() | ||
{ | ||
// Arrange | ||
var fileControllerSut = _fixture.Create<FileController>(); | ||
|
||
_fileThumbnailProviderServiceStub.Setup(mock => mock.GetFileThumbnailAsync(It.IsAny<Guid>())) | ||
.Returns(Task.FromResult<FileThumbnailModel>(null)); | ||
|
||
// Act | ||
var result = await fileControllerSut.GetFileThumbnail(_fileIdStub); | ||
|
||
// Assert | ||
ClassicAssert.IsInstanceOf<BadRequestObjectResult>(result); | ||
} | ||
} | ||
} |
Oops, something went wrong.