main
1using System.Collections.Generic;
2using developwithpassion.bdd.contexts;
3using developwithpassion.bdd.harnesses.mbunit;
4using developwithpassion.bdddoc.core;
5using gorilla.migrations.console.infrastructure;
6using MbUnit.Framework;
7
8namespace tests.console
9{
10 public class SimpleContainerSpecs
11 {
12 public abstract class concern : observations_for_a_sut_with_a_contract<Container, SimpleContainer>
13 {
14 context c = () =>
15 {
16 builder = new SimpleContainerBuilder();
17 };
18
19 public override Container create_sut()
20 {
21 return builder.build();
22 }
23
24 static protected SimpleContainerBuilder builder;
25 }
26
27 [Concern(typeof (SimpleContainer))]
28 public class when_registering_an_item_with_the_container : concern
29 {
30 context c = () =>
31 {
32 builder.register(() => new Thingy()).as_an<IThingy>().scoped_as<Factory>();
33 };
34
35 because b = () =>
36 {
37 result = controller.sut.get_a<IThingy>();
38 };
39
40 it should_return_a_new_instance_each_time_it_is_told_to_create_one = () =>
41 {
42 result.should_not_be_equal_to(controller.sut.get_a<IThingy>());
43 };
44
45 static IThingy result;
46 }
47
48 [Concern(typeof (SimpleContainer))]
49 public class when_resolving_multiple_implementations_for_a_component : concern
50 {
51 context c = () =>
52 {
53 builder.register(() => new Thingy()).as_an<IThingy>();
54 builder.register(() => new AnotherThingy()).as_an<IThingy>();
55 };
56
57 because b = () =>
58 {
59 results = controller.sut.get_all<IThingy>();
60 };
61
62 it should_return_each_registered_implementation = () =>
63 {
64 results.should_contain_item_matching(x => x is Thingy);
65 results.should_contain_item_matching(x => x is AnotherThingy);
66 };
67
68 static IEnumerable<IThingy> results;
69 }
70
71 [Concern(typeof (SimpleContainer))]
72 public class when_attempting_to_resolve_an_item_from_the_container_that_has_not_been_registered : concern
73 {
74 because b = () =>
75 {
76 controller.doing(() => controller.sut.get_a<string>());
77 };
78
79 it should_throw_a_meaningful_exception = () =>
80 {
81 controller.exception_thrown_by_the_sut.should_be_an_instance_of<ComponentResolutionException<string>>();
82 };
83 }
84
85 [Concern(typeof (SimpleContainer))]
86 [Ignore]
87 public class when_resolving_an_ienumerable_of_anything : concern
88 {
89 context c = () =>
90 {
91 builder.register(() => new Thingy()).as_an<IThingy>();
92 builder.register(() => new AnotherThingy()).as_an<IThingy>();
93 };
94
95 because b = () =>
96 {
97 results = controller.sut.get_a<IEnumerable<IThingy>>();
98 };
99
100 it should_return_each_registered_implementation = () =>
101 {
102 results.should_contain_item_matching(x => x is Thingy);
103 results.should_contain_item_matching(x => x is AnotherThingy);
104 };
105
106 static IEnumerable<IThingy> results;
107 }
108 }
109
110
111 interface IThingy {}
112
113 class Thingy : IThingy {}
114
115 class AnotherThingy : IThingy {}
116}