main
 1using System;
 2using Gorilla.Commons.Infrastructure.Container;
 3using gorilla.commons.utility;
 4
 5namespace tests.unit.commons.infrastructure
 6{
 7    [Concern(typeof (Resolve))]
 8    public abstract class behaves_like_a_inversion_of_control_container : concerns {}
 9
10    [Concern(typeof (Resolve))]
11    public class when_resolving_a_dependency_using_the_container : behaves_like_a_inversion_of_control_container
12    {
13        context c = () =>
14        {
15            registry = an<DependencyRegistry>();
16            presenter = an<Command>();
17            registry.is_told_to(x => x.get_a<Command>()).it_will_return(presenter);
18            Resolve.initialize_with(registry);
19        };
20
21        because b = () =>
22        {
23            result = Resolve.the<Command>();
24        };
25
26        it should_leverage_the_underlying_container_it_was_initialized_with =
27            () => registry.was_told_to(x => x.get_a<Command>());
28
29        it should_return_the_resolved_dependency = () => result.should_be_equal_to(presenter);
30
31        after_all a = () => Resolve.initialize_with(null);
32
33        static DependencyRegistry registry;
34        static Command result;
35        static Command presenter;
36    }
37
38    [Concern(typeof (Resolve))]
39    public class when_resolving_a_dependency_that_is_not_registered_ : behaves_like_a_inversion_of_control_container
40    {
41        context c = () =>
42        {
43            registry = an<DependencyRegistry>();
44            registry.is_told_to(x => x.get_a<Command>()).it_will_throw(new Exception());
45            Resolve.initialize_with(registry);
46        };
47
48        because b = () =>
49        {
50            the_call = call.to(() => Resolve.the<Command>());
51        };
52
53        after_all a = () => Resolve.initialize_with(null);
54
55        it should_throw_a_dependency_resolution_exception =
56            () => the_call.should_have_thrown<DependencyResolutionException<Command>>();
57
58        static DependencyRegistry registry;
59        static Action the_call;
60    }
61}