public void CallsHangUpUntilAllConnectionsHaveBeenClosed() { var api = new Mock <IRasApi32>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); var handle = new IntPtr(1); var counter = 0; api.Setup(o => o.RasHangUp(handle)).Returns(() => { counter++; if (counter < 3) { return(SUCCESS); } else { return(ERROR_NO_CONNECTION); } }); var target = new RasHangUpService(api.Object, exceptionPolicy.Object); target.UnsafeHangUp(handle, true, CancellationToken.None); api.Verify(o => o.RasHangUp(handle), Times.Exactly(3)); }
public void ThrowsAnExceptionWhenTheHandleIsZero() { var api = new Mock <IRasApi32>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); var target = new RasHangUpService(api.Object, exceptionPolicy.Object); Assert.Throws <ArgumentNullException>(() => target.UnsafeHangUp(IntPtr.Zero, true, CancellationToken.None)); }
public void HangsUpTheConnectionFromPtrAsExpected() { var handle = new IntPtr(1); var api = new Mock <IRasApi32>(); api.Setup(o => o.RasHangUp(handle)).Returns(ERROR_NO_CONNECTION); var exceptionPolicy = new Mock <IExceptionPolicy>(); var target = new RasHangUpService(api.Object, exceptionPolicy.Object); target.UnsafeHangUp(handle, true, CancellationToken.None); api.Verify(o => o.RasHangUp(handle), Times.Once); }
public void ThrowsAnExceptionWhenHangUpReturnsAnInvalidResultCode() { var api = new Mock <IRasApi32>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); exceptionPolicy.Setup(o => o.Create(-1)).Returns(new TestException()); var handle = new IntPtr(1); api.Setup(o => o.RasHangUp(handle)).Returns(-1); var target = new RasHangUpService(api.Object, exceptionPolicy.Object); Assert.Throws <TestException>(() => target.UnsafeHangUp(handle, true, CancellationToken.None)); api.Verify(o => o.RasHangUp(handle), Times.Once); }