112 lines
3.9 KiB
C#
112 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
|
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
|
|
|
namespace Application.UnitTests.Controllers
|
|
{
|
|
public class UserAssignmentControllerTest
|
|
{
|
|
private UserAssignmentController _controller;
|
|
private Mock<IUserAssignmentService> _mockUserAssignmentService;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockUserAssignmentService = new Mock<IUserAssignmentService>();
|
|
_controller = new UserAssignmentController(_mockUserAssignmentService.Object);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAllUserAssignments_OK()
|
|
{
|
|
_mockUserAssignmentService.Setup(service => service.GetAllUserAssignmentsAsync())
|
|
.ReturnsAsync(new List<UserAssignment>());
|
|
|
|
var result = await _controller.GetAllUserAssignments();
|
|
Assert.NotNull(result);
|
|
|
|
var okResult = result as OkObjectResult;
|
|
Assert.NotNull(okResult);
|
|
Assert.AreEqual(200, okResult.StatusCode);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAllUserAssignments_Exception()
|
|
{
|
|
{
|
|
_mockUserAssignmentService.Setup(service => service.GetAllUserAssignmentsAsync())
|
|
.ThrowsAsync(new Exception("Exception Message"));
|
|
|
|
var result = await _controller.GetAllUserAssignments();
|
|
Assert.NotNull(result);
|
|
|
|
var statusRes = result as StatusCodeResult;
|
|
Assert.NotNull(statusRes);
|
|
Assert.AreEqual(500, statusRes.StatusCode);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public async Task SetRegionalManager_OK()
|
|
{
|
|
|
|
var assignment = new UserAssignmentRequest
|
|
{
|
|
EmployeeId = "123",
|
|
Key = "NORTH",
|
|
Type = AssignmentType.RegionalManager
|
|
};
|
|
|
|
_mockUserAssignmentService.Setup(service => service.SetRegionalManager(It.IsAny<UserAssignmentRequest>()))
|
|
.ReturnsAsync(new UserAssignment());
|
|
|
|
var result = await _controller.SetRegionalManager(assignment);
|
|
Assert.NotNull(result);
|
|
|
|
var okResult = result as OkResult;
|
|
Assert.NotNull(okResult);
|
|
Assert.AreEqual(200, okResult.StatusCode);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SetRegionalManager_BadUserAssignmentException()
|
|
{
|
|
var assignment = new UserAssignmentRequest();
|
|
_mockUserAssignmentService.Setup(service => service.SetRegionalManager(assignment))
|
|
.ThrowsAsync(new BadUserAssignmentException("Exception Message"));
|
|
|
|
var result = await _controller.SetRegionalManager(assignment);
|
|
Assert.NotNull(result);
|
|
|
|
var badRequestRes = result as BadRequestObjectResult;
|
|
Assert.NotNull(badRequestRes);
|
|
Assert.AreEqual(400, badRequestRes.StatusCode);
|
|
Assert.AreEqual("Exception Message", badRequestRes.Value);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SetRegionalManager_Exception()
|
|
{
|
|
var assignment = new UserAssignmentRequest();
|
|
_mockUserAssignmentService.Setup(service => service.SetRegionalManager(assignment))
|
|
.ThrowsAsync(new Exception("Exception Message"));
|
|
|
|
var result = await _controller.SetRegionalManager(assignment);
|
|
Assert.NotNull(result);
|
|
|
|
var statusRes = result as StatusCodeResult;
|
|
Assert.NotNull(statusRes);
|
|
Assert.AreEqual(500, statusRes.StatusCode);
|
|
}
|
|
}
|
|
}
|