main
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Castle.DynamicProxy;
 5using gorilla.infrastructure.threading;
 6using gorilla.utility;
 7using Machine.Specifications;
 8using solidware.financials.windows.ui;
 9
10namespace specs.unit.ui
11{
12    public class RunInBackgroundInterceptorSpecs
13    {
14        public abstract class concern
15        {
16            Establish context = () =>
17            {
18                processor = new TestCommandProcessor();
19                sut = new RunInBackgroundInterceptor(processor);
20            };
21
22            static protected RunInBackgroundInterceptor sut;
23            static protected TestCommandProcessor processor;
24        }
25
26        public class when_running_all_actions_against_a_proxy_on_a_background_thread : concern
27        {
28            Establish context = () =>
29            {
30                invocation = Create.an<IInvocation>();
31            };
32
33            Because of = () =>
34            {
35                sut.Intercept(invocation);
36            };
37
38            It should_push_a_command_on_the_background_thread_to_invoke_the_call = () =>
39            {
40                invocation.was_not_told_to(x => x.Proceed());
41                processor.actions.Count.should_be_equal_to(1);
42                processor.actions.First().Invoke();
43                invocation.received(x => x.Proceed());
44            };
45
46            static IInvocation invocation;
47        }
48    }
49
50    public class TestCommandProcessor : CommandProcessor
51    {
52        public List<Action> actions = new List<Action>();
53
54        public void run() {}
55
56        public void add(Action command)
57        {
58            actions.add(command);
59        }
60
61        public void add(Command command_to_process)
62        {
63            add(command_to_process.run);
64        }
65
66        public void stop() {}
67    }
68}