Adding
This commit is contained in:
+786
@@ -0,0 +1,786 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
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.Services.AutoDecision;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class ActivityControllerTest
|
||||
{
|
||||
private ActivityController _controller;
|
||||
private Mock<IActivityService> _mockActivityService;
|
||||
private Mock<IActivityDetailService> _mockActivityDetailService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
private Mock<IDashboardService> _mockDashboardService;
|
||||
private Mock<IActivityDecisionService> _mockActivityDecisionService;
|
||||
private Mock<IEStatementService> _mockEStatementService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockActivityService = new Mock<IActivityService>();
|
||||
_mockActivityDetailService = new Mock<IActivityDetailService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockDashboardService = new Mock<IDashboardService>();
|
||||
_mockActivityDecisionService = new Mock<IActivityDecisionService>();
|
||||
_mockEStatementService = new Mock<IEStatementService>();
|
||||
_controller = new ActivityController(_mockActivityService.Object, _mockActivityDetailService.Object, _mockUserService.Object,
|
||||
_mockCurrentUserService.Object, _mockDashboardService.Object, _mockActivityDecisionService.Object, _mockEStatementService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
var filter = new ActivityFilter()
|
||||
{
|
||||
Limit = 999,
|
||||
Page = 1
|
||||
};
|
||||
var results = new PagedResult<Activity>();
|
||||
results.Items = new List<Activity>()
|
||||
{
|
||||
new Activity()
|
||||
{
|
||||
Id = 1
|
||||
}
|
||||
};
|
||||
results.Total = 1;
|
||||
|
||||
_mockActivityService
|
||||
.Setup(service => service.ListByFilterAsync(filter)).ReturnsAsync(results);
|
||||
var result = await _controller.Get(filter);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task POST_OK()
|
||||
{
|
||||
var activity = new Activity()
|
||||
{
|
||||
Product = Product.CheckCard,
|
||||
State = ActivityState.Created,
|
||||
EmployeeId = "55",
|
||||
DepartmentId = 55,
|
||||
SourceId = "444",
|
||||
SourceSystem = SystemType.Dna
|
||||
};
|
||||
_mockActivityService
|
||||
.Setup(service => service.SaveActivityAsync(activity)).ReturnsAsync(1);
|
||||
|
||||
var result = await _controller.CreateActivity(activity);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_CurrentUserActivity_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 EmployeeProgress(user, range, new List<IPayoutRule>());
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockDashboardService
|
||||
.Setup(service => service.GetEmployeeProgressForMonthRangeAsync(goals.Employee, range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _controller.GetCurrentUserProgress(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_CurrentUserDepartmentProgress_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,
|
||||
Departments = new List<UserDepartment> {
|
||||
new UserDepartment {
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 7, 1),
|
||||
EndDate = new DateTime(2021, 7, 31)
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var goals = new List<DepartmentProgress> { new DepartmentProgress(1, range) };
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockActivityService
|
||||
.Setup(service => service.GetDepartmentActivityForMonthRangeAsync(user.Departments, range))
|
||||
.ReturnsAsync(goals);
|
||||
|
||||
var result = await _controller.GetCurrentUserProgress(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_CurrentUserRegionProgress_OK()
|
||||
{
|
||||
var user1 = new ApplicationUser()
|
||||
{
|
||||
Email = "[email protected]",
|
||||
FirstName = "Test",
|
||||
LastName = "McTester"
|
||||
};
|
||||
var user = new AppUser()
|
||||
{
|
||||
Role = Role.RegionalManager,
|
||||
AdEmail = "[email protected]",
|
||||
BaseRole = "Tester",
|
||||
EmployeeId = "11771",
|
||||
FullName = "Test McTester",
|
||||
HomeDepartment = "HOME",
|
||||
PersonId = 565,
|
||||
Departments = new List<UserDepartment> {
|
||||
new UserDepartment {
|
||||
DepartmentId = 1,
|
||||
StartDate = new DateTime(2021, 7, 1),
|
||||
EndDate = new DateTime(2021, 7, 31),
|
||||
Role = Role.RegionalManager,
|
||||
Department = new Department()
|
||||
{
|
||||
Id = 5,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Dept 1",
|
||||
RegionCode = Region.North.Code
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var range = new MonthRange(2021,1,2021,2);
|
||||
var progress = new RegionProgress(Region.North, range);
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser()).Returns(user1);
|
||||
_mockUserService.Setup(service => service.GetUserByAdEmailAsync(user1.Email)).ReturnsAsync(user);
|
||||
_mockDashboardService
|
||||
.Setup(service => service.GetRegionProgressForMonthRangeAsync(Region.North, range))
|
||||
.ReturnsAsync(progress);
|
||||
|
||||
var result = await _controller.GetRegionProgress(range.FromMonth, range.FromYear, range.ToMonth, range.ToYear, Region.East.Code);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivityStateChanges_OK()
|
||||
{
|
||||
_mockActivityService
|
||||
.Setup(service => service.GetActivityStateChanges(It.IsAny<int>())).ReturnsAsync(
|
||||
new List<ActivityStateChange>()
|
||||
{
|
||||
new ActivityStateChange()
|
||||
{
|
||||
Id = 1,
|
||||
ActivityId = 5
|
||||
},
|
||||
new ActivityStateChange()
|
||||
{
|
||||
Id = 2,
|
||||
ActivityId = 5
|
||||
},
|
||||
new ActivityStateChange()
|
||||
{
|
||||
Id = 3,
|
||||
ActivityId = 5
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetActivityStateChanges(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
|
||||
var value = okResult.Value as IReadOnlyCollection<ActivityStateChange>;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual(3, value.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivityStateChanges_Exception()
|
||||
{
|
||||
_mockActivityService.Setup(x => x.GetActivityStateChanges(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("oops"));
|
||||
|
||||
var result = await _controller.GetActivityStateChanges(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Ok()
|
||||
{
|
||||
|
||||
_mockActivityService.Setup(x => x.GetActivity(5))
|
||||
.ReturnsAsync(new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
});
|
||||
|
||||
var result = await _controller.Get(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
|
||||
var value = okResult.Value as Activity;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual(5, value.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_NotFound()
|
||||
{
|
||||
_mockActivityService.Setup(x => x.GetActivity(1))
|
||||
.ThrowsAsync(new NotFoundException("Not Found"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Exception()
|
||||
{
|
||||
_mockActivityService.Setup(x => x.GetActivity(1))
|
||||
.ThrowsAsync(new Exception("Internal Server Error"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_Ok()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange));
|
||||
_mockActivityService.Setup(mock => mock.ApplyStateChange(stateChange,true))
|
||||
.ReturnsAsync(activityResult);
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_AppUserNotFound()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns((ApplicationUser)null);
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_UserNotFound()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_BadActivityStateChangeException()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new BadActivityStateChangeException("Bad activity state change."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Bad activity state change.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_NotAuthorizedException()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new NotAuthorizedException("Not Authorized."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var objectResult = result as ObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(403, objectResult.StatusCode);
|
||||
Assert.AreEqual("Not Authorized.", objectResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_NotFoundException()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new NotFoundException("Activity Not Found."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ManuallyUpdateActivityState_Exception()
|
||||
{
|
||||
var stateChange = new ActivityStateChange
|
||||
{
|
||||
ActivityId = 11,
|
||||
Note = "Change",
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
var activityResult = new Activity
|
||||
{
|
||||
Id = 11,
|
||||
State = ActivityState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ValidateCanApplyActivityStateChange(It.IsAny<AppUser>(), stateChange))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.ManuallyUpdateActivityState(stateChange);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_Ok()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
|
||||
var response = new ActivityTransferAction
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewActivity = new Activity
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Referral,
|
||||
Detail = new ActivityDetail
|
||||
{
|
||||
Activity = new Activity
|
||||
{
|
||||
Product = Product.CreditCard,
|
||||
Type = ActivityType.Referral,
|
||||
},
|
||||
AccountNumber = "1234567890"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(request)).ReturnsAsync(response).Verifiable();
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
_mockActivityService.Verify();
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
|
||||
var activityTransfer = okResult.Value as ActivityTransferAction;
|
||||
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual("XXXXXX7890", activityTransfer.NewActivity.Detail.AccountNumber);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_NotFoundException()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(It.IsAny<ActivityTransferRequest>()))
|
||||
.ThrowsAsync(new NotFoundException(""));
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_BadActivityTransferRequestException()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(It.IsAny<ActivityTransferRequest>()))
|
||||
.ThrowsAsync(new BadActivityTransferActionException("Cannot complete request."));
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Cannot complete request.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RequestTransfer_Exception()
|
||||
{
|
||||
var request = new ActivityTransferRequest
|
||||
{
|
||||
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
||||
RequestedActivityId = 1,
|
||||
NewDepartmentId = 2,
|
||||
NewEmployeeId = "C0000"
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.RequestTransfer(It.IsAny<ActivityTransferRequest>()))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.RequestTransfer(request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_Ok()
|
||||
{
|
||||
var approval = new ActivityTransferApprovalRequest
|
||||
{
|
||||
Id = 1,
|
||||
ApprovalState = ActivityTransferState.Accepted
|
||||
};
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), approval))
|
||||
.ReturnsAsync(new ActivityTransferAction { Id = 1 } );
|
||||
|
||||
var result = await _controller.ApproveTransfer(approval);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_AppUserNotFound()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns((ApplicationUser)null);
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_UserNotFound()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync((AppUser)null);
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
Assert.AreEqual("No AD User Found.", unauthorizedResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_NotFoundException()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService
|
||||
.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), It.IsAny<ActivityTransferApprovalRequest>()))
|
||||
.ThrowsAsync(new NotFoundException(""));
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Activity Transfer Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_BadActivityTransferActionException()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService
|
||||
.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), It.IsAny<ActivityTransferApprovalRequest>()))
|
||||
.ThrowsAsync(new BadActivityTransferActionException("Cannot complete request."));
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("Cannot complete request.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ApproveTransfer_Exception()
|
||||
{
|
||||
_mockCurrentUserService.Setup(mock => mock.GetCurrentUser())
|
||||
.Returns(new ApplicationUser { Email = "[email protected]" });
|
||||
_mockUserService.Setup(mock => mock.GetUserByAdEmailAsync(It.Is<string>(s => s == "[email protected]")))
|
||||
.ReturnsAsync(new AppUser());
|
||||
_mockActivityService
|
||||
.Setup(mock => mock.ApproveTransfer(It.IsAny<AppUser>(), It.IsAny<ActivityTransferApprovalRequest>()))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.ApproveTransfer(new ActivityTransferApprovalRequest());
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransferAction_Ok()
|
||||
{
|
||||
var actionFromService = new ActivityTransferAction
|
||||
{
|
||||
Id = 1,
|
||||
State = ActivityTransferState.Requested
|
||||
};
|
||||
_mockActivityService.Setup(mock => mock.GetRequestedTransfer(1))
|
||||
.ReturnsAsync(actionFromService);
|
||||
|
||||
var result = await _controller.GetTransferAction(1);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTransferAction_Exception()
|
||||
{
|
||||
_mockActivityService.Setup(mock => mock.GetRequestedTransfer(1))
|
||||
.ThrowsAsync(new Exception("Internal Server Error."));
|
||||
|
||||
var result = await _controller.GetTransferAction(1);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services.QueueServices;
|
||||
using LCU.Library.Internal.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class ActivityImportControllerTest
|
||||
{
|
||||
private ActivityImportController _controller;
|
||||
private Mock<IQueueCreditCardImportService> _mockQueueCreditCardImportService;
|
||||
private Mock<IQueueIndirectVehicleImportService> _mockQueueVehicleImportService;
|
||||
private Mock<IQueueAlliedGapMbpService> _mockQueueAlliedGapMbpService;
|
||||
private Mock<IQueueActionCreditCardService> _mockQueueActionCreditCardService;
|
||||
private Mock<IQueueActionVehicleService> _mockQueueActionVehicleService;
|
||||
private Mock<IEStatementService> _mockEStatementService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockQueueCreditCardImportService = new Mock<IQueueCreditCardImportService>();
|
||||
_mockQueueVehicleImportService = new Mock<IQueueIndirectVehicleImportService>();
|
||||
_mockQueueActionVehicleService = new Mock<IQueueActionVehicleService>();
|
||||
_mockQueueActionCreditCardService = new Mock<IQueueActionCreditCardService>();
|
||||
_mockQueueAlliedGapMbpService = new Mock<IQueueAlliedGapMbpService>();
|
||||
_controller = new ActivityImportController(_mockQueueCreditCardImportService.Object, _mockQueueVehicleImportService.Object,
|
||||
_mockQueueActionCreditCardService.Object,
|
||||
_mockQueueActionVehicleService.Object, _mockQueueAlliedGapMbpService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueCreditCardImportRequest_Accepted()
|
||||
{
|
||||
_mockQueueCreditCardImportService.Setup(x => x.QueueCreditCardSalesImport(It.IsAny<ImportCreditCardSalesRequest>()));
|
||||
|
||||
var result = await _controller.QueueCreditCardImportRequest(It.IsAny<ImportCreditCardSalesRequest>());
|
||||
|
||||
var acceptedResult = result as AcceptedResult;
|
||||
Assert.NotNull(acceptedResult);
|
||||
Assert.AreEqual(202, acceptedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueCreditCardImportRequest_ServiceFails_ServiceException()
|
||||
{
|
||||
_mockQueueCreditCardImportService.Setup(x => x.QueueCreditCardSalesImport(It.IsAny<ImportCreditCardSalesRequest>()))
|
||||
.ThrowsAsync(new ServiceException("Failure"));
|
||||
|
||||
var result = await _controller.QueueCreditCardImportRequest(It.IsAny<ImportCreditCardSalesRequest>());
|
||||
|
||||
var objectResult = result as ObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueCreditCardImportRequest_ServiceFails_Exception()
|
||||
{
|
||||
_mockQueueCreditCardImportService.Setup(x => x.QueueCreditCardSalesImport(It.IsAny<ImportCreditCardSalesRequest>()))
|
||||
.ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var result = await _controller.QueueCreditCardImportRequest(It.IsAny<ImportCreditCardSalesRequest>());
|
||||
|
||||
var objectResult = result as StatusCodeResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueIndirectVehicleImportRequest_Accepted()
|
||||
{
|
||||
_mockQueueVehicleImportService.Setup(x => x.QueueIndirectVehicleSalesImport(It.IsAny<ImportIndirectVehicleSalesRequest>()));
|
||||
|
||||
var result = await _controller.QueueIndirectVehicleImportRequest(It.IsAny<ImportIndirectVehicleSalesRequest>());
|
||||
|
||||
var acceptedResult = result as AcceptedResult;
|
||||
Assert.NotNull(acceptedResult);
|
||||
Assert.AreEqual(202, acceptedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueIndirectVehicleImportRequest_ServiceFails_ServiceException()
|
||||
{
|
||||
_mockQueueVehicleImportService.Setup(x => x.QueueIndirectVehicleSalesImport(It.IsAny<ImportIndirectVehicleSalesRequest>()))
|
||||
.ThrowsAsync(new ServiceException("Failure"));
|
||||
|
||||
var result = await _controller.QueueIndirectVehicleImportRequest(It.IsAny<ImportIndirectVehicleSalesRequest>());
|
||||
|
||||
var objectResult = result as ObjectResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task QueueeIndirectVehicleImportRequest_ServiceFails_Exception()
|
||||
{
|
||||
_mockQueueVehicleImportService.Setup(x => x.QueueIndirectVehicleSalesImport(It.IsAny<ImportIndirectVehicleSalesRequest>()))
|
||||
.ThrowsAsync(new Exception("Failure"));
|
||||
|
||||
var result = await _controller.QueueIndirectVehicleImportRequest(It.IsAny<ImportIndirectVehicleSalesRequest>());
|
||||
|
||||
var objectResult = result as StatusCodeResult;
|
||||
Assert.NotNull(objectResult);
|
||||
Assert.AreEqual(500, objectResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
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.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class CommissionControllerTest
|
||||
{
|
||||
private CommissionController _controller;
|
||||
private Mock<ICommissionService> _mockCommissionService;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCommissionService = new Mock<ICommissionService>();
|
||||
_controller = new CommissionController(_mockCommissionService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockCommissionService.Setup(mock => mock.GetCommissionsAsync())
|
||||
.ReturnsAsync(new List<Commission>
|
||||
{
|
||||
new Commission()
|
||||
});
|
||||
|
||||
var result = await _controller.Get();
|
||||
|
||||
Assert.NotNull(result);
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_ServiceException_Returns500()
|
||||
{
|
||||
_mockCommissionService.Setup(mock => mock.GetCommissionsAsync())
|
||||
.ThrowsAsync(new Exception("error thrown"));
|
||||
|
||||
var result = await _controller.Get();
|
||||
|
||||
Assert.NotNull(result);
|
||||
var errorResult = result as StatusCodeResult;
|
||||
Assert.NotNull(errorResult);
|
||||
Assert.AreEqual(500, errorResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetCommissions_Created()
|
||||
{
|
||||
var commissions = new List<Commission>();
|
||||
_mockCommissionService.Setup(mock => mock.SaveCommissionsAsync(commissions));
|
||||
|
||||
var result = await _controller.SetCommissions(commissions);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var noContentResult = result as NoContentResult;
|
||||
Assert.NotNull(noContentResult);
|
||||
Assert.AreEqual(204, noContentResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetCommissions_ServiceException_Returns500()
|
||||
{
|
||||
var commissions = new List<Commission>();
|
||||
_mockCommissionService.Setup(mock => mock.SaveCommissionsAsync(commissions))
|
||||
.ThrowsAsync(new Exception("error thrown"));
|
||||
|
||||
var result = await _controller.SetCommissions(commissions);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var errorResult = result as StatusCodeResult;
|
||||
Assert.NotNull(errorResult);
|
||||
Assert.AreEqual(500, errorResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SetCommissions_CommissionExistsException_Returns409()
|
||||
{
|
||||
var commissions = new List<Commission>();
|
||||
_mockCommissionService.Setup(mock => mock.SaveCommissionsAsync(commissions))
|
||||
.ThrowsAsync(new CommissionExistsException("commission exists error thrown"));
|
||||
|
||||
var result = await _controller.SetCommissions(commissions);
|
||||
|
||||
Assert.NotNull(result);
|
||||
var conflictResult = result as ConflictObjectResult;
|
||||
Assert.NotNull(conflictResult);
|
||||
Assert.AreEqual(409, conflictResult.StatusCode);
|
||||
Assert.AreEqual("commission exists error thrown", conflictResult.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
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 LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Common;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class DeadActivityControllerTest
|
||||
{
|
||||
private DeadActivityController _controller;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
_controller = new DeadActivityController(_mockDeadActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
var filter = new DeadActivityFilter()
|
||||
{
|
||||
Limit = 999,
|
||||
Page = 1
|
||||
};
|
||||
var results = new PagedResult<DeadActivity>();
|
||||
results.Items = new List<DeadActivity>()
|
||||
{
|
||||
new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test")
|
||||
};
|
||||
results.Total = 1;
|
||||
|
||||
_mockDeadActivityService
|
||||
.Setup(service => service.ListByFilterAsync(filter)).ReturnsAsync(results);
|
||||
var result = await _controller.Get(filter);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Ok()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(5))
|
||||
.ReturnsAsync(new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test"));
|
||||
|
||||
var result = await _controller.Get(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
var value = okResult.Value as DeadActivity;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual("1234", value.SourceId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_NotFound()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(1))
|
||||
.ThrowsAsync(new NotFoundException("Not Found"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("DeadActivity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Exception()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(1))
|
||||
.ThrowsAsync(new Exception("Internal Server Error"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDeadActivityState_Ok()
|
||||
{
|
||||
var deadActivity = new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test");
|
||||
_mockDeadActivityService.Setup(mock => mock.ProcessDeadActivity(1,2))
|
||||
.ReturnsAsync(deadActivity);
|
||||
|
||||
var result = await _controller.Delete(1,2);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProcessDeadActivityState_Ok_NoLink()
|
||||
{
|
||||
var deadActivity = new DeadActivity("1234", SystemType.Action, DeadActivityReason.Other, "test");
|
||||
_mockDeadActivityService.Setup(mock => mock.ProcessDeadActivity(1,-1))
|
||||
.ReturnsAsync(deadActivity);
|
||||
|
||||
var result = await _controller.Delete(1);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
using System.Threading.Tasks;
|
||||
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 LCU.API.Internal.Operations.IncentiveApi.Controllers;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class DeadActiviyControlerTest
|
||||
{
|
||||
private DeadActivityController _controller;
|
||||
private Mock<IDeadActivityService> _mockDeadActivityService;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mockDeadActivityService = new Mock<IDeadActivityService>();
|
||||
_controller = new DeadActivityController(_mockDeadActivityService.Object);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_Ok()
|
||||
{
|
||||
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(5))
|
||||
.ReturnsAsync(new DeadActivity(new Activity()
|
||||
{
|
||||
Id = 5,
|
||||
Detail = new ActivityDetail()
|
||||
}, DeadActivityReason.Other, "Test"));
|
||||
|
||||
var result = await _controller.Get(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
|
||||
|
||||
var value = okResult.Value as DeadActivity;
|
||||
Assert.NotNull(value);
|
||||
Assert.AreEqual("Test", value.ReasonNote);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Single_NotFound()
|
||||
{
|
||||
_mockDeadActivityService.Setup(x => x.GetDeadActivity(It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Not Found"));
|
||||
|
||||
var result = await _controller.Get(1);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badRequestResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(badRequestResult);
|
||||
Assert.AreEqual(400, badRequestResult.StatusCode);
|
||||
Assert.AreEqual("DeadActivity Not Found.", badRequestResult.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+254
@@ -0,0 +1,254 @@
|
||||
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.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class DepartmentControllerTest
|
||||
{
|
||||
private DepartmentController _controller;
|
||||
private IDepartmentService _mockDepartmentService;
|
||||
private IUserService _userService;
|
||||
private ICurrentUserService _currentUser;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockDepartmentService = Mock.Of<IDepartmentService>();
|
||||
_userService = Mock.Of<IUserService>();
|
||||
_currentUser = Mock.Of<ICurrentUserService>();
|
||||
_controller = new DepartmentController(_mockDepartmentService, _userService, _currentUser);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAll_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetAllDepartmentsAsync()).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 0
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetDepartments(null,null);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetAll_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetAllDepartmentsAsync())
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartments(null, null);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentByIdAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new Department() { Id = 5 });
|
||||
|
||||
var result = await _controller.GetDepartmentById(0);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_NotFound()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentByIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentById(5);
|
||||
;
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as NotFoundObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(404, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetById_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentByIdAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentById(5);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateDepartment_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.SaveDepartmentAsync(It.IsAny<Department>()))
|
||||
.ReturnsAsync(new Department() {Id = 5});
|
||||
|
||||
var result = await _controller.CreateDepartment(new Department() {DepartmentName = "Test"});
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateDepartment_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.SaveDepartmentAsync(It.IsAny<Department>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.CreateDepartment(new Department() {DepartmentName = "Test"});
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CreateDepartment_DuplicateName()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.SaveDepartmentAsync(It.IsAny<Department>()))
|
||||
.ThrowsAsync(new DuplicateDataException("Oops"));
|
||||
|
||||
var result = await _controller.CreateDepartment(new Department() {DepartmentName = "Test"});
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(400, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ReturnsAsync(new Department() {Id = 5});
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_NotFound()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Oops"));
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as NotFoundObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(404, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateDepartment_DuplicateName()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.UpdateDepartmentAsync(It.IsAny<Department>(), It.IsAny<int>()))
|
||||
.ThrowsAsync(new DuplicateDataException("Oops"));
|
||||
|
||||
var result = await _controller.UpdateDepartment(new Department() {DepartmentName = "Test"}, 3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(400, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetails_OK()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentDetailsAsync(It.IsAny<int>()))
|
||||
.ReturnsAsync(new DepartmentDetails {
|
||||
Department = new Department { Id = 3 },
|
||||
Assignments = new List<UserDepartment> { new UserDepartment(), new UserDepartment() },
|
||||
RegionalManager = new AppUser { EmployeeId = "C0000" }
|
||||
});
|
||||
|
||||
var result = await _controller.GetDepartmentDetails(3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetails_Exception()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentDetailsAsync( It.IsAny<int>()))
|
||||
.ThrowsAsync(new Exception("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentDetails(3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetDepartmentDetails_NotFound()
|
||||
{
|
||||
Mock.Get(_mockDepartmentService).Setup(service => service.GetDepartmentDetailsAsync(It.IsAny<int>()))
|
||||
.ThrowsAsync(new NotFoundException("Oops"));
|
||||
|
||||
var result = await _controller.GetDepartmentDetails(3);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as NotFoundObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(404, statusRes.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+703
@@ -0,0 +1,703 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
||||
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.IncentiveApi.Services.Dayforce;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Models.DataTransfer;
|
||||
using LCU.API.Internal.Operations.IncentiveApi.Exceptions;
|
||||
using LCU.Library.Internal.IncentiveApiModels.Requests;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class EmployeeControllerTest
|
||||
{
|
||||
private EmployeeController _controller;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
private Mock<IDayForceSyncService> _mockDayForceService;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockDayForceService = new Mock<IDayForceSyncService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_controller = new EmployeeController(
|
||||
_mockCurrentUserService.Object,
|
||||
_mockDayForceService.Object,
|
||||
_mockUserService.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.GetAllUsersAsync(null))
|
||||
.ReturnsAsync(
|
||||
new List<AppUser>()
|
||||
{
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 456,
|
||||
EmployeeId = "DEF",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.Admin,
|
||||
HomeDepartment = "Branch-44"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 789,
|
||||
EmployeeId = "CONTRACTOR1",
|
||||
BaseRole = "QA",
|
||||
Role = Role.Teller,
|
||||
HomeDepartment = "Branch-44"
|
||||
},
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 900,
|
||||
EmployeeId = "CONTRACTOR2",
|
||||
BaseRole = "QA",
|
||||
Role = Role.BM,
|
||||
HomeDepartment = "Branch-0"
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.GetAllUsers(null, null);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Resolve_ok()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.FindUserAsync("123", null))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.ResolveUser("123");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Resolve_BadRequest()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.FindUserAsync("11771", null))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.ResolveUser("11771", "[email protected]");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as BadRequestObjectResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(400, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Resolve_Throws()
|
||||
{
|
||||
_mockUserService
|
||||
.Setup(service => service.FindUserAsync("123", null))
|
||||
.Throws<Exception>();
|
||||
|
||||
var result = await _controller.ResolveUser("123");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var statusRes = result as StatusCodeResult;
|
||||
Assert.NotNull(statusRes);
|
||||
Assert.AreEqual(500, statusRes.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Self_ok()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.GetCurrentEmployee();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Self_Unknown()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
(AppUser)null
|
||||
);
|
||||
|
||||
var result = await _controller.GetCurrentEmployee();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as NoContentResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(204, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_Ok()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
|
||||
var department = new Department()
|
||||
{
|
||||
Id = 555,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test Dept",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
};
|
||||
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
|
||||
var userDepartments = new List<UserDepartment>
|
||||
{
|
||||
new UserDepartment()
|
||||
{
|
||||
Employee = employee,
|
||||
Note = "Test Assignment",
|
||||
Department = department,
|
||||
StartDate = DateTime.Today,
|
||||
IsHome = false
|
||||
}
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service => service.AssignDepartments(employee.EmployeeId, It.IsAny<DepartmentAssignmentRequest>()))
|
||||
.ReturnsAsync(
|
||||
userDepartments
|
||||
);
|
||||
|
||||
var result = await _controller.AssignDepartment(employee.EmployeeId, assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_BadRequest()
|
||||
{
|
||||
var department = new Department()
|
||||
{
|
||||
Id = 555,
|
||||
State = DepartmentState.Active,
|
||||
DepartmentName = "Test Dept",
|
||||
BusinessLineCode = BusinessLine.Operations.Code
|
||||
};
|
||||
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service => service.AssignDepartments(employee.EmployeeId, It.IsAny<DepartmentAssignmentRequest>()))
|
||||
.ThrowsAsync(new BadDepartmentAssignmentException("test"));
|
||||
|
||||
var result = await _controller.AssignDepartment(employee.EmployeeId, assignment);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(400, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_ADUserNotFound()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
_mockCurrentUserService
|
||||
.Setup(service => service.GetCurrentUser())
|
||||
.Returns<ApplicationUser>(null);
|
||||
|
||||
var result = await _controller.AssignDepartment("C1", assignment);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignment_ForbiddenSelfAssign()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "999",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.AssignDepartment("999", assignment);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var forbiddennResult = result as ObjectResult;
|
||||
Assert.NotNull(forbiddennResult);
|
||||
Assert.AreEqual(403, forbiddennResult.StatusCode);
|
||||
Assert.AreEqual("Not allowed to assign yourself to a department.", forbiddennResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentUpdate_Ok()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = 555,
|
||||
Employee = employee,
|
||||
IsHome = false,
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
var request = new DepartmentUpdateRequest()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
AssignmentId = 5,
|
||||
SlidingPayout = 100,
|
||||
Role = "Teller"
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service =>
|
||||
service.UpdateDepartmentAssignment(request))
|
||||
.ReturnsAsync(
|
||||
assignment
|
||||
);
|
||||
|
||||
var result =
|
||||
await _controller.UpdateDepartmentAssignment(assignment.Employee.EmployeeId, assignment.DepartmentId, request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentTerm_BadRequest()
|
||||
{
|
||||
var employee = new AppUser()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
};
|
||||
var assignment = new UserDepartment()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = 555,
|
||||
Employee = employee,
|
||||
IsHome = false,
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
var request = new DepartmentUpdateRequest()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
AssignmentId = 5,
|
||||
SlidingPayout = 999,
|
||||
Role = "Teller"
|
||||
};
|
||||
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "1",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service =>
|
||||
service.UpdateDepartmentAssignment(request))
|
||||
.ThrowsAsync(new BadDepartmentAssignmentException("test"));
|
||||
|
||||
var result =
|
||||
await _controller.UpdateDepartmentAssignment(assignment.Employee.EmployeeId, assignment.DepartmentId, request);
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as BadRequestObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(400, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentTerm_ADUserNotFound()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
_mockCurrentUserService
|
||||
.Setup(service => service.GetCurrentUser())
|
||||
.Returns<ApplicationUser>(null);
|
||||
|
||||
var result = await _controller.UpdateDepartmentAssignment("C1", 1, null);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var unauthorizedResult = result as UnauthorizedObjectResult;
|
||||
Assert.NotNull(unauthorizedResult);
|
||||
Assert.AreEqual(401, unauthorizedResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Post_DepartmentAssignmentTerm_ForbiddenSelfTerm()
|
||||
{
|
||||
var assignment = new DepartmentAssignmentRequest()
|
||||
{
|
||||
Note = "Test Assignment",
|
||||
DepartmentId = new int [555],
|
||||
StartDate = DateTime.Today
|
||||
};
|
||||
var request = new DepartmentUpdateRequest()
|
||||
{
|
||||
EmployeeId = "11771",
|
||||
AssignmentId = 5,
|
||||
SlidingPayout = 999,
|
||||
Role = "Teller"
|
||||
};
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByAdEmailAsync("[email protected]"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
EmployeeId = "999",
|
||||
PersonId = 0,
|
||||
AdEmail = "[email protected]"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.UpdateDepartmentAssignment("999", 1, request);
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
var forbiddennResult = result as ObjectResult;
|
||||
Assert.NotNull(forbiddennResult);
|
||||
Assert.AreEqual(403, forbiddennResult.StatusCode);
|
||||
Assert.AreEqual("Not allowed to terminate yourself from a department.", forbiddennResult.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_By_Id_ok()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("ABC"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.GetEmployeeById("ABC");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_By_Id_Unknown()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]",
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("DEF"))
|
||||
.ReturnsAsync(
|
||||
(AppUser)null
|
||||
);
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("ABC"))
|
||||
.ReturnsAsync(
|
||||
new AppUser()
|
||||
{
|
||||
AdEmail = "[email protected]",
|
||||
PersonId = 123,
|
||||
EmployeeId = "ABC",
|
||||
BaseRole = "Developer",
|
||||
Role = Role.UNKNOWN_ROLE,
|
||||
HomeDepartment = "Branch-44"
|
||||
}
|
||||
);
|
||||
|
||||
var result = await _controller.GetEmployeeById("DEF");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as NoContentResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(204, okResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_Employee_By_Id_Throw()
|
||||
{
|
||||
_mockCurrentUserService.Setup(service => service.GetCurrentUser())
|
||||
.Returns(
|
||||
new ApplicationUser()
|
||||
{
|
||||
FirstName = "Test",
|
||||
LastName = "McGee",
|
||||
Roles = new[] { "QA" },
|
||||
Email = "[email protected]"
|
||||
});
|
||||
_mockUserService
|
||||
.Setup(service => service.GetUserByEmployeeIdAsync("DEF"))
|
||||
.Throws<Exception>();
|
||||
|
||||
var result = await _controller.GetEmployeeById("DEF");
|
||||
Assert.NotNull(result);
|
||||
|
||||
var badResult = result as StatusCodeResult;
|
||||
Assert.NotNull(badResult);
|
||||
Assert.AreEqual(500, badResult.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SyncDayForce_ForceRefresh()
|
||||
{
|
||||
_mockDayForceService.Setup(service => service.SyncDayForceUsers(new DayforceProcessRequest()));
|
||||
|
||||
var result = await _controller.SyncDayForce();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var successResult = result as StatusCodeResult;
|
||||
Assert.NotNull(successResult);
|
||||
Assert.AreEqual(200, successResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
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.Persistence;
|
||||
using LCU.API.Internal.Operations.IncentiveApiLib.Services;
|
||||
|
||||
namespace Application.UnitTests.Controllers
|
||||
{
|
||||
public class SettingsControllerTest
|
||||
{
|
||||
private SettingsController _controller;
|
||||
private Mock<ICurrentUserService> _mockCurrentUserService;
|
||||
private Mock<IDepartmentService> _mockDepartmentService;
|
||||
private Mock<ISettingsService> _mockSettingsService;
|
||||
private Mock<IUserService> _mockUserService;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_mockCurrentUserService = new Mock<ICurrentUserService>();
|
||||
_mockDepartmentService = new Mock<IDepartmentService>();
|
||||
_mockSettingsService = new Mock<ISettingsService>();
|
||||
_mockUserService = new Mock<IUserService>();
|
||||
_controller = new SettingsController(
|
||||
_mockCurrentUserService.Object,
|
||||
new DateTimeService(),
|
||||
_mockDepartmentService.Object,
|
||||
_mockSettingsService.Object,
|
||||
_mockUserService.Object
|
||||
);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Get_OK()
|
||||
{
|
||||
_mockDepartmentService.Setup(service => service.GetAllDepartmentsAsync()).ReturnsAsync(
|
||||
new List<Department>()
|
||||
{
|
||||
new Department()
|
||||
{
|
||||
Id = 0
|
||||
}
|
||||
});
|
||||
|
||||
_mockUserService.Setup(service => service.GetAllUserSummariesAsync()).ReturnsAsync(
|
||||
new List<UserSummary>()
|
||||
{
|
||||
new UserSummary()
|
||||
{
|
||||
}
|
||||
});
|
||||
|
||||
var result = await _controller.Get();
|
||||
Assert.NotNull(result);
|
||||
|
||||
var okResult = result as OkObjectResult;
|
||||
Assert.NotNull(okResult);
|
||||
Assert.AreEqual(200, okResult.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user