Mercurial > silverbladetech
view Library/LibrarySystem.Tests/LibrarySystemTests.cs @ 42:0d4aff4f699d
Enabled nuget package restore on build
author | adminsh@apollo |
---|---|
date | Tue, 03 Apr 2012 23:32:40 +0100 |
parents | dbd242eb9c33 |
children |
line wrap: on
line source
using LibrarySystem.Core; using LibrarySystem.Interfaces; using NUnit.Framework; namespace LibrarySystem.Tests { [TestFixture] public class LibraryTests { /* * Factory that creates: * Library with 10 books (2 x Lord of the Flies, 3 x 1984, 5 x Brave New World) */ private ILibrary CreateScenario() { #region Publisher IPublisher penguin = new Publisher() {Name = "Penguin"}; #endregion #region Publications IPublication lordOfTheFlies = new Publication() { Author = "William Golding", ISBN = "0140283331", Publisher = penguin, Title = "Lord of the Flies" }; IPublication nineteenEightyFour = new Publication() { Author = "George Orwell", ISBN = "0452284236", Title = "Nineteen Eighty-Four" }; IPublication braveNewWorld = new Publication() { Author = "Aldous Huxley", ISBN = "0060850523", Title = "Brave New World" }; #endregion #region Books // Lord of the flies IBook book1 = new Book(lordOfTheFlies) {Id = "0000001", CurrentFee = 1.25m}; IBook book2 = new Book(lordOfTheFlies) {Id = "0000002", CurrentFee = 1.25m}; IBook book3 = new Book(lordOfTheFlies) {Id = "0000003", CurrentFee = 1.25m}; // 1984 IBook book4 = new Book(nineteenEightyFour) {Id = "0000004", CurrentFee = 1.5m}; IBook book5 = new Book(nineteenEightyFour) {Id = "0000005", CurrentFee = 1.5m}; // Brave new world IBook book6 = new Book(braveNewWorld) {Id = "0000006", CurrentFee = 1.8m}; IBook book7 = new Book(braveNewWorld) {Id = "0000007", CurrentFee = 1.8m}; IBook book8 = new Book(braveNewWorld) {Id = "0000008", CurrentFee = 1.8m}; IBook book9 = new Book(braveNewWorld) {Id = "0000009", CurrentFee = 1.8m}; IBook book10 = new Book(braveNewWorld) {Id = "0000010", CurrentFee = 1.8m}; #endregion #region Library ILibrary library = new Library(); library.Location = "Leicester Square"; library.AddStock(book1, book2, book3, book4, book5, book6, book7, book8, book9, book10); #endregion return library; } [Test] public void AddStockShouldIncreaseStockListCountByOne() { //arrange var library = new Library(); var expected = library.StockList.Count + 1; var dummyBook = new Book(new Publication()); //act library.AddStock(dummyBook); var actual = library.StockList.Count; //assert Assert.AreEqual(expected, actual); } [Test] public void SearchForAvailableBookByIBSNShouldReturnTrue() { var library = CreateScenario(); // Lord of the flies var validISBN = "0140283331"; var actual = library.IsBookAvailableByISBN(validISBN); Assert.IsTrue(actual); } [Test] public void SearchForUnavailableBookByIBSNShouldReturnFalse() { var library = CreateScenario(); // rubbish data var invalidISBN = "X"; var actual = library.IsBookAvailableByISBN(invalidISBN); Assert.IsFalse(actual); } [Test] public void FindBooksByValidSearchTitleString() { var library = CreateScenario(); // good search string var searchString = "Flies"; // number of Lord of the Flies books expected var expected = 3; var actual = library.FindBooks(searchString).Count; Assert.AreEqual(expected, actual); } [Test] public void FindBooksByValidSearchTitleStringLowerCase() { var library = CreateScenario(); // good search string var searchString = "flies"; // number of Lord of the Flies books expected var expected = 3; var actual = library.FindBooks(searchString).Count; Assert.AreEqual(expected, actual); } [Test] public void FindBooksByValidSearchStringMultiplePublications() { var library = CreateScenario(); // good search string var searchString = "e"; // number of Lord of the Flies books expected var expected = 10; var actual = library.FindBooks(searchString).Count; Assert.AreEqual(expected, actual); } [Test] public void FindBooksByValidSearchAuthorString() { var library = CreateScenario(); // number of Brave New World books expected var expected = 5; var searchString = "ldous"; var actual = library.FindBooks(searchString).Count; Assert.AreEqual(expected, actual); } [Test] public void FindBooksByInvalidSearchString() { var library = CreateScenario(); // rubbish data var searchString = "XYZ"; var actual = library.FindBooks(searchString); Assert.IsEmpty(actual); } } }