private void ProcessCheckLostOrders() { try { string subject; string body; orderHistoryScope = container.BeginLifetimeScope(); _orderHistoryLogic = orderHistoryScope.Resolve <IOrderHistoryLogic>(); subject = _orderHistoryLogic.CheckForLostOrders(out body); StringBuilder sbMsgBody = new StringBuilder(); sbMsgBody.Append(body); if ((subject != null) && (subject.Length > 0) && (body != null) && (body.Length > 0)) { _emailClient = lostOrdersScope.Resolve <IEmailClient>(); //_log.WriteErrorLog("BEK: " + subject + ";" + body ); _emailClient.SendEmail(Configuration.FailureEmailAdresses, null, null, "BEK: " + subject, body); } } catch (Exception ex) { _log.WriteErrorLog("Error in ProcessCheckLostOrdersMinuteTick", ex); KeithLink.Common.Impl.Email.ExceptionEmail.Send(ex); } }
private void InitializeOrderUpdateThread() { orderHistoryScope = container.BeginLifetimeScope(); _orderHistoryLogic = orderHistoryScope.Resolve <IOrderHistoryLogic>(); //_orderHistoryLogic.SubscribeToQueue(); _orderHistoryLogic.ListenForQueueMessages(); }
private static IOrderHistoryLogic MakeUnitToBeTested() { ContainerBuilder builder = DependencyMapFactory.GetOrderServiceContainer(); IContainer container = builder.Build(); IOrderHistoryLogic testunit = container.Resolve <IOrderHistoryLogic>(); return(testunit); }
public void OrderHistoryWithSubbedAndReplacedItems_ExecutesInReasonableTimeSpan() { // arrange IOrderHistoryLogic testunit = MakeUnitToBeTested(); // act string jsonOrderHistoryFile = GetMockData("OrderHistoryFileWithReplacementItems.json"); Action processOrder = () => testunit.ProcessOrder(jsonOrderHistoryFile); // assert processOrder.ExecutionTime().Should().BeLessOrEqualTo(TimeSpan.FromSeconds(10)); }
public void OrderHistory_HasValidHeadersAndOrderDate() { // arrange IOrderHistoryLogic testunit = MakeUnitToBeTested(); // act string jsonOrderHistoryFile = testunit.ReadOrderFromQueue(); // assert OrderHistoryFile orderHistoryFile = JsonConvert.DeserializeObject <OrderHistoryFile>(jsonOrderHistoryFile); CheckFile(orderHistoryFile); }
public void OrderHistory_HasValidHeadersAndOrderDate() { // arrange IOrderHistoryLogic testunit = MakeUnitToBeTested(); // act var mockDataReader = GetMockDataReader("OT780FDF-2018206-10273884.TXT"); OrderHistoryFileReturn orderHistoryFiles = testunit.ParseMainframeFile(mockDataReader); mockDataReader.Close(); // assert orderHistoryFiles.Files.Count.Should().Be(40); orderHistoryFiles.Files.ForEach(file => CheckFile(file)); }
public void WhenMainframeFileDoesNotContainOrderHistory_HasValidHeadersAndOrderDate() { // arrange MockDependents mockDependents = new MockDependents(); IOrderHistoryLogic testunit = MakeUnitToBeTested(true, mockDependents); // act var mockDataReader = new StringReader(string.Empty); OrderHistoryFileReturn orderHistoryFiles = testunit.ParseMainframeFile(mockDataReader); mockDataReader.Close(); // assert orderHistoryFiles.Files.Count.Should().Be(0); }
public void OrderHistory_HasValidHeadersAndOrderDate() { // arrange MockDependents mockDependents = new MockDependents(); IOrderHistoryLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderHistoryFile = testunit.ReadOrderFromQueue(); // assert mockDependents.MockGenericQueueRepository .Verify(m => m.ConsumeFromQueue(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once, "not called."); OrderHistoryFile orderHistoryFile = JsonConvert.DeserializeObject <OrderHistoryFile>(jsonOrderHistoryFile); CheckFile(orderHistoryFile); }
/// <summary> /// ctor /// </summary> /// <param name="shoppingCartLogic"></param> /// <param name="orderLogic"></param> /// <param name="shipDayRepo"></param> /// <param name="historyRequestLogic"></param> /// <param name="profileLogic"></param> /// <param name="exportSettingsLogic"></param> /// <param name="logRepo"></param> /// <param name="historyHeaderRepository"></param> /// <param name="orderHistoryLogic"></param> /// <param name="cartService"></param> public OrderController(IShoppingCartLogic shoppingCartLogic, IOrderLogic orderLogic, IShipDateRepository shipDayRepo, IListService listService, ICatalogLogic catalogLogic, IOrderHistoryRequestLogic historyRequestLogic, IUserProfileLogic profileLogic, IExportSettingLogic exportSettingsLogic, IEventLogRepository logRepo, IOrderHistoryHeaderRepsitory historyHeaderRepository, IOrderHistoryLogic orderHistoryLogic, IShoppingCartService cartService) : base(profileLogic) { _historyRequestLogic = historyRequestLogic; _orderLogic = orderLogic; _shipDayService = shipDayRepo; _shoppingCartLogic = shoppingCartLogic; _exportLogic = exportSettingsLogic; _log = logRepo; _historyHeaderRepo = historyHeaderRepository; _historyLogic = orderHistoryLogic; _listService = listService; _catalogLogic = catalogLogic; _shoppingCartService = cartService; }
public void OrderHistoryWithSubbedAndReplacedItems_IsSentToRepositoryWithValidOrderDate() { // arrange MockDependents mockDependents = new MockDependents(); IOrderHistoryLogic testunit = MakeUnitToBeTested(true, mockDependents); //expect string expectedOrderdate = new DateTime(2018, 07, 19, 16, 34, 51).ToLongDateFormatWithTime(); // act string jsonOrderHistoryFile = GetMockData("OrderHistoryFileWithReplacementItems.json"); testunit.ProcessOrder(jsonOrderHistoryFile); // assert mockDependents.MockOrderHistoryHeaderRepository .Verify(m => m.CreateOrUpdate(It.Is <EF.OrderHistoryHeader>(header => header.OrderDateTime == expectedOrderdate)), Times.Once, "not called with expected order date."); //mockDependents.MockOrderHistoryHeaderRepository.VerifyAll(); }
private void ProcessOrderHistoryListener() { try { using (_historyResponseScope = _diContainer.BeginLifetimeScope()) { IOrderHistoryLogic logic = _historyResponseScope.Resolve <IOrderHistoryLogic>(); logic.ListenForMainFrameCalls(); } } catch (Exception e) { string logMessage = "Processing failed receiving order updates. Processing of order updates will not continue. Please restart this service."; _log.WriteErrorLog(logMessage); ExceptionEmail.Send(e, logMessage); } }
public void ProcessOrderUpdatesTick(object state) { if (!_orderUpdateProcessing) { _orderUpdateProcessing = true; try { // if update path does not exist, send an email then suppress messages // disallow processing here until the folder exists, but do not kill the service // to keep other threads running if (Directory.Exists(Configuration.OrderUpdateWatchPath)) { _allowOrderUpdateProcessing = true; _silenceOrderUpdateMessages = false; } else { _allowOrderUpdateProcessing = false; if (!_silenceOrderUpdateMessages) { HandleMissingOrderUpdateWatchPath(); _silenceOrderUpdateMessages = true; } } if (_allowOrderUpdateProcessing) { string[] files = Directory.GetFiles(Configuration.OrderUpdateWatchPath); _orderScope = _diContainer.BeginLifetimeScope(); IGenericQueueRepository repo = _orderScope.Resolve <IGenericQueueRepository>(); Parallel.ForEach(files, filePath => { IOrderHistoryLogic logic = _orderScope.Resolve <IOrderHistoryLogic>(); if (CanOpenFile(filePath)) { var logMessage = "Processing " + filePath + "."; _log.WriteInformationLog(logMessage); OrderHistoryFileReturn parsedFile = null; using (var reader = File.OpenText(filePath)) { parsedFile = logic.ParseMainframeFile(reader); } if (parsedFile.Files.Count == 0) { logMessage = "No instances of OrderHistoryFile were extracted from " + filePath + "."; _log.WriteWarningLog(logMessage); } var serializedFiles = new BlockingCollection <string>(); Parallel.ForEach(parsedFile.Files, file => { // do not upload an order file with an invalid header if (file.ValidHeader) { file.SenderApplicationName = Configuration.ApplicationName; file.SenderProcessName = "Process Order History Updates From Mainframe (Flat File)"; try { var serializedFile = JsonConvert.SerializeObject(file); serializedFiles.Add(serializedFile); //StringBuilder logMsg = new StringBuilder(); //logMsg.AppendLine(string.Format("Serializing order history message ({0}).", file.MessageId)); //logMsg.AppendLine(); //logMsg.AppendLine(serializedFile); //_log.WriteInformationLog(logMsg.ToString()); _silenceOrderUpdateMessages = false; } catch (Exception ex) { if (!_silenceOrderUpdateMessages) { HandleException(ex); _silenceOrderUpdateMessages = true; } } } }); if (serializedFiles.Count > 0) { logMessage = "Publishing " + serializedFiles.Count + " order history messages to queue."; _log.WriteInformationLog(logMessage); repo.BulkPublishToQueue(serializedFiles.ToList(), Configuration.RabbitMQConfirmationServer, Configuration.RabbitMQUserNamePublisher, Configuration.RabbitMQUserPasswordPublisher, Configuration.RabbitMQVHostConfirmation, Configuration.RabbitMQExchangeHourlyUpdates); } File.Delete(filePath); logMessage = "Deleted " + filePath + "."; _log.WriteInformationLog(logMessage); } // end if CanOpenFile }); _orderScope.Dispose(); } } catch (Exception ex) { HandleException(ex); } _orderUpdateProcessing = false; } }