Beispiel #1
0
        public void TestCheckSyncValueTaskIntDynamicWorkedStackTraceOk()
        {
            //SETUP
            dynamic valueTask = ValueTaskIntMethod(VTaskOptions.ThrowException);

            //ATTEMPT
            try
            {
                var result = ValueTaskSyncCheckers.CheckSyncValueTaskWorkedDynamicAndReturnResult <int>(valueTask);
            }
            catch (Exception e)
            {
                e.Message.ShouldEqual("Exception thrown");
                var stackTraceLines = e.StackTrace.Split('\n').Select(x => x.Trim()).ToArray();
                stackTraceLines[0].ShouldContain("TestValueTask.ValueTaskIntMethod(VTaskOptions options)");
                stackTraceLines[0].ShouldEndWith("62");
                stackTraceLines[1].ShouldContain("ValueTaskSyncCheckers.CheckSyncValueTaskWorkedAndReturnResult[TResult](ValueTask`1 valueTask)");
                stackTraceLines[1].ShouldEndWith("42");
                stackTraceLines[2].ShouldContain("ValueTaskSyncCheckers.GenericValueTypeChecker`1..ctor(Object valueTask)");
                stackTraceLines[2].ShouldEndWith("67");
                stackTraceLines[3].ShouldEqual("--- End of stack trace from previous location where exception was thrown ---");

                return;
            }

            //VERIFY
            Assert.False(true, "Should have thrown exception");
        }
Beispiel #2
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);
        }