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 _mockGoalService; private Mock _mockUserService; private Mock _mockCurrentUserService; private Mock _goalDispersalService; [SetUp] public void Setup() { _mockGoalService = new Mock(); _mockUserService = new Mock(); _goalDispersalService = new Mock(); _mockCurrentUserService = new Mock(); _controller = new GoalController(_mockGoalService.Object, _goalDispersalService.Object ,_mockCurrentUserService.Object, _mockUserService.Object); } [Test] public async Task Get_OK() { _mockGoalService .Setup(service => service.GetGoalsAsync(It.IsAny())).ReturnsAsync( new List() { 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() { new AppUser() { Role = Role.Admin, AdEmail = "tester@test.com", 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 = "tester@test.com", FirstName = "Test", LastName = "McTester" }; var user = new AppUser() { Role = Role.Admin, AdEmail = "tester@test.com", 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 = "tester@test.com", FirstName = "Test", LastName = "McTester" }; var user = new AppUser() { Role = Role.Admin, AdEmail = "tester@test.com", BaseRole = "Tester", EmployeeId = "11771", FullName = "Test McTester", HomeDepartment = "HOME", PersonId = 565 }; var range = new MonthRange(2021,1,2021,2); var goals = new List { 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); } } }