using System.Collections.Generic; using System.Threading.Tasks; using LCU.API.Internal.Operations.IncentiveApi.Services; using LCU.API.Internal.Operations.IncentiveApi.Services.Payout; 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.API.Internal.Operations.IncentiveApi.Models.Payout; using LCU.Library.Internal.IncentiveApiModels.Common; namespace Application.UnitTests.Controllers { public class PayoutControllerTest { private PayoutController _controller; private Mock _mockPayoutService; private Mock _mockUserService; private Mock _mockActivityService; private Mock _mockCurrentUserService; [SetUp] public void Setup() { _mockPayoutService = new Mock(); _mockUserService = new Mock(); _mockCurrentUserService = new Mock(); _mockActivityService = new Mock(); _controller = new PayoutController(_mockPayoutService.Object, _mockUserService.Object, _mockCurrentUserService.Object, _mockActivityService.Object); } [Test] public async Task Get_Employee_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 = "5", FullName = "Test McTester", HomeDepartment = "HOME", PersonId = 565 }; _mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1); _mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(user.EmployeeId)).ReturnsAsync(user); _mockPayoutService .Setup(service => service.BuildUserDepartmentsPayoutView(It.IsAny(), It.IsAny())) .ReturnsAsync( new List()); var result = await _controller.GetEmployeePayout("5", 2021, 12); Assert.NotNull(result); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } [Test] public async Task Get_Me_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 = "5", FullName = "Test McTester", HomeDepartment = "HOME", PersonId = 565 }; _mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1); _mockUserService.Setup(service => service.GetUserByEmployeeIdAsync(user.EmployeeId)).ReturnsAsync(user); _mockPayoutService .Setup(service => service.BuildUserDepartmentsPayoutView(It.IsAny(), It.IsAny())) .ReturnsAsync( new List()); var result = await _controller.GetEmployeePayout(user.EmployeeId, 2021, 12); Assert.NotNull(result); var okResult = result as OkObjectResult; Assert.NotNull(okResult); Assert.AreEqual(200, okResult.StatusCode); } } }