main
1using developwithpassion.bdd.contexts;
2using Gorilla.Commons.Testing;
3using gorilla.commons.Utility;
4using Rhino.Mocks;
5
6namespace momoney.service.infrastructure.threading
7{
8 [Concern(typeof (BackgroundThread))]
9 public abstract class behaves_like_a_background_thread : concerns_for<IBackgroundThread, BackgroundThread>
10 {
11 context c = () =>
12 {
13 command_to_execute = the_dependency<DisposableCommand>();
14 worker_thread = the_dependency<IWorkerThread>();
15 };
16
17 static protected DisposableCommand command_to_execute;
18 static protected IWorkerThread worker_thread;
19 }
20
21 [Concern(typeof (BackgroundThread))]
22 public class when_executing_a_command_on_a_background_thread : behaves_like_a_background_thread
23 {
24 it should_execute_the_command_asynchronously = () => command_to_execute.was_told_to(c => c.run());
25
26 it should_start_the_worker_thread_asynchronously = () => worker_thread.was_told_to(t => t.begin());
27
28 because b = () =>
29 {
30 sut.run();
31 worker_thread.Raise(t => t.DoWork += null, null, null);
32 };
33 }
34
35 [Concern(typeof (BackgroundThread))]
36 public class when_disposing_a_background_thread : behaves_like_a_background_thread
37 {
38 it should_dispose_the_command_running_on_the_thread = () => worker_thread.was_told_to(w => w.Dispose());
39
40 because b = () => sut.Dispose();
41 }
42}