using Moq; using NUnit.Framework; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using LCU.API.Internal.DocumentIngestor.Services; using LCU.API.Internal.DocumentIngestor.Configurations; using LCU.API.Internal.DocumentIngestorLib.Repositories; using LCU.Library.Internal.DocumentIngestorModels.Entities; using LCU.Library.Internal.DocumentIngestorModels.Enums; using LCU.Library.Internal.DocumentIngestorModels.Models; using LCU.Library.Internal.DocumentIngestorModels.Models.Pagination; using LCU.Library.Internal.Exceptions; namespace LCU.API.Internal.DocumentIngestorTests.Services; public class MemberNotificationInfoServiceTest { private MemberNotificationInfoService _memberNotificationInfoService; private Mock _unitOfWork; private ApiConfiguration _apiConfiguration; private Mock _mockMemberNotificationInfoRepository; private Mock _mockProcessingLogService; [SetUp] public void Setup() { _unitOfWork = new Mock(); _apiConfiguration = new ApiConfiguration { BatchSkipAmount = 10000 }; _mockMemberNotificationInfoRepository = new Mock(); _mockProcessingLogService = new Mock(); _memberNotificationInfoService = new MemberNotificationInfoService ( _unitOfWork.Object, _apiConfiguration, _mockMemberNotificationInfoRepository.Object, _mockProcessingLogService.Object ); } [Test] public async Task GetAsync_MemberNotificationInfos_Returned() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var documentProcessingInfos = new List() { new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") } }; _mockMemberNotificationInfoRepository.Setup(x => x.FindAsync()).ReturnsAsync(documentProcessingInfos); var result = await _memberNotificationInfoService.GetAsync(); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); _mockMemberNotificationInfoRepository.Verify(x => x.FindAsync(), Times.Once); } [Test] public void GetAsync_Exception() { _mockMemberNotificationInfoRepository.Setup(x => x.FindAsync()).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.GetAsync()); _mockMemberNotificationInfoRepository.Verify(x => x.FindAsync(), Times.Once); } [Test] public async Task GetByIdAsync_MemberNotificationInfo_Returned() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ReturnsAsync(memberNotificationInfo); var result = await _memberNotificationInfoService.GetByIdAsync(memberNotificationInfoId); Assert.IsNotNull(result); Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId); Assert.AreEqual(memberNotificationInfoId, result.MemberNotificationInfoId); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); } [Test] public void GetByIdAsync_Exception() { var id = 1; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.GetByIdAsync(id)); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); } [Test] public async Task GetByDocumentProcessingInfoIdAsync_MemberNotificationInfos_Returned() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var documentProcessingInfos = new List() { new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") } }; _mockMemberNotificationInfoRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ReturnsAsync(documentProcessingInfos); var result = await _memberNotificationInfoService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId); Assert.IsNotNull(result); Assert.AreEqual(1, result.Count()); _mockMemberNotificationInfoRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny()), Times.Once); } [Test] public void GetByDocumentProcessingInfoIdAsync_Exception() { var documentProcessingInfoId = 1; _mockMemberNotificationInfoRepository.Setup(x => x.FindByDocumentProcessingInfoIdAsync(documentProcessingInfoId)).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.GetByDocumentProcessingInfoIdAsync(documentProcessingInfoId)); _mockMemberNotificationInfoRepository.Verify(x => x.FindByDocumentProcessingInfoIdAsync(It.IsAny()), Times.Once); } [Test] public async Task SaveAsync_MemberNotificationInfo_Returned() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.AddAsync(memberNotificationInfo)).ReturnsAsync(memberNotificationInfo); var result = await _memberNotificationInfoService.SaveAsync(memberNotificationInfo); Assert.IsNotNull(result); Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId); Assert.AreEqual(memberNotificationInfoId, result.MemberNotificationInfoId); _mockMemberNotificationInfoRepository.Verify(x => x.AddAsync(It.IsAny()), Times.Once); } [Test] public void SaveAsync_Exception() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.AddAsync(memberNotificationInfo)).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.SaveAsync(memberNotificationInfo)); _mockMemberNotificationInfoRepository.Verify(x => x.AddAsync(It.IsAny()), Times.Once); } [Test] public async Task Update_MemberNotificationInfo_Returned() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.Update(memberNotificationInfo)); var result = await _memberNotificationInfoService.Update(memberNotificationInfo); Assert.IsNotNull(result); Assert.AreEqual(documentProcessingInfoId, result.DocumentProcessingInfoId); Assert.AreEqual(memberNotificationInfoId, result.MemberNotificationInfoId); _mockMemberNotificationInfoRepository.Verify(x => x.Update(It.IsAny()), Times.Once); } [Test] public void Update_FindByIdAsync_ThrowsException() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.GetByIdAsync(memberNotificationInfo.MemberNotificationInfoId)); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.Update(It.IsAny()), Times.Never); } [Test] public void Update_Update_ThrowsException() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.Update(memberNotificationInfo)).Throws(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.Update(memberNotificationInfo)); _mockMemberNotificationInfoRepository.Verify(x => x.Update(It.IsAny()), Times.Once); } [Test] public async Task UpdateRange_MemberNotificationInfo_Returned() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfos = new List() { new() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") } }; _mockMemberNotificationInfoRepository.Setup(x => x.UpdateRange(memberNotificationInfos)); var result = await _memberNotificationInfoService.UpdateRange(memberNotificationInfos); Assert.IsNotNull(result); Assert.AreEqual(documentProcessingInfoId, result.FirstOrDefault()?.DocumentProcessingInfoId); Assert.AreEqual(memberNotificationInfoId, result.FirstOrDefault()?.MemberNotificationInfoId); _mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny>()), Times.Once); } [Test] public void UpdateRange_FindByIdAsync_ThrowsException() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfos = new List() { new() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") } }; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.GetByIdAsync(memberNotificationInfoId)); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); } [Test] public void UpdateRange_Update_ThrowsException() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfos = new List() { new() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") } }; _mockMemberNotificationInfoRepository.Setup(x => x.UpdateRange(memberNotificationInfos)).Throws(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.UpdateRange(memberNotificationInfos)); _mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny>()), Times.Once); } [Test] public async Task Delete_Success() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ReturnsAsync(memberNotificationInfo); _mockMemberNotificationInfoRepository.Setup(x => x.Remove(memberNotificationInfo)); await _memberNotificationInfoService.Delete(memberNotificationInfoId); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.Remove(It.IsAny()), Times.Once); } [Test] public void Delete_FindByIdAsync_ThrowsException() { var id = 1; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(id)).ThrowsAsync(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.Delete(id)); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.Remove(It.IsAny()), Times.Never); } [Test] public void Delete_Remove_ThrowsException() { var memberNotificationInfoId = 10; var documentProcessingInfoId = 1; var memberNotificationInfo = new MemberNotificationInfo() { MemberNotificationInfoId = memberNotificationInfoId, DocumentProcessingInfoId = documentProcessingInfoId, UploadDate = Convert.ToDateTime("1/1/2022") }; _mockMemberNotificationInfoRepository.Setup(x => x.FindByIdAsync(memberNotificationInfoId)).ReturnsAsync(memberNotificationInfo); _mockMemberNotificationInfoRepository.Setup(x => x.Remove(memberNotificationInfo)).Throws(new Exception("Error")); Assert.ThrowsAsync(async () => await _memberNotificationInfoService.Delete(memberNotificationInfoId)); _mockMemberNotificationInfoRepository.Verify(x => x.FindByIdAsync(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.Remove(It.IsAny()), Times.Once); } [Test] public async Task SetDocumentNotificationStatus_NotificationInfoDoesntExist_ReturnsFalseAndDoesNotUpdateOrLog() { var memberNotificationInfo = new MemberNotificationInfo { MemberNotificationInfoId = DateTime.Now.Millisecond }; var notificationStatus = NotificationStatusTypes.CriticalFailure; var userName = Guid.NewGuid().ToString(); var reason = Guid.NewGuid().ToString(); _mockMemberNotificationInfoRepository .Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId)) .ReturnsAsync((MemberNotificationInfo)null); var updated = await _memberNotificationInfoService.SetDocumentNotificationStatus ( memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason ); Assert.IsFalse(updated); _mockMemberNotificationInfoRepository.Verify(r => r.Update(memberNotificationInfo), Times.Never); _mockProcessingLogService.Verify(s => s.SaveAsync(It.IsAny()), Times.Never); } [Test] public void SetDocumentNotificationStatus_FindingNotificationInfoThrows_ThrowsServiceException() { var memberNotificationInfo = new MemberNotificationInfo { MemberNotificationInfoId = DateTime.Now.Millisecond }; var notificationStatus = NotificationStatusTypes.CriticalFailure; var userName = Guid.NewGuid().ToString(); var reason = Guid.NewGuid().ToString(); _mockMemberNotificationInfoRepository .Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId)) .ThrowsAsync(new Exception()); var thrown = Assert.ThrowsAsync(() => _memberNotificationInfoService.SetDocumentNotificationStatus(memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason)); StringAssert.Contains(memberNotificationInfo.MemberNotificationInfoId.ToString(), thrown.Message); StringAssert.Contains(notificationStatus.ToString(), thrown.Message); } [Test] public async Task SetDocumentNotificationStatus_SetStatusThrows_ThrowsServiceExceptionAndDoesNotLog() { var notificationStatus = NotificationStatusTypes.CriticalFailure; var memberNotificationInfo = new MemberNotificationInfo { MemberNotificationInfoId = DateTime.Now.Millisecond, DocumentProcessingInfoId = DateTime.Now.Millisecond + 1, NotificationStatusType = notificationStatus + 1 }; var userName = Guid.NewGuid().ToString(); var reason = Guid.NewGuid().ToString(); var processingLogs = new List(); _mockMemberNotificationInfoRepository .Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId)) .ReturnsAsync(memberNotificationInfo); _mockMemberNotificationInfoRepository .Setup(r => r.Update(memberNotificationInfo)) .Throws(new Exception()); _mockProcessingLogService .Setup(s => s.SaveAsync(It.IsAny())) .Callback(processingLogs.Add); var thrown = Assert.ThrowsAsync(() => _memberNotificationInfoService.SetDocumentNotificationStatus(memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason)); StringAssert.Contains(memberNotificationInfo.MemberNotificationInfoId.ToString(), thrown.Message); StringAssert.Contains(notificationStatus.ToString(), thrown.Message); CollectionAssert.IsEmpty(processingLogs); } [Test] public async Task SetDocumentNotificationStatus_SetStatusSuccess_LogsChange() { var notificationStatus = NotificationStatusTypes.CriticalFailure; var originalNotificationStatus = notificationStatus + 1; var memberNotificationInfo = new MemberNotificationInfo { MemberNotificationInfoId = DateTime.Now.Millisecond, DocumentProcessingInfoId = DateTime.Now.Millisecond + 1, NotificationStatusType = originalNotificationStatus }; var userName = Guid.NewGuid().ToString(); var reason = Guid.NewGuid().ToString(); var processingLogs = new List(); _mockMemberNotificationInfoRepository .Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId)) .ReturnsAsync(memberNotificationInfo); _mockProcessingLogService .Setup(s => s.SaveAsync(It.IsAny())) .Callback(processingLogs.Add); var testStart = DateTime.UtcNow; await _memberNotificationInfoService.SetDocumentNotificationStatus ( memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason ); var testEnd = DateTime.UtcNow; Assert.AreEqual(1, processingLogs.Count); var log = processingLogs.Single(); Assert.AreEqual(memberNotificationInfo.DocumentProcessingInfoId, log.DocumentProcessingInfoId); Assert.That(log.LogTimeStamp, Is.InRange(testStart, testEnd)); StringAssert.Contains(originalNotificationStatus.ToString(), log.LogMessage); StringAssert.Contains(notificationStatus.ToString(), log.LogMessage); StringAssert.Contains(reason, log.LogMessage); } [Test] public async Task SetDocumentNotificationStatus_LoggingChangeThrows_ThrowsServiceException() { var notificationStatus = NotificationStatusTypes.CriticalFailure; var memberNotificationInfo = new MemberNotificationInfo { MemberNotificationInfoId = DateTime.Now.Millisecond, NotificationStatusType = notificationStatus + 1 }; var userName = Guid.NewGuid().ToString(); var reason = Guid.NewGuid().ToString(); _mockMemberNotificationInfoRepository .Setup(s => s.FindByIdAsync(memberNotificationInfo.MemberNotificationInfoId)) .ReturnsAsync(memberNotificationInfo); _mockProcessingLogService .Setup(s => s.SaveAsync(It.IsAny())) .ThrowsAsync(new Exception()); var thrown = Assert.ThrowsAsync(() => _memberNotificationInfoService.SetDocumentNotificationStatus(memberNotificationInfo.MemberNotificationInfoId, notificationStatus, userName, reason)); StringAssert.Contains(memberNotificationInfo.MemberNotificationInfoId.ToString(), thrown.Message); StringAssert.Contains(notificationStatus.ToString(), thrown.Message); } [Test] public async Task SetDocumentNotificationStatus_SetStatusSuccessAndLogSuccess_ReturnsTrue() { var notificationStatus = NotificationStatusTypes.CriticalFailure; var notificationInfo = new MemberNotificationInfo { MemberNotificationInfoId = DateTime.Now.Millisecond, DocumentProcessingInfoId = DateTime.Now.Millisecond + 1, NotificationStatusType = notificationStatus }; var newNotificationStatus = notificationStatus + 1; var userName = Guid.NewGuid().ToString(); var reason = Guid.NewGuid().ToString(); var processingLogs = new List(); _mockMemberNotificationInfoRepository .Setup(s => s.FindByIdAsync(notificationInfo.MemberNotificationInfoId)) .ReturnsAsync(notificationInfo); _mockMemberNotificationInfoRepository .Setup(r => r.Update(notificationInfo)) .Callback(returnedUpdated => returnedUpdated.NotificationStatusType = notificationInfo.NotificationStatusType); _mockProcessingLogService .Setup(s => s.SaveAsync(It.IsAny())) .Callback(processingLogs.Add); var updated = await _memberNotificationInfoService.SetDocumentNotificationStatus ( notificationInfo.MemberNotificationInfoId, newNotificationStatus, userName, reason ); Assert.IsTrue(updated); Assert.AreEqual(newNotificationStatus, notificationInfo.NotificationStatusType); Assert.AreEqual(1, processingLogs.Count); } [Test] public async Task BulkSetDocumentNotificationStatus_Success() { var notificationInfos = new List { new() { DocumentProcessingInfoId = DateTime.Now.Millisecond, NotificationStatusType = NotificationStatusTypes.CriticalFailure }, new() { DocumentProcessingInfoId = DateTime.Now.Millisecond + 1, NotificationStatusType = NotificationStatusTypes.CriticalFailure }, }; var request = new BulkNotificationStatusRequest { Filter = new() { NotificationStatusFilters = new List { NotificationStatusTypes.CriticalFailure } }, NotificationStatus = NotificationStatusTypes.Complete, ReasonMessage = Guid.NewGuid().ToString() }; var userName = Guid.NewGuid().ToString(); _mockMemberNotificationInfoRepository .Setup(s => s.GetMemberNotificationInfosByFilter(request.Filter)) .ReturnsAsync(notificationInfos); _mockMemberNotificationInfoRepository .Setup(r => r.UpdateRange(notificationInfos)); _mockProcessingLogService .Setup(s => s.SaveRangeAsync(It.IsAny>())); var updated = await _memberNotificationInfoService.BulkSetDocumentNotificationStatus(request, userName); Assert.IsTrue(updated); Assert.AreEqual(request.NotificationStatus, notificationInfos[0].NotificationStatusType); Assert.AreEqual(request.NotificationStatus, notificationInfos[1].NotificationStatusType); _mockMemberNotificationInfoRepository.Verify(x => x.GetMemberNotificationInfosByFilter(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny>()), Times.Once); _mockProcessingLogService.Verify(x => x.SaveRangeAsync(It.IsAny>()), Times.Once); } [Test] public async Task BulkSetDocumentNotificationStatus_Bulk_Success() { var repeatAmount = 15000; var randomInt = new Random(); var notificationInfos = Enumerable.Repeat(1, repeatAmount) .Select(_ => new MemberNotificationInfo { DocumentProcessingInfoId = randomInt.Next(1, repeatAmount), NotificationStatusType = NotificationStatusTypes.CriticalFailure }).ToList(); var request = new BulkNotificationStatusRequest { Filter = new() { NotificationStatusFilters = new List { NotificationStatusTypes.CriticalFailure } }, NotificationStatus = NotificationStatusTypes.Complete, ReasonMessage = Guid.NewGuid().ToString() }; var userName = Guid.NewGuid().ToString(); _mockMemberNotificationInfoRepository .Setup(s => s.GetMemberNotificationInfosByFilter(request.Filter)) .ReturnsAsync(notificationInfos); _mockMemberNotificationInfoRepository.Setup(s => s.UpdateRange(It.IsAny>())); _mockProcessingLogService .Setup(s => s.SaveRangeAsync(It.IsAny>())); Assert.IsTrue(await _memberNotificationInfoService.BulkSetDocumentNotificationStatus(request, userName)); _mockMemberNotificationInfoRepository.Verify(x => x.GetMemberNotificationInfosByFilter(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny>()), Times.Exactly(2)); _mockProcessingLogService.Verify(x => x.SaveRangeAsync(It.IsAny>()), Times.Exactly(2)); } [Test] public Task BulkSetDocumentNotificationStatus_Failure_ServiceException() { var request = new BulkNotificationStatusRequest { Filter = new() { NotificationStatusFilters = new List { NotificationStatusTypes.CriticalFailure } }, NotificationStatus = NotificationStatusTypes.Complete, ReasonMessage = Guid.NewGuid().ToString() }; var userName = Guid.NewGuid().ToString(); _mockMemberNotificationInfoRepository .Setup(s => s.GetMemberNotificationInfosByFilter(request.Filter)) .ThrowsAsync(new Exception()); Assert.ThrowsAsync(() => _memberNotificationInfoService.BulkSetDocumentNotificationStatus(request, userName)); _mockMemberNotificationInfoRepository.Verify(x => x.GetMemberNotificationInfosByFilter(It.IsAny()), Times.Once); _mockMemberNotificationInfoRepository.Verify(x => x.UpdateRange(It.IsAny>()), Times.Never); _mockProcessingLogService.Verify(x => x.SaveRangeAsync(It.IsAny>()), Times.Never); return Task.CompletedTask; } }