-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for CompetitiveEventAccountingType service and controller, u…
…pdate tests for CompetitiveEvent service
- Loading branch information
Showing
5 changed files
with
356 additions
and
39 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
OutOfSchool/OutOfSchool.WebApi.Tests/Controllers/CompetEventAccountingTypeControllerTests.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,74 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Localization; | ||
using Moq; | ||
using NUnit.Framework; | ||
using OutOfSchool.BusinessLogic; | ||
using OutOfSchool.BusinessLogic.Enums; | ||
using OutOfSchool.BusinessLogic.Models.CompetitiveEvent; | ||
using OutOfSchool.BusinessLogic.Services; | ||
using OutOfSchool.WebApi.Controllers.V1; | ||
|
||
namespace OutOfSchool.WebApi.Tests.Controllers; | ||
|
||
[TestFixture] | ||
public class CompetitiveEventAccountingTypeControllerTests | ||
{ | ||
private CompetitiveEventAccountingTypeController controller; | ||
private Mock<ICompetitiveEventAccountingTypeService> service; | ||
private IMapper mapper; | ||
|
||
[SetUp] | ||
public void Setup() | ||
{ | ||
service = new Mock<ICompetitiveEventAccountingTypeService>(); | ||
var localizer = new Mock<IStringLocalizer<SharedResource>>(); | ||
controller = new CompetitiveEventAccountingTypeController(service.Object); | ||
} | ||
|
||
[Test] | ||
public async Task GetAll_WhenValidLocalization_ReturnsOkWithResult() | ||
{ | ||
// Arrange | ||
var localization = LocalizationType.Ua; | ||
var accountingTypesDto = FakeCompetitiveEventAccountingTypesDto(); | ||
|
||
service.Setup(s => s.GetAll(localization)).ReturnsAsync(accountingTypesDto); | ||
|
||
// Act | ||
var result = await controller.GetAll(); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<OkObjectResult>(result); | ||
var okResult = result as OkObjectResult; | ||
Assert.IsNotNull(okResult); | ||
Assert.AreEqual(StatusCodes.Status200OK, okResult.StatusCode); | ||
Assert.AreEqual(accountingTypesDto, okResult.Value); | ||
} | ||
|
||
[Test] | ||
public async Task GetAll_WhenEmptyCollection_ReturnsNoContent() | ||
{ | ||
// Arrange | ||
service.Setup(s => s.GetAll(It.IsAny<LocalizationType>())) | ||
.ReturnsAsync(new List<CompetitiveEventAccountingTypeDto>()); | ||
|
||
// Act | ||
var result = await controller.GetAll().ConfigureAwait(false); | ||
|
||
// Assert | ||
Assert.IsInstanceOf<NoContentResult>(result); | ||
} | ||
|
||
private IEnumerable<CompetitiveEventAccountingTypeDto> FakeCompetitiveEventAccountingTypesDto() | ||
{ | ||
return new List<CompetitiveEventAccountingTypeDto>() | ||
{ | ||
new CompetitiveEventAccountingTypeDto { Id = 1, Title = "Тип 1"}, | ||
new CompetitiveEventAccountingTypeDto { Id = 2, Title = "Тип 2"}, | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.