Example #1
0
        public void Should_Call_AfterAction()
        {
            _asyncMethod1Worked.ShouldBe(false);
            InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
                MyMethod1Async(),
                async() =>
            {
                _asyncMethod1Worked.ShouldBe(true);
                await Task.Delay(10);
            },
                (exception) => { }
                ).Wait();

            _asyncMethod2Worked.ShouldBe(false);
            var returnValue = InternalAsyncHelper.AwaitTaskWithPostActionAndFinallyAndGetResult(
                MyMethod2Async(),
                async() =>
            {
                _asyncMethod2Worked.ShouldBe(true);
                await Task.Delay(10);
            },
                (exception) => { }
                ).Result;

            returnValue.ShouldBe(42);
        }
Example #2
0
        public async Task Should_Call_AfterAction()
        {
            _asyncMethod1Worked.ShouldBe(false);
            await InternalAsyncHelper.AwaitTaskWithPostActionAndFinally(
                MyMethod1Async(),
                async() =>
            {
                _asyncMethod1Worked.ShouldBe(true);
                await Task.Delay(10);
            },
                exception => { }
                );

            _asyncMethod2Worked.ShouldBe(false);
            int returnValue = await InternalAsyncHelper.AwaitTaskWithPostActionAndFinallyAndGetResult(
                MyMethod2Async(),
                async() =>
            {
                _asyncMethod2Worked.ShouldBe(true);
                await Task.Delay(10);
            },
                exception => { }
                );

            returnValue.ShouldBe(42);
        }