main
1using Machine.Specifications;
2using solidware.financials.service.orm;
3
4namespace specs.unit.service.orm
5{
6 public class SimpleIdentityMapSpecs
7 {
8 [Concern(typeof (SimpleIdentityMap<,>))]
9 public abstract class behaves_like_identity_map
10 {
11 Establish context = () =>
12 {
13 sut = new SimpleIdentityMap<int, string>();
14 };
15
16 static protected IdentityMap<int, string> sut;
17 }
18
19 [Concern(typeof (SimpleIdentityMap<,>))]
20 public class when_getting_an_item_from_the_identity_map_for_an_item_that_has_been_added : behaves_like_identity_map
21 {
22 It should_return_the_item_that_was_added_for_the_given_key = () =>
23 {
24 result.should_be_equal_to("1");
25 };
26
27 Because b = () =>
28 {
29 sut.add(1, "1");
30 result = sut.item_that_belongs_to(1);
31 };
32
33 static string result;
34 }
35
36 [Concern(typeof (SimpleIdentityMap<,>))]
37 public class when_getting_an_item_from_the_identity_map_that_has_not_been_added : behaves_like_identity_map
38 {
39 It should_return_the_default_value_for_that_type = () =>
40 {
41 result.should_be_equal_to(null);
42 };
43
44 Because b = () =>
45 {
46 result = sut.item_that_belongs_to(2);
47 };
48
49 static string result;
50 }
51
52 [Concern(typeof (SimpleIdentityMap<,>))]
53 public class when_checking_if_an_item_has_been_added_to_the_identity_map_that_has_been_added :
54 behaves_like_identity_map
55 {
56 It should_return_true = () =>
57 {
58 result.should_be_true();
59 };
60
61 Because b = () =>
62 {
63 sut.add(10, "10");
64 result = sut.contains_an_item_for(10);
65 };
66
67 static bool result;
68 }
69
70 [Concern(typeof (SimpleIdentityMap<,>))]
71 public class when_checking_if_an_item_has_been_added_to_the_identity_map_that_has_not_been_added :
72 behaves_like_identity_map
73 {
74 It should_return_false = () =>
75 {
76 result.should_be_false();
77 };
78
79 Because b = () =>
80 {
81 result = sut.contains_an_item_for(9);
82 };
83
84 static bool result;
85 }
86
87 [Concern(typeof (SimpleIdentityMap<,>))]
88 public class when_updating_the_value_for_a_key_that_has_already_been_added_to_the_identity_map :
89 behaves_like_identity_map
90 {
91 It should_replace_the_old_item_with_the_new_one = () =>
92 {
93 result.should_be_equal_to("7");
94 };
95
96 Because b = () =>
97 {
98 sut.add(6, "6");
99 sut.update_the_item_for(6, "7");
100 result = sut.item_that_belongs_to(6);
101 };
102
103 static string result;
104 }
105
106 [Concern(typeof (SimpleIdentityMap<,>))]
107 public class when_updating_the_value_for_a_key_that_has_not_been_added_to_the_identity_map : behaves_like_identity_map
108 {
109 It should_add_the_new_item = () =>
110 {
111 result.should_be_equal_to("3");
112 };
113
114 Because b = () =>
115 {
116 sut.update_the_item_for(3, "3");
117 result = sut.item_that_belongs_to(3);
118 };
119
120 static string result;
121 }
122 }
123}