Added training reminder worker
This commit is contained in:
@ -29,7 +29,7 @@ internal class ECNServiceTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiringTECNsWithDbErrorShouldThrowException() {
|
||||
public void GetExpiringTECNsWithDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).ThrowsAsync(new Exception());
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
@ -38,7 +38,7 @@ internal class ECNServiceTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetExpiredTECNsWithDbErrorShouldThrowException() {
|
||||
public void GetExpiredTECNsWithDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).ThrowsAsync(new Exception());
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
@ -215,7 +215,7 @@ internal class ECNServiceTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetTECNNotificationUserEmailsDbErrorShouldThrowException() {
|
||||
public void GetTECNNotificationUserEmailsDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<string>(It.IsAny<string>())).Throws(new Exception());
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
@ -238,4 +238,52 @@ internal class ECNServiceTests {
|
||||
|
||||
Assert.That(actualEmails.Count(), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEcnByNumberWithInvalidNumberShouldThrowException() {
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<ArgumentException>(async Task () => await _ecnService.GetEcnByNumber(0));
|
||||
|
||||
Assert.ThrowsAsync<ArgumentException>(async Task () => await _ecnService.GetEcnByNumber(-4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEcnByNumberDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Throws(new Exception());
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task () => await _ecnService.GetEcnByNumber(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetEcnByNumberEcnNotFoundShouldThrowException() {
|
||||
IEnumerable<ECN> expectedEcns = new List<ECN>();
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(expectedEcns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task () => await _ecnService.GetEcnByNumber(8));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetEcnByNumberShouldReturnExpectedEcn() {
|
||||
IEnumerable<ECN> expectedEcns = new List<ECN>() {
|
||||
new ECN() {
|
||||
ECNNumber = 1,
|
||||
OriginatorID = 1,
|
||||
Title = "title"
|
||||
}
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<ECN>(It.IsAny<string>())).Returns(Task.FromResult(expectedEcns));
|
||||
|
||||
_ecnService = new ECNService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
ECN actualEcn = await _ecnService.GetEcnByNumber(9);
|
||||
|
||||
Assert.That(expectedEcns.First(), Is.EqualTo(actualEcn));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FabApprovalWorkerService.Services;
|
||||
using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Services;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@ -26,6 +27,8 @@ public class TrainingServiceTests {
|
||||
public void TrainingServiceWithNullDalServiceShouldThrowException() {
|
||||
Assert.Throws<ArgumentNullException>(() => new TrainingService(_mockLogger.Object, null));
|
||||
}
|
||||
<<<<<<< Updated upstream
|
||||
=======
|
||||
|
||||
[Test]
|
||||
public void DeleteDocAssignmentWithInvalidIdShouldThrowException() {
|
||||
@ -169,4 +172,71 @@ public class TrainingServiceTests {
|
||||
|
||||
_mockDalService.Verify(d => d.ExecuteAsync(It.IsAny<string>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActiveTrainingAssignmentsShouldReturnExpectedAssignments() {
|
||||
IEnumerable<TrainingAssignment> expectedAssignments = new List<TrainingAssignment>() {
|
||||
new TrainingAssignment() {
|
||||
ID = 1,
|
||||
TrainingID = 1,
|
||||
UserID = 1,
|
||||
DateAssigned = DateTime.Now
|
||||
},
|
||||
new TrainingAssignment() {
|
||||
ID = 2,
|
||||
TrainingID = 1,
|
||||
UserID = 2,
|
||||
DateAssigned = DateTime.Now
|
||||
},
|
||||
new TrainingAssignment() {
|
||||
ID = 3,
|
||||
TrainingID = 1,
|
||||
UserID = 3,
|
||||
DateAssigned = DateTime.Now
|
||||
}
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<TrainingAssignment>(It.IsAny<string>())).Returns(Task.FromResult(expectedAssignments));
|
||||
|
||||
_trainingService = new TrainingService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
IEnumerable<TrainingAssignment> actualAssignments = await _trainingService.GetActiveTrainingAssignments();
|
||||
|
||||
Assert.That(actualAssignments.Count() == expectedAssignments.Count());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetActiveTrainingAssignmentsWithDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<TrainingAssignment>(It.IsAny<string>())).Throws(new Exception());
|
||||
|
||||
_trainingService = new TrainingService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task() => await _trainingService.GetActiveTrainingAssignments());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateTrainingAssignmentLastNotificationWithInvalidIdShouldThrowException() {
|
||||
_trainingService = new TrainingService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<ArgumentException>(async Task () => await _trainingService.UpdateTrainingAssignmentLastNotification(-1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateTrainingAssignmentLastNotificationDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.ExecuteAsync(It.IsAny<string>())).Throws(new Exception());
|
||||
|
||||
_trainingService = new TrainingService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task () => await _trainingService.UpdateTrainingAssignmentLastNotification(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateTrainingAssignmentLastNotificationShouldExecuteSql() {
|
||||
_trainingService = new TrainingService(_mockLogger.Object, _mockDalService.Object);
|
||||
|
||||
await _trainingService.UpdateTrainingAssignmentLastNotification(1);
|
||||
|
||||
_mockDalService.Verify(d => d.ExecuteAsync(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
>>>>>>> Stashed changes
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ using FabApprovalWorkerService.Models;
|
||||
using FabApprovalWorkerService.Services;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Identity.Client;
|
||||
|
||||
using Moq;
|
||||
|
||||
@ -458,4 +459,56 @@ internal class UserServiceTests {
|
||||
|
||||
Assert.That(actualEmail, Is.EqualTo(emailsFromDb.First()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUserByIdWithInvalidIdShouldThrowException() {
|
||||
_userService = new UserService(MOCK_LOGGER, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<ArgumentException>(async Task () => await _userService.GetUserById(-4));
|
||||
|
||||
Assert.ThrowsAsync<ArgumentException>(async Task () => await _userService.GetUserById(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUserByIdDbErrorShouldThrowException() {
|
||||
_mockDalService.Setup(d => d.QueryAsync<User>(It.IsAny<string>())).Throws(new Exception());
|
||||
|
||||
_userService = new UserService(MOCK_LOGGER, _mockDalService.Object);
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task () => await _userService.GetUserById(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetUserByIdNoUserFoundShouldThrowException() {
|
||||
IEnumerable<User> emptyUsers = new List<User>();
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<User>(It.IsAny<string>())).Returns(Task.FromResult(emptyUsers));
|
||||
|
||||
Assert.ThrowsAsync<Exception>(async Task() => await _userService.GetUserById(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetUserByIdShouldReturnExpectedUser() {
|
||||
IEnumerable<User> expectedUsers = new List<User>() {
|
||||
new User() {
|
||||
UserID = 1,
|
||||
LoginID = "id",
|
||||
FirstName = "firstName",
|
||||
LastName = "lastName",
|
||||
Email = "email",
|
||||
IsAdmin = false,
|
||||
OOO = false,
|
||||
CanViewITAR = true,
|
||||
IsManager = false
|
||||
}
|
||||
};
|
||||
|
||||
_mockDalService.Setup(d => d.QueryAsync<User>(It.IsAny<string>())).Returns(Task.FromResult(expectedUsers));
|
||||
|
||||
_userService = new UserService(MOCK_LOGGER, _mockDalService.Object);
|
||||
|
||||
User actualUser = await _userService.GetUserById(4);
|
||||
|
||||
Assert.That(expectedUsers.First(), Is.EqualTo(actualUser));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user