public void TestCheckSyncValueTaskIntDynamicWorked(VTaskOptions options) { //SETUP dynamic valueTask = ValueTaskIntMethod(options); int result = 0; //ATTEMPT try { result = ValueTaskSyncCheckers.CheckSyncValueTaskWorkedDynamicAndReturnResult <int>(valueTask); } catch (Exception e) { options.ShouldNotEqual(VTaskOptions.Sync); if (options.HasFlag(VTaskOptions.Async)) { e.Message.ShouldEqual("Expected a sync task, but got an async task"); } if (options.HasFlag(VTaskOptions.ThrowException)) { e.Message.ShouldEqual("Exception thrown"); } return; } //VERIFY options.ShouldEqual(VTaskOptions.Sync); result.ShouldEqual(1); }
public void TestCheckSyncValueTaskIntWorked(VTaskOptions options) { //SETUP var valueTaskInt = ValueTaskIntMethod(options); //ATTEMPT try { valueTaskInt.CheckSyncValueTaskWorkedAndReturnResult(); } catch (Exception e) { options.ShouldNotEqual(VTaskOptions.Sync); if (options.HasFlag(VTaskOptions.Async)) { e.Message.ShouldEqual("Expected a sync task, but got an async task"); } if (options.HasFlag(VTaskOptions.ThrowException)) { e.Message.ShouldEqual("Exception thrown"); } return; } //VERIFY options.ShouldEqual(VTaskOptions.Sync); }
private async ValueTask <int> ValueTaskIntMethod(VTaskOptions options) { if (options.HasFlag(VTaskOptions.Async)) { var cancelToken = options.HasFlag(VTaskOptions.CancelAsync) ? new CancellationToken(true) : CancellationToken.None; await Task.Delay(1000, cancelToken); } if (options.HasFlag(VTaskOptions.ThrowException)) { throw new InvalidOperationException("Exception thrown"); } return(1); }
public async Task TestValueTaskMethodAsyncOk(VTaskOptions options) { //SETUP //ATTEMPT try { await ValueTaskMethod(options); } catch { (options.HasFlag(VTaskOptions.ThrowException) || options.HasFlag(VTaskOptions.CancelAsync)).ShouldBeTrue(); return; } //VERIFY options.HasFlag(VTaskOptions.CancelAsync).ShouldBeFalse(); options.HasFlag(VTaskOptions.ThrowException).ShouldBeFalse(); }
public void TestValueTaskIntMethodSyncOk(VTaskOptions options) { //SETUP //ATTEMPT var valueTaskInt = ValueTaskIntMethod(options); //VERIFY valueTaskInt.IsFaulted.ShouldEqual(options.HasFlag(VTaskOptions.ThrowException)); }
private async ValueTask ValueTaskMethod(VTaskOptions options, int depth = 0) { if (options.HasFlag(VTaskOptions.Async)) { var cancelToken = options.HasFlag(VTaskOptions.CancelAsync) ? new CancellationToken(true) : CancellationToken.None; await Task.Delay(1, cancelToken); } if (depth > 0 && !options.HasFlag(VTaskOptions.Async)) { var valueTask = ValueTaskMethod(options, depth - 1); valueTask.CheckSyncValueTaskWorked(); return; } if (options.HasFlag(VTaskOptions.ThrowException)) { throw new Exception("Exception thrown"); } }
private void CheckSyncValueTask(ValueTask valueTask, VTaskOptions options) { if (options.HasFlag(VTaskOptions.ThrowException)) { valueTask.IsFaulted.ShouldBeTrue(); valueTask.IsCompleted.ShouldBeTrue(); valueTask.IsCompletedSuccessfully.ShouldBeFalse(); var task = valueTask.AsTask(); task.Exception.ShouldNotBeNull(); } else { valueTask.IsFaulted.ShouldBeFalse(); valueTask.IsCompleted.ShouldBeTrue(); valueTask.IsCompletedSuccessfully.ShouldBeTrue(); var task = valueTask.AsTask(); task.Exception.ShouldBeNull(); } valueTask.IsCanceled.ShouldEqual(options.HasFlag(VTaskOptions.CancelAsync)); }