using System; using LCU.Library.Internal.IncentiveApiModels.Entities; using LCU.Library.Internal.IncentiveApiModels.Enums; using NUnit.Framework; namespace Application.UnitTests.Entities { public class UserDepartmentTest { private readonly AppUser _employee = new AppUser() { EmployeeId = "5", PersonId = 0, AdEmail = "nobody@nowhere.com" }; [Test] public void NonConflictingAssignment_Diff_Dept() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Today, EndDate = null }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 6, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Today, EndDate = null }; Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); Assert.AreEqual(string.Empty, message); } [Test] public void NonConflictingAssignment_Diff_User() { var employee2 = new AppUser() { EmployeeId = "6", PersonId = 0, AdEmail = "nobody2@nowhere.com" }; var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Today, EndDate = null }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = employee2, StartDate = DateTime.Today, EndDate = null }; Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); Assert.AreEqual(string.Empty, message); } [Test] public void ConflictingAssignment_Case_Null_Null() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Today, EndDate = null }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Today, EndDate = null }; Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void ConflictingAssignment_Case_Null_Valid() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Parse("2021-01-01T00:00:00.000Z").ToUniversalTime(), EndDate = null }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-07-31T23:59:00.000Z").ToUniversalTime() }; Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void ConflictingAssignment_Case_Valid_Null_Before() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(1) }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Today.AddDays(1), EndDate = null }; Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void NonConflictingAssignment_Case_Valid_Null_After() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(1) }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Today.AddDays(2), EndDate = null }; Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void NonConflictingAssignment_Case_Valid_Valid_After() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-07-31T23:59:00.000Z").ToUniversalTime() }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Parse("2021-08-01T00:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-08-31T23:59:00.000Z").ToUniversalTime() }; Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void NonConflictingAssignment_Case_Valid_Valid_Before() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-07-31T23:59:00.000Z").ToUniversalTime() }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Parse("2021-06-01T00:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-06-30T23:59:00.000Z").ToUniversalTime() }; Assert.False(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void ConflictingAssignment_Case_Valid_Valid_Overlap() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(5) }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Today.AddDays(2), EndDate = DateTime.Today.AddDays(10) }; Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } [Test] public void ConflictingAssignment_Case_Overlap_IgnoreTimestamp() { var existingAssignment = new UserDepartment() { DepartmentId = 5, Employee = _employee, StartDate = DateTime.Parse("2021-07-01T00:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-07-05T12:00:00.000Z").ToUniversalTime() }; var newAssignment = new UserDepartment() { // DepartmentID will be NULL. Department = new Department() { Id = 5, State = DepartmentState.Active, DepartmentName = "Test", BusinessLineCode = BusinessLine.Operations.Code }, Employee = _employee, StartDate = DateTime.Parse("2021-07-05T15:00:00.000Z").ToUniversalTime(), EndDate = DateTime.Parse("2021-07-08T00:00:00.000Z").ToUniversalTime() }; Assert.True(existingAssignment.IsConflictingAssignment(newAssignment, out string message)); } } }