This repository has been archived by the owner on Jun 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(back-end): Add Statistics controller tests
See also: #119
- Loading branch information
1 parent
4301dbe
commit d5bd0d0
Showing
1 changed file
with
81 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using AutoMapper; | ||
using Kaizen.Controllers; | ||
using Kaizen.Domain.Entities; | ||
using Kaizen.Domain.Repositories; | ||
using Kaizen.Models.Statistics; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Kaizen.Test.Controllers | ||
{ | ||
[TestFixture] | ||
public class StatisticsControllerTest : BaseControllerTest | ||
{ | ||
private StatisticsController _statisticsController; | ||
private Mock<IStatisticsRepository> _statisticsRepository; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_statisticsRepository = new Mock<IStatisticsRepository>(); | ||
_statisticsController = | ||
new StatisticsController(_statisticsRepository.Object, ServiceProvider.GetService<IMapper>()); | ||
|
||
SetUpStatisticsRepository(); | ||
} | ||
|
||
private void SetUpStatisticsRepository() | ||
{ | ||
_statisticsRepository.Setup(r => r.GetYearStatistics(DateTime.Now.Year)).ReturnsAsync(new YearStatistics | ||
{ | ||
Id = 1, | ||
AppliedActivities = 1, | ||
Year = DateTime.Now.Year | ||
}); | ||
|
||
_statisticsRepository.Setup(r => r.GetMonthStatistics(It.IsAny<DateTime>())).ReturnsAsync( | ||
new MonthStatistics | ||
{ | ||
Id = 1, | ||
AppliedActivities = 1 | ||
}); | ||
|
||
_statisticsRepository.Setup(r => r.GetDayStatistics(It.IsAny<DateTime>())).ReturnsAsync(new DayStatistics | ||
{ | ||
Id = 1, | ||
AppliedActivities = 1 | ||
}); | ||
} | ||
|
||
[Test] | ||
public async Task Get_Current_Year_Statistics() | ||
{ | ||
ActionResult<YearStatisticsViewModel> result = await _statisticsController.CurrentYear(); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.Value); | ||
} | ||
|
||
[Test] | ||
public async Task Get_Current_Month_Statistics() | ||
{ | ||
ActionResult<MonthStatisticsViewModel> result = await _statisticsController.CurrentMont(); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.Value); | ||
} | ||
|
||
[Test] | ||
public async Task Get_Current_Day_Statistics() | ||
{ | ||
var result = await _statisticsController.CurrentDay(); | ||
|
||
Assert.IsNotNull(result); | ||
Assert.IsNotNull(result.Value); | ||
} | ||
} | ||
} |