main
1using developwithpassion.bdd.contexts;
2using Gorilla.Commons.Testing;
3
4namespace momoney.database.transactions
5{
6 [Concern(typeof (IdentityMap<,>))]
7 public class behaves_like_identity_map : concerns_for<IIdentityMap<int, string>, IdentityMap<int, string>>
8 {
9 public override IIdentityMap<int, string> create_sut()
10 {
11 return new IdentityMap<int, string>();
12 }
13 }
14
15 [Concern(typeof (IdentityMap<,>))]
16 public class when_getting_an_item_from_the_identity_map_for_an_item_that_has_been_added : behaves_like_identity_map
17 {
18 it should_return_the_item_that_was_added_for_the_given_key = () => result.should_be_equal_to("1");
19
20 because b = () =>
21 {
22 sut.add(1, "1");
23 result = sut.item_that_belongs_to(1);
24 };
25
26 static string result;
27 }
28
29 [Concern(typeof (IdentityMap<,>))]
30 public class when_getting_an_item_from_the_identity_map_that_has_not_been_added : behaves_like_identity_map
31 {
32 it should_return_the_default_value_for_that_type = () => result.should_be_equal_to(null);
33
34 because b = () => { result = sut.item_that_belongs_to(2); };
35
36 static string result;
37 }
38
39 [Concern(typeof (IdentityMap<,>))]
40 public class when_checking_if_an_item_has_been_added_to_the_identity_map_that_has_been_added :
41 behaves_like_identity_map
42 {
43 it should_return_true = () => result.should_be_true();
44
45 because b = () =>
46 {
47 sut.add(10, "10");
48 result = sut.contains_an_item_for(10);
49 };
50
51 static bool result;
52 }
53
54 [Concern(typeof (IdentityMap<,>))]
55 public class when_checking_if_an_item_has_been_added_to_the_identity_map_that_has_not_been_added :
56 behaves_like_identity_map
57 {
58 it should_return_false = () => result.should_be_false();
59
60 because b = () => { result = sut.contains_an_item_for(9); };
61
62 static bool result;
63 }
64
65 [Concern(typeof (IdentityMap<,>))]
66 public class when_updating_the_value_for_a_key_that_has_already_been_added_to_the_identity_map :
67 behaves_like_identity_map
68 {
69 it should_replace_the_old_item_with_the_new_one = () => result.should_be_equal_to("7");
70
71 because b = () =>
72 {
73 sut.add(6, "6");
74 sut.update_the_item_for(6, "7");
75 result = sut.item_that_belongs_to(6);
76 };
77
78 static string result;
79 }
80
81 [Concern(typeof (IdentityMap<,>))]
82 public class when_updating_the_value_for_a_key_that_has_not_been_added_to_the_identity_map :
83 behaves_like_identity_map
84 {
85 it should_add_the_new_item = () => result.should_be_equal_to("3");
86
87 because b = () =>
88 {
89 sut.update_the_item_for(3, "3");
90 result = sut.item_that_belongs_to(3);
91 };
92
93 static string result;
94 }
95}