summaryrefslogtreecommitdiff
path: root/product/Service/Infrastructure/Threading/BackgroundThreadSpecs.cs
blob: c5ee6659115a2e99dc2890503f3dc933313ea19c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using developwithpassion.bdd.contexts;
using Gorilla.Commons.Testing;
using MoMoney.Utility.Core;
using Rhino.Mocks;

namespace Gorilla.Commons.Infrastructure.Threading
{
    [Concern(typeof (BackgroundThread))]
    public abstract class behaves_like_a_background_thread : concerns_for<IBackgroundThread, BackgroundThread>
    {
        context c = () =>
                        {
                            command_to_execute = the_dependency<IDisposableCommand>();
                            worker_thread = the_dependency<IWorkerThread>();
                        };

        protected static IDisposableCommand command_to_execute;
        protected static IWorkerThread worker_thread;
    }

    [Concern(typeof (BackgroundThread))]
    public class when_executing_a_command_on_a_background_thread : behaves_like_a_background_thread
    {
        it should_execute_the_command_asynchronously = () => command_to_execute.was_told_to(c => c.run());

        it should_start_the_worker_thread_asynchronously = () => worker_thread.was_told_to(t => t.begin());

        because b = () =>
                        {
                            sut.run();
                            worker_thread.Raise(t => t.DoWork += null, null, null);
                        };
    }

    [Concern(typeof (BackgroundThread))]
    public class when_disposing_a_background_thread : behaves_like_a_background_thread
    {
        it should_dispose_the_command_running_on_the_thread = () => worker_thread.was_told_to(w => w.Dispose());

        because b = () => sut.Dispose();
    }
}