public virtual Task DoAsync()
            {
                BeforeAfterCallOrderInterceptor.ActionCalled();
                var result = new Task(() => Thread.Sleep(100));

                result.Start();
                return(result);
            }
            public virtual Task <int> DoAsyncInt()
            {
                BeforeAfterCallOrderInterceptor.ActionCalled();
                var result = new Task <int>(
                    () =>
                {
                    Thread.Sleep(100);
                    return(42);
                });

                result.Start();
                return(result);
            }
        public void AsyncMethodsCanBeIntercepted()
        {
            using (var kernel = this.CreateDefaultInterceptionKernel())
            {
                BeforeAfterCallOrderInterceptor.Reset();

                kernel.Bind <AsyncService>().ToSelf().Intercept().With <BeforeAfterCallOrderInterceptor>();

                var service = kernel.Get <AsyncService>();
                var task    = service.DoAsync();
                task.Wait();

                BeforeAfterCallOrderInterceptor.Order.Should().Be("Before_Action_AfterCompleted_");
            }
        }
        public void AsyncMethodsWithReturnValue_InterceptorsCanChangeTheResult()
        {
            using (var kernel = this.CreateDefaultInterceptionKernel())
            {
                BeforeAfterCallOrderInterceptor.Reset();

                kernel.Bind <AsyncService>().ToSelf().Intercept().With <IncreaseResultInterceptor>();
                var service = kernel.Get <AsyncService>();

                var task = service.DoAsyncInt();
                task.Wait();

                BeforeAfterCallOrderInterceptor.Order.Should().Be("Before_Action_AfterCompleted_");
                task.Result.Should().Be(43);
            }
        }