public void WhenMainframeTransactionFails_ThrowsHostTransactionFailureException() { // arrange int WSAECONNRESET = 10054; MockDependents mockDependents = new MockDependents(); mockDependents.MockOrderSocketConnectionRepository .Setup(m => m.Receive()) .Throws(BuildMockException(WSAECONNRESET)); IOrderQueueLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderFile = GetMockData("OrderFile.json"); OrderFile order = JsonConvert.DeserializeObject <OrderFile>(jsonOrderFile); Action sendToHost = () => testunit.SendToHost(order); // assert sendToHost.Should() .Throw <HostTransactionFailureException>() .WithInnerException <SocketResponseException>() .WithInnerException <IOException>() .WithMessage("*connection was forcibly closed by the remote host*"); }
public void WhenMainframeDoesNotRespond_ThrowsTimeoutException() { // arrange int WSAETIMEDOUT = 10060; MockDependents mockDependents = new MockDependents(); mockDependents.MockOrderSocketConnectionRepository .Setup(m => m.Receive()) .Throws(BuildMockException(WSAETIMEDOUT)); IOrderQueueLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderFile = GetMockData("OrderFile.json"); OrderFile order = JsonConvert.DeserializeObject <OrderFile>(jsonOrderFile); Action sendToHost = () => testunit.SendToHost(order); // assert sendToHost.Should() .Throw <TimeoutException>() .WithInnerException <SocketResponseException>() .WithInnerException <IOException>() .WithMessage("*host has failed to respond*"); }
private void ProcessQueueTick(object state) { if (!_orderQueueProcessing) { _orderQueueProcessing = true; // do not process between 1 and 5 if (DateTime.Now.Hour >= 1 && DateTime.Now.Hour < 5) { _log.WriteInformationLog("Script stopped for processing window"); while (DateTime.Now.Hour < 5) { Thread.Sleep(60000); } _log.WriteInformationLog("Script started after processing window"); } try { using (_queueScope = _diContainer.BeginLifetimeScope()) { IOrderQueueLogic orderQueue = _queueScope.Resolve <IOrderQueueLogic>(); orderQueue.ProcessOrders(); } _successfulOrderConnection = true; _unsentCount = 0; } catch (EarlySocketException earlyEx) { HandleEarlySocketException(earlyEx, false); } catch (SocketResponseException responseEx) { HandleSocketResponseException(responseEx, false); } catch (CancelledTransactionException cancelledEx) { HandleCancelledException(cancelledEx); } catch (Exception ex) { _log.WriteErrorLog("Error processing orders", ex); ExceptionEmail.Send(ex, "", "Error processing orders"); } _orderQueueProcessing = false; } }
public void WhenOrderTransmissionIsSuccessful_ExecutesInReasonableTimeSpan() { Queue <string> successfulResponseQueue = GetSuccessfulResponseQueue(); MockDependents mockDependents = new MockDependents(); mockDependents.MockOrderSocketConnectionRepository .Setup(m => m.Receive()) .Returns(() => successfulResponseQueue.Dequeue()); IOrderQueueLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderFile = GetMockData("OrderFile.json"); OrderFile order = JsonConvert.DeserializeObject <OrderFile>(jsonOrderFile); Action sendToHost = () => testunit.SendToHost(order); // assert sendToHost.ExecutionTime().Should().BeLessOrEqualTo(TimeSpan.FromMilliseconds(1000)); }
public void WhenOrderTransmissionIsSuccessful_HasNoExceptions() { // arrange Queue <string> successfulResponseQueue = GetSuccessfulResponseQueue(); MockDependents mockDependents = new MockDependents(); mockDependents.MockOrderSocketConnectionRepository .Setup(m => m.Receive()) .Returns(() => successfulResponseQueue.Dequeue()); IOrderQueueLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderFile = GetMockData("OrderFile.json"); OrderFile order = JsonConvert.DeserializeObject <OrderFile>(jsonOrderFile); Action sendToHost = () => testunit.SendToHost(order); // assert sendToHost.Should().NotThrow(); }
public void WhenOrderTransmissionIsSuccessful_InvokesReceive() { // arrange Queue <string> successfulResponseQueue = GetSuccessfulResponseQueue(); MockDependents mockDependents = new MockDependents(); mockDependents.MockOrderSocketConnectionRepository .Setup(m => m.Receive()) .Returns(() => successfulResponseQueue.Dequeue()); IOrderQueueLogic testunit = MakeUnitToBeTested(true, mockDependents); // act string jsonOrderFile = GetMockData("OrderFile.json"); OrderFile order = JsonConvert.DeserializeObject <OrderFile>(jsonOrderFile); Action sendToHost = () => testunit.SendToHost(order); sendToHost.Invoke(); // assert mockDependents.MockOrderSocketConnectionRepository .Verify(m => m.Receive(), Times.Exactly(6), "not called."); }