public void TaskService_AllOperationsHandlerTasks_CallsRepositoryQuery() { #region Arrange #endregion #region Act var outstandingTasks = _taskService.AllOperationsHandlerTasks().ToList(); #endregion #region Assert Assert.IsNotNull(outstandingTasks); _mockTaskRepository.Verify(x => x.Query(It.IsAny <Expression <Func <Task, bool> > >()), Times.Once()); #endregion }
public override void Execute() { try { var serviceInstanceId = Settings.Default.ServiceInstanceId; // Check that the Service Instance Id is not empty if (serviceInstanceId == Guid.Empty) { throw new ArgumentNullException(string.Format(TaskResources.ConfigurationFile_SettingMissing, nameof(serviceInstanceId))); } // Get all outstanding operations tasks var tasks = _taskService.AllOperationsHandlerTasks().ToList(); if (tasks.Any()) { foreach (var task in tasks) { try { RetryableOperation.Invoke( ExceptionPolicies.General, () => { // Create a new DI container to keep all work with the handler discrete _objectBuilder.AddChildContainer(); // Instantiate the task handler using (var taskHandler = _objectBuilder.Resolve <ITaskHandler>(task.Handler)) { // Check that the task is scheduled to be executed if (!taskHandler.CanExecute(task, serviceInstanceId)) { return; } taskHandler.Execute(task, serviceInstanceId); } }); } catch (UnRecoverableErrorException) { // Already handled } catch (Exception ex) { // Create a History Log var historyLog = task.CreateHistoryLog(_userIdentity.Name); historyLog.EventType = LoggingEventTypeNames.Error; historyLog.EventDetail = string.Format(TaskResources.UnexpectedApplicationErrorInstanceHandlingId, ex.Message); historyLog.Escalated = false; _historyLogService.Create(historyLog); // Update Task NextScheduledDate task.NextScheduledDate = DateTime.Now.AddMinutes(_parameterService.GetParameterByNameAndCache <int>(ParameterNames.RecoverableExceptionRetryDelayIntervalInMinutes)); _taskService.Update(task); } finally { _objectBuilder.RemoveAllChildContainers(); } } } } catch (Exception ex) { _loggingManager.Write(LoggingEventSource.OperationsService, LoggingEventType.Error, ex.Message); } }