Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

Commit

Permalink
test(back-end): Add Statistics controller tests
Browse files Browse the repository at this point in the history
See also: #119
  • Loading branch information
CarlosPavajeau committed Jan 7, 2021
1 parent 4301dbe commit d5bd0d0
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions Kaizen.Test/Controllers/StatisticsControllerTest.cs
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);
}
}
}

0 comments on commit d5bd0d0

Please sign in to comment.