266 lines
10 KiB
C#
266 lines
10 KiB
C#
using LCU.API.Internal.Operations.IncentiveApi.Services;
|
|
using LCU.Library.Internal.IncentiveApiModels.Entities;
|
|
using LCU.Library.Internal.IncentiveApiModels.Enums;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
|
|
using LCU.API.Internal.Operations.IncentiveApiLib;
|
|
|
|
namespace Application.UnitTests.Repository
|
|
{
|
|
public class ActivityTransferActionRepositoryTest
|
|
{
|
|
private ApplicationDbContext _context;
|
|
private ActivityTransferActionRepository _repository;
|
|
private Mock<IDateTime> _mockDateTime;
|
|
|
|
[SetUp]
|
|
public void Setup()
|
|
{
|
|
_mockDateTime = new Mock<IDateTime>();
|
|
var mockCurrentUserService = Mock.Of<ICurrentUserService>();
|
|
Mock.Get(mockCurrentUserService).Setup(s => s.GetCurrentUser()).Returns(new ApplicationUser()
|
|
{
|
|
Email = "[email protected]",
|
|
});
|
|
var options = new DbContextOptionsBuilder<ApplicationDbContext>()
|
|
.UseInMemoryDatabase(Guid.NewGuid().ToString())
|
|
.EnableSensitiveDataLogging(true)
|
|
.Options;
|
|
_context = new ApplicationDbContext(options, mockCurrentUserService, _mockDateTime.Object);
|
|
_repository = new ActivityTransferActionRepository(_context);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SaveTransferAsync_Basic()
|
|
{
|
|
_mockDateTime.SetupGet(mock => mock.Now).Returns(new DateTime(2021, 9, 10, 1, 2, 3, 456));
|
|
|
|
var activityToTransfer = new Activity()
|
|
{
|
|
Id = 2,
|
|
EmployeeId = "C0000",
|
|
DepartmentId = 5,
|
|
Product = Product.CheckCard,
|
|
SourceId = "2",
|
|
State = ActivityState.Accepted,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
MemberName = "Tester 1",
|
|
AgreementNumber = "234"
|
|
}
|
|
};
|
|
_context.Add(activityToTransfer);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var activtyTransferAction = new ActivityTransferAction
|
|
{
|
|
Id = 0,
|
|
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
|
RequestedActivityId = 2,
|
|
State = ActivityTransferState.Requested,
|
|
NewActivityDepartmentId = 3,
|
|
NewActivityEmployeeId = "C0000"
|
|
};
|
|
|
|
var savedId = await _repository.SaveTransferAsync(activtyTransferAction);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var found = await _context.ActivityTransferActions.FindAsync(savedId);
|
|
|
|
Assert.NotNull(found);
|
|
Assert.AreEqual(ActivityState.Accepted, found.ActivityStateBeforeTransfer);
|
|
Assert.AreEqual(2, found.RequestedActivityId);
|
|
Assert.AreEqual(ActivityTransferState.Requested, found.State);
|
|
Assert.AreEqual(3, found.NewActivityDepartmentId);
|
|
Assert.IsNull(found.NewActivityId);
|
|
Assert.AreEqual("C0000", found.NewActivityEmployeeId);
|
|
Assert.AreEqual(new DateTime(2021, 9, 10, 1, 2, 3, 456), found.Created);
|
|
Assert.AreEqual("[email protected]", found.CreatedBy);
|
|
Assert.AreEqual(UserType.Associate, found.CreatedByType);
|
|
Assert.AreEqual(new DateTime(2021, 9, 10, 1, 2, 3, 456), found.LastUpdated);
|
|
Assert.AreEqual("[email protected]", found.LastUpdatedBy);
|
|
Assert.AreEqual(UserType.Associate, found.LastUpdatedByType);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetTransferActionById_Basic()
|
|
{
|
|
var activityToTransfer = new Activity()
|
|
{
|
|
Id = 2,
|
|
EmployeeId = "C0000",
|
|
DepartmentId = 5,
|
|
Product = Product.CheckCard,
|
|
SourceId = "2",
|
|
State = ActivityState.Accepted,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
MemberName = "Tester 1",
|
|
AgreementNumber = "234"
|
|
}
|
|
};
|
|
_context.Add(activityToTransfer);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var activtyTransferAction1 = new ActivityTransferAction
|
|
{
|
|
Id = 1,
|
|
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
|
RequestedActivityId = 2,
|
|
State = ActivityTransferState.Accepted,
|
|
NewActivityDepartmentId = 3,
|
|
NewActivityEmployeeId = "C0001"
|
|
};
|
|
|
|
var activtyTransferAction2 = new ActivityTransferAction
|
|
{
|
|
Id = 2,
|
|
ActivityStateBeforeTransfer = ActivityState.Rejected,
|
|
RequestedActivityId = 2,
|
|
State = ActivityTransferState.Requested,
|
|
NewActivityDepartmentId = 4,
|
|
NewActivityEmployeeId = "C0002"
|
|
};
|
|
_context.Add(activtyTransferAction1);
|
|
_context.Add(activtyTransferAction2);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var found = await _repository.GetTransferActionById(2);
|
|
|
|
Assert.AreEqual(2, found.Id);
|
|
Assert.AreEqual(ActivityState.Rejected, found.ActivityStateBeforeTransfer);
|
|
Assert.AreEqual(2, found.RequestedActivityId);
|
|
Assert.AreEqual(ActivityTransferState.Requested, found.State);
|
|
Assert.AreEqual(4, found.NewActivityDepartmentId);
|
|
Assert.AreEqual("C0002", found.NewActivityEmployeeId);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetRequestedTransferActionByActivityId_Basic()
|
|
{
|
|
var activityToTransfer = new Activity()
|
|
{
|
|
Id = 2,
|
|
EmployeeId = "C0000",
|
|
DepartmentId = 5,
|
|
Product = Product.CheckCard,
|
|
SourceId = "2",
|
|
State = ActivityState.Accepted,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
MemberName = "Tester 1",
|
|
AgreementNumber = "234"
|
|
}
|
|
};
|
|
_context.Add(activityToTransfer);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var activtyTransferAction1 = new ActivityTransferAction
|
|
{
|
|
Id = 1,
|
|
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
|
RequestedActivityId = 2,
|
|
State = ActivityTransferState.Accepted,
|
|
NewActivityDepartmentId = 3,
|
|
NewActivityEmployeeId = "C0001"
|
|
};
|
|
|
|
var activtyTransferAction2 = new ActivityTransferAction
|
|
{
|
|
Id = 2,
|
|
ActivityStateBeforeTransfer = ActivityState.Rejected,
|
|
RequestedActivityId = 2,
|
|
State = ActivityTransferState.Requested,
|
|
NewActivityDepartmentId = 4,
|
|
NewActivityEmployeeId = "C0002"
|
|
};
|
|
_context.Add(activtyTransferAction1);
|
|
_context.Add(activtyTransferAction2);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var found = await _repository.GetRequestedTransferActionByActivityId(2);
|
|
|
|
Assert.AreEqual(2, found.Id);
|
|
Assert.AreEqual(ActivityState.Rejected, found.ActivityStateBeforeTransfer);
|
|
Assert.AreEqual(2, found.RequestedActivityId);
|
|
Assert.AreEqual(ActivityTransferState.Requested, found.State);
|
|
Assert.AreEqual(4, found.NewActivityDepartmentId);
|
|
Assert.AreEqual("C0002", found.NewActivityEmployeeId);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetActiveTransfersByState_Basic()
|
|
{
|
|
var activityToTransfer = new Activity()
|
|
{
|
|
Id = 2,
|
|
EmployeeId = "C0000",
|
|
DepartmentId = 5,
|
|
Product = Product.CheckCard,
|
|
SourceId = "2",
|
|
State = ActivityState.Accepted,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
MemberName = "Tester 1",
|
|
AgreementNumber = "234"
|
|
}
|
|
};
|
|
_context.Add(activityToTransfer);
|
|
var activityToTransfer2 = new Activity()
|
|
{
|
|
Id = 3,
|
|
EmployeeId = "C0000",
|
|
DepartmentId = 5,
|
|
Product = Product.CheckCard,
|
|
SourceId = "3",
|
|
State = ActivityState.PendingReferral,
|
|
Detail = new ActivityDetail()
|
|
{
|
|
MemberName = "Tester 1",
|
|
AgreementNumber = "234"
|
|
}
|
|
};
|
|
_context.Add(activityToTransfer);
|
|
_context.Add(activityToTransfer2);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var activityTransferAction1 = new ActivityTransferAction
|
|
{
|
|
Id = 1,
|
|
ActivityStateBeforeTransfer = ActivityState.Accepted,
|
|
RequestedActivityId = 2,
|
|
State = ActivityTransferState.Requested,
|
|
NewActivityDepartmentId = 3,
|
|
NewActivityEmployeeId = "C0001",
|
|
RequestedActivity = activityToTransfer
|
|
};
|
|
|
|
var activityTransferAction2 = new ActivityTransferAction
|
|
{
|
|
Id = 2,
|
|
ActivityStateBeforeTransfer = ActivityState.PendingReferral,
|
|
RequestedActivityId = 3,
|
|
State = ActivityTransferState.Requested,
|
|
NewActivityDepartmentId = 4,
|
|
NewActivityEmployeeId = "C0002",
|
|
RequestedActivity = activityToTransfer2
|
|
};
|
|
_context.Add(activityTransferAction1);
|
|
_context.Add(activityTransferAction2);
|
|
await _context.SaveChangesAsync();
|
|
|
|
var found = await _repository.GetActiveTransfersForStateAsync(ActivityState.Accepted);
|
|
|
|
Assert.AreEqual(1, found.Count());
|
|
Assert.AreEqual(1, found.First().Id);
|
|
Assert.AreEqual(ActivityState.Accepted, found.First().ActivityStateBeforeTransfer);
|
|
}
|
|
}
|
|
}
|