main
 1using System;
 2using jive;
 3using Machine.Specifications;
 4
 5namespace specs.unit.container
 6{
 7  [Subject(typeof (Resolve))]
 8  public abstract class behaves_like_a_inversion_of_control_container
 9  {
10    [Subject(typeof (Resolve))]
11    public class when_resolving_a_dependency_using_the_container : behaves_like_a_inversion_of_control_container
12    {
13      Establish c = () =>
14      {
15        registry = Create.an<DependencyRegistry>();
16        presenter = Create.an<Command>();
17        registry.Setup(x => x.get_a<Command>()).Returns(presenter.Object);
18        Resolve.initialize_with(registry.Object);
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.Verify(x => x.get_a<Command>());
28
29      It should_return_the_resolved_dependency = () => result.should_be_equal_to(presenter.Object);
30
31      Cleanup a = () => Resolve.initialize_with(null);
32
33      static Moq.Mock<DependencyRegistry> registry;
34      static Command result;
35      static Moq.Mock<Command> presenter;
36    }
37
38    [Subject(typeof (Resolve))]
39    public class when_resolving_a_dependency_that_is_not_registered_ : behaves_like_a_inversion_of_control_container
40    {
41      Establish c = () =>
42      {
43        registry = Create.an<DependencyRegistry>();
44        registry.Setup(x => x.get_a<Command>()).Throws(new Exception());
45        Resolve.initialize_with(registry.Object);
46      };
47
48      Because b = () =>
49      {
50        the_call = call.to(() => Resolve.the<Command>());
51      };
52
53      Cleanup a = () => Resolve.initialize_with(null);
54
55      It should_throw_a_dependency_resolution_exception = () => the_call.should_have_thrown<DependencyResolutionException<Command>>();
56
57      static Moq.Mock<DependencyRegistry> registry;
58      static Action the_call;
59    }
60  }
61}