public void Throw_SocketException_when_connection_is_closed() { // Arrange var fakesocket = new FakeSocket { Connected = false, ReceiveCallback = (buffer, offset, length) => { throw new SocketException(); } }; var callbacks = new PoolSocketCallbacks(); var poolsocket = new PoolSocket(fakesocket, callbacks.Reclaim); // Act try { poolsocket.Receive(new byte[0], 0, 0); Assert.Fail("didn't throw"); } catch (SocketException ex) { // Assert Assert.AreEqual((int)SocketError.NotConnected, ex.ErrorCode); } }
public void On_failure_PoolSocket_and_underlying_socket_are_disposed_and_reclaimed() { // Arrange var fakesocket = new FakeSocket { ReceiveCallback = (buffer, offset, length) => { throw new SocketException(); } }; var callbacks = new PoolSocketCallbacks(); var poolsocket = new PoolSocket(fakesocket, callbacks.Reclaim); // Act try { poolsocket.Receive(new byte[0], 0, 0); Assert.Fail("didn't throw"); } catch(SocketException) { } // Assert Assert.AreEqual(1, fakesocket.ReceiveCalled, "send called wrong number of times"); Assert.IsTrue(fakesocket.IsDisposed, "underlying socket wasn't disposed"); Assert.IsTrue(poolsocket.IsDisposed, "pool socket wasn't disposed"); Assert.AreEqual(1, callbacks.ReclaimCalled, "reclaim was called wrong number of times"); Assert.AreSame(fakesocket, callbacks.ReclaimedSocket, "underlying socket wasn't the one reclaimed"); }