public void ThrowsAnExceptionWhenTheConnectionIsNull() { var api = new Mock <IRasApi32>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); var target = new RasHangUpService(api.Object, exceptionPolicy.Object); Assert.Throws <ArgumentNullException>(() => target.HangUp(null, true, CancellationToken.None)); }
public void ThrowsAnExceptionWhenCancellationIsRequested() { var api = new Mock <IRasApi32>(); var exceptionPolicy = new Mock <IExceptionPolicy>(); var handle = new IntPtr(1); var connection = new Mock <IRasConnection>(); connection.Setup(o => o.Handle).Returns(handle); using (var cancellationSource = new CancellationTokenSource()) { cancellationSource.Cancel(); var target = new RasHangUpService(api.Object, exceptionPolicy.Object); Assert.Throws <OperationCanceledException>(() => target.HangUp(connection.Object, true, cancellationSource.Token)); } }
public void HangsUpTheConnectionAsExpected() { var handle = new IntPtr(1); var connection = new Mock <IRasConnection>(); connection.Setup(o => o.Handle).Returns(handle); 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.HangUp(connection.Object, true, CancellationToken.None); api.Verify(o => o.RasHangUp(handle), Times.Once); }