public void Should_Call_AfterAction()
        {
            _asyncMethod1Worked.ShouldBe(false);
            InternalAsyncHelper.WaitTaskAndActionWithFinally(
                MyMethod1Async(),
                async() =>
            {
                _asyncMethod1Worked.ShouldBe(true);
                await Task.Delay(10);
            },
                () => { }
                ).Wait();

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

            returnValue.ShouldBe(42);
        }
Example #2
0
        private void PerformAsyncUow(IInvocation invocation, UnitOfWorkOptions options)
        {
            var uow = _unitOfWorkManager.Begin(options);

            invocation.Proceed();

            if (invocation.Method.ReturnType == typeof(Task))
            {
                invocation.ReturnValue = InternalAsyncHelper.WaitTaskAndActionWithFinally(
                    (Task)invocation.ReturnValue,
                    async() => await uow.CompleteAsync(),
                    uow.Dispose
                    );
            }
            else //Task<TResult>
            {
                invocation.ReturnValue = InternalAsyncHelper.CallReturnGenericTaskAfterAction(
                    invocation.Method.ReturnType.GenericTypeArguments[0],
                    invocation.ReturnValue,
                    async() => await uow.CompleteAsync(),
                    uow.Dispose
                    );
            }
        }