Files
monorepo/LCU.API.Operations.IncentiveAPI/LCU.API.Internal.Operations.IncentiveApi.UnitTests/Controllers/GoalControllerTest.cs
T
2026-03-17 09:53:09 -05:00

184 lines
6.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.API.Internal.Operations.IncentiveApi.Services;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using LCU.Library.Internal.IncentiveApiModels.Requests;
using LCU.API.Internal.Operations.IncentiveApi.Models;
using LCU.Library.Internal.IncentiveApiModels.Common;
namespace Application.UnitTests.Controllers
{
public class GoalControllerTest
{
private GoalController _controller;
private Mock<IGoalService> _mockGoalService;
private Mock<IUserService> _mockUserService;
private Mock<ICurrentUserService> _mockCurrentUserService;
private Mock<IGoalDispersalService> _goalDispersalService;
[SetUp]
public void Setup()
{
_mockGoalService = new Mock<IGoalService>();
_mockUserService = new Mock<IUserService>();
_goalDispersalService = new Mock<IGoalDispersalService>();
_mockCurrentUserService = new Mock<ICurrentUserService>();
_controller = new GoalController(_mockGoalService.Object, _goalDispersalService.Object ,_mockCurrentUserService.Object,
_mockUserService.Object);
}
[Test]
public async Task Get_OK()
{
_mockGoalService
.Setup(service => service.GetGoalsAsync(It.IsAny<GoalSearchRequest>())).ReturnsAsync(
new List<Goal>()
{
new Goal()
{
Id = 1
}
});
var result = await _controller.GetGoals(12,2021,12,2021, 1);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult.StatusCode);
}
[Test]
public async Task Get_DepartmentGoals_OK()
{
var goals = new DepartmentGoals(55, DateTime.Now.Year);
_mockGoalService
.Setup(service => service.GetAnnualDepartmentGoalsAsync(goals.DepartmentId, goals.Year)).ReturnsAsync(
goals);
var result = await _controller.GetDepartmentGoals(55, DateTime.Now.Year);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult.StatusCode);
}
[Test]
public async Task Get_PersonnelGoals_OK()
{
var users = new List<AppUser>()
{
new AppUser()
{
Role = Role.Admin,
AdEmail = "[email protected]",
BaseRole = "Tester",
EmployeeId = "11771",
FullName = "Test McTester",
HomeDepartment = "HOME",
PersonId = 565
}
};
var goals = new PersonnelGoals(55, DateTime.Now.Month, DateTime.Now.Year, users);
var searchRequest = new DepartmentPersonnelSearchRequest
{
DepartmentId = goals.DepartmentId,
Year = goals.Month,
Month = goals.Year
};
_mockGoalService
.Setup(service => service.GetMonthlyPersonnelGoalsAsync(searchRequest))
.ReturnsAsync(
goals);
var result = await _controller.GetPersonnelGoals(55, DateTime.Now.Month, DateTime.Now.Year);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult.StatusCode);
}
[Test]
public async Task Get_CurrentUserGoals_OK()
{
var user1 = new ApplicationUser()
{
Email = "[email protected]",
FirstName = "Test",
LastName = "McTester"
};
var user = new AppUser()
{
Role = Role.Admin,
AdEmail = "[email protected]",
BaseRole = "Tester",
EmployeeId = "11771",
FullName = "Test McTester",
HomeDepartment = "HOME",
PersonId = 565
};
var range = new MonthRange(2021,1,2021,2);
var goals = new EmployeeGoals(user, range);
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
_mockGoalService
.Setup(service => service.GetEmployeeGoalsForMonthRangeAsync(goals.Employee, range))
.ReturnsAsync(goals);
var result = await _controller.GetCurrentUserGoals(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult.StatusCode);
}
[Test]
public async Task Get_CurrentUserDepartmentsGoals_OK()
{
var user1 = new ApplicationUser()
{
Email = "[email protected]",
FirstName = "Test",
LastName = "McTester"
};
var user = new AppUser()
{
Role = Role.Admin,
AdEmail = "[email protected]",
BaseRole = "Tester",
EmployeeId = "11771",
FullName = "Test McTester",
HomeDepartment = "HOME",
PersonId = 565
};
var range = new MonthRange(2021,1,2021,2);
var goals = new List<DepartmentGoalsForRange> { new DepartmentGoalsForRange(1, range) };
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
_mockGoalService
.Setup(service => service.GetEmployeeDepartmentsGoalsForMonthRangeAsync(user, range))
.ReturnsAsync(goals);
var result = await _controller.GetCurrentUserDepartmentsGoals(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear);
Assert.NotNull(result);
var okResult = result as OkObjectResult;
Assert.NotNull(okResult);
Assert.AreEqual(200, okResult.StatusCode);
}
}
}