public void TaskWithMoreTriesThanMaxShouldBeSetToFailedNotPerformedAndQueueMessageDeleted() { var taskQueueStorage = new Mock <ITaskQueueStorage>(); var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var serverTime = new Mock <IServerTime>(); var newContactEmailSender = new Mock <INotificationEmailSender>(); var phoneNotificationSender = new Mock <IPhoneNotificationTaskPerformer>(); var contactProductAnlyticDataImporter = new Mock <IAddAnalyticProductDataForClient>(); var createAnalyticDataTasksForClients = new Mock <ICreateAnalyticDataTasksForClients>(); var customEventsImporter = new Mock <ICustomEventsImporter>(); var seoDataImporter = new Mock <ISeoDataImporter>(); var userEmailSender = new Mock <IUserNotificationEmailSender>(); var importCustomEventsTaskCreator = new Mock <IImportCustomEventsTaskCreator>(); var removeExpiredTokens = new Mock <IRemoveExpiredTokens>(); var createUpdatePhoneCallsForClients = new Mock <ICreateUpdatePhonecallsTasksForClients>(); var updatePhoneCalls = new Mock <IUpdatePhonecalls>(); var smsNotificationTaskCreator = new Mock <ISmsNotificationTaskPerformer>(); var userSmsNotificationTaskPerformer = new Mock <IUserSmsNotificationTaskPerformer>(); var task1 = ModelHelper.Task1AllData; var taskId = task1.Id; task1.NumTries = 4; taskRepository.Add(task1); TaskQueueMessage taskQueueMessage = new TaskQueueMessage() { Id = "taskqueuemessageId", PopReceipt = "PopReceipt", Message = taskId.ToString() }; var taskDelegate = new TaskDelegate( taskQueueStorage.Object, taskRepository, serverTime.Object, newContactEmailSender.Object, phoneNotificationSender.Object, contactProductAnlyticDataImporter.Object, createAnalyticDataTasksForClients.Object, customEventsImporter.Object, seoDataImporter.Object, userEmailSender.Object, importCustomEventsTaskCreator.Object, removeExpiredTokens.Object, createUpdatePhoneCallsForClients.Object, updatePhoneCalls.Object, smsNotificationTaskCreator.Object, userSmsNotificationTaskPerformer.Object); taskDelegate.PerformNextTask(taskQueueMessage.Message); seoDataImporter.Verify(wr => wr.PerformTask(It.IsAny <InsideModel.Models.Task>()), Times.Never); Assert.AreEqual(1, taskRepository.Where(t => t.Id == taskId).Count()); Assert.AreEqual(TaskStatus.Failed, taskRepository.Where(t => t.Id == taskId).First().Status); }
public void TaskSuccessSetStatusCompleteAndDeleteTaskQueueMessage() { DateTime now = new DateTime(2013, 1, 17); var taskQueueStorage = new Mock <ITaskQueueStorage>(); var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var serverTime = new Mock <IServerTime>(); var newContactEmailSender = new Mock <INotificationEmailSender>(); var phoneNotificationSender = new Mock <IPhoneNotificationTaskPerformer>(); var contactProductAnlyticDataImporter = new Mock <IAddAnalyticProductDataForClient>(); var createAnalyticDataTasksForClients = new Mock <ICreateAnalyticDataTasksForClients>(); var customEventsImporter = new Mock <ICustomEventsImporter>(); var seoDataImporter = new Mock <ISeoDataImporter>(); var userEmailSender = new Mock <IUserNotificationEmailSender>(); var importCustomEventsTaskCreator = new Mock <IImportCustomEventsTaskCreator>(); var removeExpiredTokens = new Mock <IRemoveExpiredTokens>(); var createUpdatePhoneCallsForClients = new Mock <ICreateUpdatePhonecallsTasksForClients>(); var updatePhoneCalls = new Mock <IUpdatePhonecalls>(); var smsNotificationTaskCreator = new Mock <ISmsNotificationTaskPerformer>(); var userSmsNotificationTaskPerformer = new Mock <IUserSmsNotificationTaskPerformer>(); serverTime.Setup(st => st.RequestStarted).Returns(now); var task1 = ModelHelper.Task1AllData; var taskId = task1.Id; taskRepository.Add(task1); TaskQueueMessage taskQueueMessage = new TaskQueueMessage() { Id = "taskqueuemessageId", PopReceipt = "PopReceipt", Message = taskId.ToString() }; var taskDelegate = new TaskDelegate( taskQueueStorage.Object, taskRepository, serverTime.Object, newContactEmailSender.Object, phoneNotificationSender.Object, contactProductAnlyticDataImporter.Object, createAnalyticDataTasksForClients.Object, customEventsImporter.Object, seoDataImporter.Object, userEmailSender.Object, importCustomEventsTaskCreator.Object, removeExpiredTokens.Object, createUpdatePhoneCallsForClients.Object, updatePhoneCalls.Object, smsNotificationTaskCreator.Object, userSmsNotificationTaskPerformer.Object); taskDelegate.PerformNextTask(taskQueueMessage.Message); Assert.AreEqual(1, taskRepository.Where(t => t.Id == taskId).Count()); Assert.AreEqual(TaskStatus.Completed, taskRepository.Where(t => t.Id == taskId).First().Status); }
public void Add(InsideModel.Models.Task queueTask) { taskRepository.Add(queueTask); taskRepository.SaveChanges(); TimeSpan?initialInvisibility = null; if (serverTime.Now < queueTask.EarliestExecution) { initialInvisibility = queueTask.EarliestExecution - serverTime.Now; } var taskQueueMessage = new TaskQueueMessage() { Message = queueTask.Id.ToString() }; var message = new CloudQueueMessage(taskQueueMessage.Message); queue.AddMessage(message, null, initialInvisibility); }
public void ReQueue(InsideModel.Models.Task queueTask) { if (queueTask.NumTries > 0) { queueTask.EarliestExecution = serverTime.Now + GetNextExecutionDelay(queueTask.NumTries); } var taskQueueMessage = new TaskQueueMessage() { Message = queueTask.Id.ToString() }; var message = new CloudQueueMessage(taskQueueMessage.Message); TimeSpan?initialInvisibility = null; if (serverTime.Now < queueTask.EarliestExecution) { initialInvisibility = queueTask.EarliestExecution - serverTime.Now; } queue.AddMessage(message, null, initialInvisibility); }
public void OnGoogleApiExeptionAnalyticProductRetryForbidden() { DateTime earliestExecution = new DateTime(2013, 1, 15); DateTime now = new DateTime(2013, 1, 17); var taskQueueStorage = new Mock <ITaskQueueStorage>(); var taskRepository = new LocalRepository <InsideModel.Models.Task>(); var serverTime = new Mock <IServerTime>(); var newContactEmailSender = new Mock <INotificationEmailSender>(); var phoneNotificationSender = new Mock <IPhoneNotificationTaskPerformer>(); var contactProductAnlyticDataImporter = new Mock <IAddAnalyticProductDataForClient>(); var createAnalyticDataTasksForClients = new Mock <ICreateAnalyticDataTasksForClients>(); var customEventsImporter = new Mock <ICustomEventsImporter>(); var seoDataImporter = new Mock <ISeoDataImporter>(); var userEmailSender = new Mock <IUserNotificationEmailSender>(); var importCustomEventsTaskCreator = new Mock <IImportCustomEventsTaskCreator>(); var removeExpiredTokens = new Mock <IRemoveExpiredTokens>(); var createUpdatePhoneCallsForClients = new Mock <ICreateUpdatePhonecallsTasksForClients>(); var updatePhoneCalls = new Mock <IUpdatePhonecalls>(); var smsNotificationTaskCreator = new Mock <ISmsNotificationTaskPerformer>(); var userSmsNotificationTaskPerformer = new Mock <IUserSmsNotificationTaskPerformer>(); serverTime.Setup(st => st.RequestStarted).Returns(now); serverTime.Setup(st => st.Now).Returns(now); var task1 = ModelHelper.Task1AllData; task1.Type = TaskType.AddProductAnalyticData; var taskId = task1.Id; task1.EarliestExecution = earliestExecution; taskRepository.Add(task1); TaskQueueMessage taskQueueMessage = new TaskQueueMessage() { Id = "taskqueuemessageId", PopReceipt = "PopReceipt", Message = taskId.ToString() }; contactProductAnlyticDataImporter.Setup(wr => wr.PerformTask(It.IsAny <InsideModel.Models.Task>())).Throws(new GoogleApiException("Analytics", "task failed") { HttpStatusCode = HttpStatusCode.Forbidden }); var taskDelegate = new TaskDelegate( taskQueueStorage.Object, taskRepository, serverTime.Object, newContactEmailSender.Object, phoneNotificationSender.Object, contactProductAnlyticDataImporter.Object, createAnalyticDataTasksForClients.Object, customEventsImporter.Object, seoDataImporter.Object, userEmailSender.Object, importCustomEventsTaskCreator.Object, removeExpiredTokens.Object, createUpdatePhoneCallsForClients.Object, updatePhoneCalls.Object, smsNotificationTaskCreator.Object, userSmsNotificationTaskPerformer.Object); taskDelegate.PerformNextTask(taskQueueMessage.Message); Assert.AreEqual(1, taskRepository.Where(t => t.Id == taskId).Count()); Assert.AreEqual(1, taskRepository.Where(t => t.Id == taskId).First().NumTries); Assert.AreEqual("Queued", taskRepository.Where(t => t.Id == taskId).First().Status); taskQueueStorage.Verify(tq => tq.ReQueue(It.Is <InsideModel.Models.Task>(t => t.NumTries == 1)), Times.Once); }