Пример #1
0
            public void WhenPortIsFree_HasNoException()
            {
                // arrange
                MockDependents mockDependents = new MockDependents();

                ISocketListenerRepository testunit = MakeUnitToBeTested(true, mockDependents);

                // act
                Socket listener         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Action bindSocketToPort = () => testunit.BindSocketToPort(listener, Configuration.MainframeConfirmationListeningPort);

                // assert
                bindSocketToPort.Should().NotThrow();
            }
Пример #2
0
            public void WhenPortIsInUse_HasNoException()
            {
                // arrange
                MockDependents mockDependents = new MockDependents();

                ISocketListenerRepository testunit = MakeUnitToBeTested(true, mockDependents);

                var slowClosinglistener = StartListener(Configuration.MainframeConfirmationListeningPort);     // starts the port in use condition

                if (slowClosinglistener.IsBound == false)
                {
                    throw new Exception("Test logic failure: failed to start contending listener.");
                }

                Task.Run(() => StopListenerAfterDelay(slowClosinglistener, 30000));     // keep the port in use condition

                // act
                Socket listener         = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Action bindSocketToPort = () => testunit.BindSocketToPort(listener, Configuration.MainframeConfirmationListeningPort);

                // assert
                bindSocketToPort.Should().NotThrow();
            }