コード例 #1
0
            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*");
            }
コード例 #2
0
            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*");
            }
コード例 #3
0
            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));
            }
コード例 #4
0
            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();
            }
コード例 #5
0
            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.");
            }