Mercurial > silverbladetech
comparison Library/LibrarySystem.Tests/LibrarySystemTests.cs @ 41:dbd242eb9c33
Initial wave of TDD development
author | adminsh@apollo |
---|---|
date | Tue, 03 Apr 2012 23:29:32 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
40:64c89891d7b6 | 41:dbd242eb9c33 |
---|---|
1 using LibrarySystem.Core; | |
2 using LibrarySystem.Interfaces; | |
3 using NUnit.Framework; | |
4 | |
5 namespace LibrarySystem.Tests | |
6 { | |
7 [TestFixture] | |
8 public class LibraryTests | |
9 { | |
10 /* | |
11 * Factory that creates: | |
12 * Library with 10 books (2 x Lord of the Flies, 3 x 1984, 5 x Brave New World) | |
13 */ | |
14 private ILibrary CreateScenario() | |
15 { | |
16 #region Publisher | |
17 | |
18 IPublisher penguin = new Publisher() {Name = "Penguin"}; | |
19 | |
20 #endregion | |
21 | |
22 #region Publications | |
23 | |
24 IPublication lordOfTheFlies = new Publication() | |
25 { | |
26 Author = "William Golding", | |
27 ISBN = "0140283331", | |
28 Publisher = penguin, | |
29 Title = "Lord of the Flies" | |
30 }; | |
31 | |
32 IPublication nineteenEightyFour = new Publication() | |
33 { | |
34 Author = "George Orwell", | |
35 ISBN = "0452284236", | |
36 Title = "Nineteen Eighty-Four" | |
37 }; | |
38 | |
39 IPublication braveNewWorld = new Publication() | |
40 { | |
41 Author = "Aldous Huxley", | |
42 ISBN = "0060850523", | |
43 Title = "Brave New World" | |
44 }; | |
45 | |
46 #endregion | |
47 | |
48 #region Books | |
49 | |
50 // Lord of the flies | |
51 IBook book1 = new Book(lordOfTheFlies) | |
52 {Id = "0000001", CurrentFee = 1.25m}; | |
53 IBook book2 = new Book(lordOfTheFlies) | |
54 {Id = "0000002", CurrentFee = 1.25m}; | |
55 IBook book3 = new Book(lordOfTheFlies) | |
56 {Id = "0000003", CurrentFee = 1.25m}; | |
57 | |
58 // 1984 | |
59 IBook book4 = new Book(nineteenEightyFour) | |
60 {Id = "0000004", CurrentFee = 1.5m}; | |
61 IBook book5 = new Book(nineteenEightyFour) | |
62 {Id = "0000005", CurrentFee = 1.5m}; | |
63 | |
64 // Brave new world | |
65 IBook book6 = new Book(braveNewWorld) | |
66 {Id = "0000006", CurrentFee = 1.8m}; | |
67 IBook book7 = new Book(braveNewWorld) | |
68 {Id = "0000007", CurrentFee = 1.8m}; | |
69 IBook book8 = new Book(braveNewWorld) | |
70 {Id = "0000008", CurrentFee = 1.8m}; | |
71 IBook book9 = new Book(braveNewWorld) | |
72 {Id = "0000009", CurrentFee = 1.8m}; | |
73 IBook book10 = new Book(braveNewWorld) | |
74 {Id = "0000010", CurrentFee = 1.8m}; | |
75 | |
76 #endregion | |
77 | |
78 #region Library | |
79 | |
80 ILibrary library = new Library(); | |
81 library.Location = "Leicester Square"; | |
82 library.AddStock(book1, book2, book3, book4, book5, book6, book7, book8, book9, book10); | |
83 | |
84 #endregion | |
85 | |
86 return library; | |
87 } | |
88 | |
89 [Test] | |
90 public void AddStockShouldIncreaseStockListCountByOne() | |
91 { | |
92 //arrange | |
93 var library = new Library(); | |
94 var expected = library.StockList.Count + 1; | |
95 var dummyBook = new Book(new Publication()); | |
96 | |
97 //act | |
98 library.AddStock(dummyBook); | |
99 var actual = library.StockList.Count; | |
100 | |
101 //assert | |
102 Assert.AreEqual(expected, actual); | |
103 } | |
104 | |
105 [Test] | |
106 public void SearchForAvailableBookByIBSNShouldReturnTrue() | |
107 { | |
108 var library = CreateScenario(); | |
109 | |
110 // Lord of the flies | |
111 var validISBN = "0140283331"; | |
112 | |
113 var actual = library.IsBookAvailableByISBN(validISBN); | |
114 | |
115 Assert.IsTrue(actual); | |
116 } | |
117 | |
118 [Test] | |
119 public void SearchForUnavailableBookByIBSNShouldReturnFalse() | |
120 { | |
121 var library = CreateScenario(); | |
122 | |
123 // rubbish data | |
124 var invalidISBN = "X"; | |
125 | |
126 var actual = library.IsBookAvailableByISBN(invalidISBN); | |
127 | |
128 Assert.IsFalse(actual); | |
129 } | |
130 | |
131 [Test] | |
132 public void FindBooksByValidSearchTitleString() | |
133 { | |
134 var library = CreateScenario(); | |
135 | |
136 // good search string | |
137 var searchString = "Flies"; | |
138 | |
139 // number of Lord of the Flies books expected | |
140 var expected = 3; | |
141 var actual = library.FindBooks(searchString).Count; | |
142 | |
143 Assert.AreEqual(expected, actual); | |
144 } | |
145 | |
146 | |
147 [Test] | |
148 public void FindBooksByValidSearchTitleStringLowerCase() | |
149 { | |
150 var library = CreateScenario(); | |
151 | |
152 // good search string | |
153 var searchString = "flies"; | |
154 | |
155 // number of Lord of the Flies books expected | |
156 var expected = 3; | |
157 var actual = library.FindBooks(searchString).Count; | |
158 | |
159 Assert.AreEqual(expected, actual); | |
160 } | |
161 | |
162 [Test] | |
163 public void FindBooksByValidSearchStringMultiplePublications() | |
164 { | |
165 var library = CreateScenario(); | |
166 | |
167 // good search string | |
168 var searchString = "e"; | |
169 | |
170 // number of Lord of the Flies books expected | |
171 var expected = 10; | |
172 var actual = library.FindBooks(searchString).Count; | |
173 | |
174 Assert.AreEqual(expected, actual); | |
175 } | |
176 | |
177 [Test] | |
178 public void FindBooksByValidSearchAuthorString() | |
179 { | |
180 var library = CreateScenario(); | |
181 | |
182 // number of Brave New World books expected | |
183 var expected = 5; | |
184 var searchString = "ldous"; | |
185 | |
186 var actual = library.FindBooks(searchString).Count; | |
187 | |
188 Assert.AreEqual(expected, actual); | |
189 } | |
190 | |
191 [Test] | |
192 public void FindBooksByInvalidSearchString() | |
193 { | |
194 var library = CreateScenario(); | |
195 | |
196 // rubbish data | |
197 var searchString = "XYZ"; | |
198 | |
199 var actual = library.FindBooks(searchString); | |
200 | |
201 Assert.IsEmpty(actual); | |
202 } | |
203 } | |
204 } |