public async Task ThrowsAsync_Should_ThrowAssertionException_WhenCustomExpressionConstraintIncorrect() { var result = await SafelyCatchAnNUnitExceptionAsync(() => Assert.ThrowsAsync(new ExceptionTypeConstraint(typeof(ArgumentException)), async() => throw new NullReferenceException())); Assert.That(result, new ExceptionTypeConstraint(typeof(AssertionException))); }
private async IPandaTask LoadAssetBundleAsync_WithCancellation_Token_Should_ThrowOperationCancelledException <T>(Func <CancellationToken, IPandaTask <T> > taskToWait) { CancellationTokenSource cancellationToken = new CancellationTokenSource(); cancellationToken.Cancel(); await Assert.ThrowsAsync <OperationCanceledException>(async() => await taskToWait.Invoke(cancellationToken.Token)); }
public async Task WaitAsync_WithCancellation_Token_Should_Throw_OperationCancelledException() { CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.Cancel(); await Assert.ThrowsAsync <OperationCanceledException>(async() => await _request.WaitAsync(cancellationTokenSource.Token)); }
public async Task GenericThrowsAsync_Should_ReturnCorrectMessage_WhenAssertionIsFailed() { const string expectedMessage = "assertion_failed_message"; var result = await SafelyCatchAnNUnitExceptionAsync(() => Assert.ThrowsAsync <NullReferenceException>(async() => { }, expectedMessage)); Assert.That(result.Message, Does.Contain(expectedMessage)); }
public async Task GenericThrowsAsync_Should_ThrowAssertionException_WhenNoAnyExceptionWasThrown() { var exceptionToThrow = new ArgumentException("some_message", "some_name"); var result = await SafelyCatchAnNUnitExceptionAsync(() => Assert.ThrowsAsync <ArgumentException>(async() => { })); Assert.That(result, new ExceptionTypeConstraint(typeof(AssertionException))); Assert.That(exceptionToThrow, Is.Not.EqualTo(result)); Assert.That(result.Message, Is.EqualTo($" Expected: <{exceptionToThrow.GetType().FullName}>" + Environment.NewLine + " But was: null" + Environment.NewLine)); }
public async Task WaitAsync_WithProgressTrackerAndCancellationToken_Should_Throw_OperationCancelledException() { var progressTracker = new ProgressTracker <float>(); CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.Cancel(); await Assert.ThrowsAsync <OperationCanceledException>(async() => await _request.WaitAsync(progressTracker, cancellationTokenSource.Token)); Assert.That(progressTracker.Progress, Is.EqualTo(1)); }
private async IPandaTask LoadAssetBundleAsync_WithProgressTrackerAndCancellationToken_Should_ThrowOperationCancelledException <T>( Func <IProgressTracker <float>, CancellationToken, IPandaTask <T> > taskToWait) { var progressTracker = new ProgressTracker <float>(); CancellationTokenSource cancellationToken = new CancellationTokenSource(); cancellationToken.Cancel(); await Assert.ThrowsAsync <OperationCanceledException>(async() => await taskToWait.Invoke(progressTracker, cancellationToken.Token)); Assert.That(progressTracker.Progress, Is.EqualTo(1)); }
public async Task ThrowsAsync_Should_ThrowAssertionException_WhenUnrelatedExceptionWasThrown() { var expectedExceptionType = typeof(NullReferenceException); var unrelatedException = new ArgumentException("some_message", "some_name"); var result = await SafelyCatchAnNUnitExceptionAsync(() => Assert.ThrowsAsync(expectedExceptionType, async() => throw unrelatedException)); Assert.That(result, new ExceptionTypeConstraint(typeof(AssertionException))); Assert.That(expectedExceptionType, Is.Not.TypeOf(result.GetType())); Assert.That(result.Message, Does.StartWith($" Expected: <{expectedExceptionType.FullName}>" + Environment.NewLine + $" But was: <{unrelatedException.GetType().FullName}: {unrelatedException.Message}" + Environment.NewLine)); }
public async Task ThrowsAsync_Should_ReturnCorrectException() { await ThrowsAsyncShouldReturnCorrectExceptionBaseTest(exception => Assert.ThrowsAsync(exception.GetType(), async() => throw exception)); }
public async Task ThrowsAsync_Should_Succeed_WithCustomExpressionConstraint() { await Assert.ThrowsAsync(new ExceptionTypeConstraint( typeof(ArgumentException)), async() => throw new ArgumentException()); }
public async Task ThrowsAsync_Should_Succeed() { await Assert.ThrowsAsync(typeof(ArgumentException), async() => throw new ArgumentException()); }