annotate Library/LibrarySystem.Tests/Core/LibraryTests.cs @ 93:03272bcb3cc0

Nuget updated
author stevenhollidge <stevenhollidge@hotmail.com>
date Mon, 30 Apr 2012 11:06:39 +0100
parents aef06698d9e2
children
rev   line source
43
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
1 using System;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
2 using System.Collections.Generic;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
3 using LibrarySystem.Core;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
4 using LibrarySystem.Interfaces;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
5 using NUnit.Framework;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
6
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
7 namespace LibrarySystem.Tests.Core
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
8 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
9 [TestFixture]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
10 public class LibraryTests
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
11 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
12 #region Factory methods to setup fixed scenario for testing
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
13
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
14 // Factory that creates:
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
15 // A library object with 10 books (2 x Lord of the Flies, 3 x 1984, 5 x Brave New World)
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
16 private ILibrary CreateLibraryScenario()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
17 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
18 #region Publisher
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
19
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
20 IPublisher penguin = Publisher.Create("Penguin");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
21
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
22 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
24 #region Publications
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
25
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
26 IPublication lordOfTheFlies = Publication.Create("William Golding", "0140283331", penguin, "Lord of the Flies");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
27
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
28 IPublication nineteenEightyFour = Publication.Create("George Orwell", "0452284236", penguin, "Nineteen Eighty-Four");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
29
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
30 IPublication braveNewWorld = Publication.Create("Aldous Huxley", "0060850523", penguin, "Brave New World");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
31
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
32 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
33
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
34 #region Books
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
35
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
36 // Lord of the flies
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
37 IBook book1 = Book.Create("0000001", lordOfTheFlies);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
38 IBook book2 = Book.Create("0000002", lordOfTheFlies);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
39 IBook book3 = Book.Create("0000003", lordOfTheFlies);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
40
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
41 // 1984
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
42 IBook book4 = Book.Create("0000004", nineteenEightyFour);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
43 IBook book5 = Book.Create("0000005", nineteenEightyFour);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
44
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
45 // Brave new world
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
46 IBook book6 = Book.Create("0000006", braveNewWorld);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
47 IBook book7 = Book.Create("0000007", braveNewWorld);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
48 IBook book8 = Book.Create("0000008", braveNewWorld);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
49 IBook book9 = Book.Create("0000009", braveNewWorld);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
50 IBook book10 = Book.Create("0000010", braveNewWorld);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
51
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
52 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
53
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
54 #region Library
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
55
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
56 ILibrary library = Library.Create("Leicester Square");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
57 library.AddStock(book1, book2, book3, book4, book5, book6, book7, book8, book9, book10);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
58
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
59 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
60
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
61 return library;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
62 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
63
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
64 public IBook CreateBook(string bookId = "dummy")
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
65 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
66 IPublisher publisher = Publisher.Create("dummy");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
67 IPublication publication = Publication.Create("dummy", "dummy", publisher, "dummy");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
68 IBook book = Book.Create(bookId, publication);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
69 return book;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
70 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
71
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
72 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
73
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
74 #region Create
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
75
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
76 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
77 public void Create_WithNullLocation_ThrowsArgumentNullException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
78 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
79 Assert.Throws<ArgumentNullException>(() => Library.Create(null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
80 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
81
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
82 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
83
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
84 #region AddStock
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
85
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
86 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
87 public void AddStock_WithNullBook_ShouldThrowArgumentNullException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
88 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
89 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
90 Assert.Throws<ArgumentNullException>(() => library.AddStock(null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
91 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
92
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
93 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
94 public void AddStock_WithOneValidBookAndOneNullBook_ShouldThrowArgumentNullException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
95 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
96 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
97 var validBook = CreateBook();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
98 Assert.Throws<ArgumentNullException>(() => library.AddStock(validBook, null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
99 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
100
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
101 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
102 public void AddStock_WithValidBook_ShouldIncreaseStockListCountByOne()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
103 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
104 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
105 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
106 var expected = library.StockList.Count + 1;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
107 var dummyBook = CreateBook();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
108
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
109 //act
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
110 library.AddStock(dummyBook);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
111 var actual = library.StockList.Count;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
112
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
113 //assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
114 Assert.AreEqual(expected, actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
115 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
116
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
117 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
118 public void AddStock_WithBookIdAlreadyInStock_ShouldThrowException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
119 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
120 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
121 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
122 var idThatIsAlreadyInStock = "0000001";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
123 var dummyBook = CreateBook(idThatIsAlreadyInStock);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
124
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
125 //act
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
126 Assert.Throws<Exception>(
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
127 () => library.AddStock(dummyBook),
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
128 string.Format("Book with {0} is already in stock", idThatIsAlreadyInStock));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
129 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
130
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
131 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
132 public void AddStock_WithValidBook_ShouldMakeBookAvailable()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
133 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
134 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
135 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
136 var id = "0000001";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
137 var dummyBook = CreateBook();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
138
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
139 //act
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
140 library.AddStock(dummyBook);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
141 var lookupBook = ((List<IStock>) library.StockList).Find(s => s.Book.Id == id);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
142 var actual = lookupBook.IsAvailable;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
143
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
144 //assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
145 Assert.IsTrue(actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
146 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
147
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
148 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
149
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
150 #region IsBookAvailableByISBN
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
151
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
152 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
153 public void IsBookAvailableByISBN_WithNullISBN_ShouldThrowArgumentNullExpection()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
154 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
155 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
156 Assert.Throws<ArgumentNullException>(() => library.IsBookAvailableByISBN(null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
157 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
158
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
159 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
160 public void IsBookAvailableByISBN_WithValidISBN_ShouldReturnTrue()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
161 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
162 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
163
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
164 // Lord of the flies
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
165 var validISBN = "0140283331";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
166
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
167 var actual = library.IsBookAvailableByISBN(validISBN);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
168
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
169 Assert.IsTrue(actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
170 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
171
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
172 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
173 public void IsBookAvailableByISBN_WithUnknownISBN_ShouldReturnFalse()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
174 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
175 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
176
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
177 // rubbish data
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
178 var unknownISBN = "X";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
179
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
180 var actual = library.IsBookAvailableByISBN(unknownISBN);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
181
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
182 Assert.IsFalse(actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
183 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
184
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
185 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
186
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
187 #region FindBooks
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
188
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
189 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
190 public void FindBooks_WhenNullSearchString_ShouldThrowArgumentNullExpection()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
191 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
192 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
193 Assert.Throws<ArgumentNullException>(() => library.FindBooks(null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
194 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
195
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
196
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
197 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
198 public void FindBooks_WithValidSearchTitleString_ShouldReturnCorrectNumberOfBooks()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
199 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
200 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
201
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
202 // good search string
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
203 var searchString = "Flies";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
204
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
205 // number of Lord of the Flies books expected
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
206 var expected = 3;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
207 var actual = library.FindBooks(searchString).Count;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
208
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
209 Assert.AreEqual(expected, actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
210 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
211
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
212 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
213 public void FindBooks_WithValidSearchTitleStringLowerCase_ShouldReturnCorrectNumberOfBooks()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
214 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
215 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
216
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
217 // good search string
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
218 var searchString = "flies";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
219
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
220 // number of Lord of the Flies books expected
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
221 var expected = 3;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
222 var actual = library.FindBooks(searchString).Count;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
223
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
224 Assert.AreEqual(expected, actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
225 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
226
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
227 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
228 public void FindBooks_WithValidSearchStringMultiplePublications_ShouldReturnCorrectNumberOfBooks()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
229 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
230 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
231
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
232 // good search string
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
233 var searchString = "e";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
234
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
235 // number of Lord of the Flies books expected
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
236 var expected = 10;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
237 var actual = library.FindBooks(searchString).Count;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
238
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
239 Assert.AreEqual(expected, actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
240 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
241
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
242 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
243 public void FindBooks_WithValidSearchAuthorString_ShouldReturnCorrectNumberOfBooks()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
244 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
245 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
246
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
247 // number of Brave New World books expected
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
248 var expected = 5;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
249 var searchString = "ldous";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
250
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
251 var actual = library.FindBooks(searchString).Count;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
252
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
253 Assert.AreEqual(expected, actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
254 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
255
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
256 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
257 public void FindBooks_WithInvalidSearchString_ShouldBeEmpty()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
258 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
259 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
260
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
261 // rubbish data
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
262 var searchString = "XYZ";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
263
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
264 var actual = library.FindBooks(searchString);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
265
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
266 Assert.IsEmpty(actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
267 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
268
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
269 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
270
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
271 #region GetBookById
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
272
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
273 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
274 public void GetBookById_WhenNullId_ShouldThrowArgumentNullExpection()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
275 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
276 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
277 Assert.Throws<ArgumentNullException>(() => library.GetBookById(null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
278 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
279
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
280 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
281 public void GetBookById_WhenValidId_ShouldReturnBook()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
282 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
283 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
284 var validBookId = "0000001";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
285 var book = library.GetBookById(validBookId);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
286 Assert.IsNotNull(book);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
287 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
288
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
289 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
290 public void GetBookById_WhenValidId_ShouldReturnNull()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
291 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
292 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
293 var invalidBookId = "X";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
294 var book = library.GetBookById(invalidBookId);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
295 Assert.IsNull(book);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
296 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
297
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
298 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
299
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
300 #region LendBook
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
301
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
302 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
303 public void LendBook_ShouldMakeBookInLibraryStockListUnavailable()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
304 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
305 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
306 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
307 var person = CreatePerson();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
308 var bookId = "0000001";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
309
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
310 // act
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
311 library.LendBook(person, bookId);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
312 var lookupBook = ((List<IStock>) library.StockList).Find(s => s.Book.Id == bookId);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
313 var actual = lookupBook.IsAvailable;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
314
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
315 // assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
316 Assert.IsFalse(actual);
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
317 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
318
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
319 private IPerson CreatePerson()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
320 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
321 var person = Person.Create("dummy", "dummy");
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
322 return person;
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
323 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
324
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
325 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
326 public void LendBook_WithNullPerson_ShouldThrowArgumentNullException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
327 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
328 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
329 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
330 var id = "dummy";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
331
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
332 // act & assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
333 Assert.Throws<ArgumentNullException>(() => library.LendBook(null, id));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
334 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
335
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
336 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
337 public void LendBook_WithNullBook_ShouldThrowArgumentNullException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
338 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
339 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
340 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
341 var person = CreatePerson();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
342
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
343 // act & assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
344 Assert.Throws<ArgumentNullException>(() => library.LendBook(person, null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
345 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
346
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
347 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
348 public void LendBook_WithNullBookAndNullPerson_ShouldThrowArgumentNullException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
349 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
350 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
351 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
352
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
353 // act & assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
354 Assert.Throws<ArgumentNullException>(() => library.LendBook(null, null));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
355 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
356
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
357 [Test]
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
358 public void LendBook_WithUnknownBook_ShouldThrowArgumentException()
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
359 {
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
360 //arrange
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
361 var library = CreateLibraryScenario();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
362 var person = CreatePerson();
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
363 var id = "dummy";
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
364
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
365 // act & assert
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
366 Assert.Throws<Exception>(
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
367 () => library.LendBook(person, id),
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
368 string.Format("Book id {0} is not in stock", id));
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
369 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
370
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
371 #endregion
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
372
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
373 }
aef06698d9e2 Added the library tests
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
374 }