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(); }
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(); }