main
 1using Castle.Core.Interceptor;
 2using developwithpassion.bdd.contexts;
 3using Gorilla.Commons.Testing;
 4using gorilla.commons.Utility;
 5
 6namespace momoney.service.infrastructure.threading
 7{
 8    [Concern(typeof (RunOnBackgroundThreadInterceptor<>))]
 9    public abstract class behaves_like_background_thread_interceptor :
10        concerns_for<IInterceptor, RunOnBackgroundThreadInterceptor<DisposableCommand>>
11    {
12        context c = () =>
13        {
14            thread_factory = the_dependency<IBackgroundThreadFactory>();
15        };
16
17        static protected IBackgroundThreadFactory thread_factory;
18    }
19
20    [Concern(typeof (RunOnBackgroundThreadInterceptor<>))]
21    public class when_intercepting_a_call_to_a_method_that_takes_a_long_time_to_complete :
22        behaves_like_background_thread_interceptor
23    {
24        context c = () =>
25        {
26            invocation = an<IInvocation>();
27            background_thread = an<IBackgroundThread>();
28            thread_factory
29                .is_told_to(f => f.create_for<DisposableCommand>())
30                .it_will_return(background_thread);
31        };
32
33        because b = () => sut.Intercept(invocation);
34
35        it should_display_a_progress_bar_on_a_background_thread =
36            () => thread_factory.was_told_to(f => f.create_for<DisposableCommand>());
37
38        it should_proceed_with_the_orginal_invocation_on_the_actual_object =
39            () => invocation.was_told_to(i => i.Proceed());
40
41        it should_hide_the_progress_bar_when_the_invocation_is_completed =
42            () => background_thread.was_told_to(b => b.Dispose());
43
44        static IInvocation invocation;
45        static IBackgroundThread background_thread;
46    }
47}