107 lines
4.0 KiB
C#
107 lines
4.0 KiB
C#
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<IPayoutService> _mockPayoutService;
|
|
private Mock<IUserService> _mockUserService;
|
|
private Mock<IActivityService> _mockActivityService;
|
|
private Mock<ICurrentUserService> _mockCurrentUserService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockPayoutService = new Mock<IPayoutService>();
|
|
_mockUserService = new Mock<IUserService>();
|
|
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
|
_mockActivityService = new Mock<IActivityService>();
|
|
_controller = new PayoutController(_mockPayoutService.Object, _mockUserService.Object,
|
|
_mockCurrentUserService.Object, _mockActivityService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Get_Employee_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 = "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<AppUser>(), It.IsAny<MonthRange>()))
|
|
.ReturnsAsync(
|
|
new List<DepartmentPayout>());
|
|
|
|
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 = "[email protected]",
|
|
FirstName = "Test",
|
|
LastName = "McTester"
|
|
};
|
|
var user = new AppUser()
|
|
{
|
|
Role = Role.Admin,
|
|
AdEmail = "[email protected]",
|
|
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<AppUser>(), It.IsAny<MonthRange>()))
|
|
.ReturnsAsync(
|
|
new List<DepartmentPayout>());
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|