Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void TestValueTaskMethodSyncOk(VTaskOptions options)
        {
            //SETUP

            //ATTEMPT
            var valueTask = ValueTaskMethod(options);

            //VERIFY
            CheckSyncValueTask(valueTask, options);
        }
Esempio n. 4
0
        public void TestValueTaskIntMethodSyncOk(VTaskOptions options)
        {
            //SETUP

            //ATTEMPT
            var valueTaskInt = ValueTaskIntMethod(options);

            //VERIFY
            valueTaskInt.IsFaulted.ShouldEqual(options.HasFlag(VTaskOptions.ThrowException));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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");
            }
        }
Esempio n. 8
0
        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));
        }