public void TrySetException_ThrowsIfExceptionIsNull() { // Arrange var op = new AsyncCompletionSource(); // Act/Assert Assert.Throws <ArgumentNullException>(() => op.TrySetException(null)); }
public void TrySetException_ThrowsIfOperationIsDisposed() { // Arrange var e = new Exception(); var op = new AsyncCompletionSource(AsyncOperationStatus.RanToCompletion); op.Dispose(); // Act/Assert Assert.Throws <ObjectDisposedException>(() => op.TrySetException(e)); }
public void TrySetException_SetsStatusToCanceled(AsyncOperationStatus status) { // Arrange var e = new OperationCanceledException(); var op = new AsyncCompletionSource(status); // Act var result = op.TrySetException(e); // Assert Assert.True(op.IsCanceled); Assert.True(result); Assert.Equal(e, op.Exception); }
public void TrySetException_RaisesCompletionCallbacks() { // Arrange var e = new Exception(); var asyncCallbackCalled1 = false; var asyncCallbackCalled2 = false; var op = new AsyncCompletionSource(asyncResult => asyncCallbackCalled1 = true, null); op.AddCompletionCallback(asyncOp => asyncCallbackCalled2 = true, null); // Act op.TrySetException(e); // Assert Assert.True(asyncCallbackCalled1); Assert.True(asyncCallbackCalled2); }