public void ExecuteTaskWhenValidItemCallsAppropriateMethods() { // Arrange var queueManagerMock = MockRepository.GenerateMock<QueueManager>(new DbDrivenQueueProcessor()); var providerSubscriberMock = MockRepository.GenerateMock<IProviderAndSubscriberOptinService>(); IQueueItem queMock = new QueueItem { Id = 1, QueueCode = QueueCodeType.PushIntegrationInventory }; queueManagerMock.Expect( qmm => qmm.GetQueueItem( Arg<IQueueItem>.Matches(iq => iq.QueueCode == QueueCodeType.PushIntegrationInventory))) .Return(queMock) .Repeat.Once(); queueManagerMock.Expect( qmm => qmm.ProcessQueueItem(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id))).Repeat.Once(); // handle the one call when used in base constructor queueManagerMock.Expect(qmm => qmm.ResetStaleQueueItems()).Repeat.Once(); AigInventoryChangeTask aigInventoryTaskMock = MockRepository.GeneratePartialMock<AigInventoryChangeTask>(queueManagerMock); aigInventoryTaskMock.State = TaskState.Running; providerSubscriberMock.Expect(psm => psm.Load()).Repeat.AtLeastOnce(); aigInventoryTaskMock.ProviderSubscriberOptInService = providerSubscriberMock; aigInventoryTaskMock.QueueManager = queueManagerMock; aigInventoryTaskMock.Expect( ait => ait.ProcessRequest(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id))) .Return(true) .Repeat.Once(); aigInventoryTaskMock.Expect( ait => ait.ValidateRequest(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id))) .Return(true) .Repeat.Once(); // Act aigInventoryTaskMock.ExecuteTask(); // Assert by verify providerSubscriberMock.VerifyAllExpectations(); queueManagerMock.VerifyAllExpectations(); aigInventoryTaskMock.VerifyAllExpectations(); }
public QueueItem Execute(QueueItem queueItem) { // in parameters var parameters = new List<SqlParameter> { DbHelper.CreateParameter(Parameters.QueueCode, queueItem.QueueCode.GetCode()), DbHelper.CreateParameter(Parameters.UserId, queueItem.UserId), DbHelper.CreateParameter(Parameters.ItemKey, queueItem.Key), DbHelper.CreateParameter(Parameters.Payload, queueItem.Payload), DbHelper.CreateParameter(Parameters.PayloadTypeCode, queueItem.PayloadType.GetCode()) }; // out parameters SqlParameter outputItemId; parameters.Add(outputItemId = DbHelper.CreateParameterOut<int>(OutParameters.ItemId, SqlDbType.Int)); DbHelper.ExecuteNonQueryCommand(this, parameters); queueItem.Id = DbHelper.ParameterValue<int?>(outputItemId); return queueItem; }
/// <summary> /// Add a queueItem based on the payment and invoice request /// </summary> /// <param name="payment">payment information</param> /// <param name="payload">invoice request</param> /// <returns>queue item with id set</returns> virtual internal QueueItem GetSettlementQueueItemFromPayment(Payment payment, SettlementInvoiceRequest payload) { QueueItem queItem = null; if (payload.IsValid()) { // create queue item from payment sent in queItem = new QueueItem { Key = payment.OrderId.ToString(), PayloadType = PayloadTypeEnum.BookingInv, QueueCode = QueueCodeType.SettlementInvoiceRequest, UserId = payment.CreatedByUserId, Payload = XmlSerialization.XmlSerializeToString(payload) }; } return queItem; }
/// <summary> /// Add a queueItem based on the payment and invoice request /// </summary> /// <param name="queItem">queue item to add</param> /// <returns>queue item with id set</returns> public QueueItem AddQueueItem(QueueItem queItem) { return queueDao.AddQueueItem(queItem); }
public void ExecuteTaskHandlesRetriesSuccessfully() { // Arrange var queueManagerMock = MockRepository.GenerateMock<QueueManager>(new DbDrivenQueueProcessor()); var providerSubscriberMock = MockRepository.GenerateMock<IProviderAndSubscriberOptinService>(); IQueueItem queMock = new QueueItem { Id = 1, QueueCode = QueueCodeType.PushIntegrationInventory }; queueManagerMock.Expect( qmm => qmm.GetQueueItem( Arg<IQueueItem>.Matches(iq => iq.QueueCode == QueueCodeType.PushIntegrationInventory))) .Return(queMock) .Repeat.Once(); // since the task fails this won't happen queueManagerMock.Expect( qmm => qmm.ProcessQueueItem(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id))).Repeat.Never(); // handle the one call when used in base constructor queueManagerMock.Expect(qmm => qmm.ResetStaleQueueItems()).Repeat.Once(); AigInventoryChangeTask aigInventoryTaskMock = MockRepository.GeneratePartialMock<AigInventoryChangeTask>(queueManagerMock); aigInventoryTaskMock.State = TaskState.Running; providerSubscriberMock.Expect(psm => psm.Load()).Repeat.AtLeastOnce(); aigInventoryTaskMock.ProviderSubscriberOptInService = providerSubscriberMock; aigInventoryTaskMock.QueueManager = queueManagerMock; // return false showing failure in execution aigInventoryTaskMock.Expect( ait => ait.ProcessRequest(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id))) .Return(false) .Repeat.Once(); aigInventoryTaskMock.Expect( ait => ait.ValidateRequest(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id))) .Return(true) .Repeat.Once(); aigInventoryTaskMock.Expect( ait => ait.ScheduleRetryAndHandleFailure(Arg<IQueueItem>.Matches(iq => iq.Id == queMock.Id), Arg<Exception>.Is.Null)).Repeat.Once(); // Act aigInventoryTaskMock.ExecuteTask(); // Assert by verify providerSubscriberMock.VerifyAllExpectations(); queueManagerMock.VerifyAllExpectations(); aigInventoryTaskMock.VerifyAllExpectations(); }
/// <summary> /// Add the given item to the eagle queue /// </summary> /// <param name="queueItem">queue item to add</param> /// <returns>queue item with id set</returns> public QueueItem AddQueueItem(QueueItem queueItem) { return new StoredProcedures.Queue.AddItemMapper().Execute(queueItem); }