# HG changeset patch # User adminsh@apollo # Date 1333492172 -3600 # Node ID dbd242eb9c33c34ec74b6ad4b93a7f4557a3fe9a # Parent 64c89891d7b68aa14d569c045bfd428167335d02 Initial wave of TDD development diff -r 64c89891d7b6 -r dbd242eb9c33 Library/Library.sln --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/Library.sln Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,26 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibrarySystem", "LibrarySystem\LibrarySystem.csproj", "{36FBA53C-CC81-4670-9151-5AD0CED4F235}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibrarySystem.Tests", "LibrarySystem.Tests\LibrarySystem.Tests.csproj", "{FD4E2D24-E13C-431F-9679-70A5A6753A15}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {36FBA53C-CC81-4670-9151-5AD0CED4F235}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36FBA53C-CC81-4670-9151-5AD0CED4F235}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36FBA53C-CC81-4670-9151-5AD0CED4F235}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36FBA53C-CC81-4670-9151-5AD0CED4F235}.Release|Any CPU.Build.0 = Release|Any CPU + {FD4E2D24-E13C-431F-9679-70A5A6753A15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FD4E2D24-E13C-431F-9679-70A5A6753A15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FD4E2D24-E13C-431F-9679-70A5A6753A15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FD4E2D24-E13C-431F-9679-70A5A6753A15}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem.Tests/LibrarySystem.Tests.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem.Tests/LibrarySystem.Tests.csproj Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,61 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {FD4E2D24-E13C-431F-9679-70A5A6753A15} + Library + Properties + LibrarySystem.Tests + LibrarySystem.Tests + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\NUnit.2.6.0.12054\lib\nunit.framework.dll + + + + + + + + + + + {36FBA53C-CC81-4670-9151-5AD0CED4F235} + LibrarySystem + + + + + + + + \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem.Tests/LibrarySystemTests.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem.Tests/LibrarySystemTests.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,204 @@ +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); + } + } +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem.Tests/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem.Tests/Properties/AssemblyInfo.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("LibrarySystem.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LibrarySystem.Tests")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4608a558-cff8-4aa0-a05d-31f9829f733b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem.Tests/packages.config --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem.Tests/packages.config Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Core/Book.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Core/Book.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using LibrarySystem.Interfaces; + +namespace LibrarySystem.Core +{ + public class Book : IBook + { + public string Author { get; set; } + public string ISBN { get; set; } + public IPublisher Publisher { get; set; } + public string Title { get; set; } + public string Id { get; set; } + public decimal CurrentFee { get; set; } + public IList RentalHistory { get; set; } + + public Book(IPublication publication) + { + Author = publication.Author; + ISBN = publication.ISBN; + Title = publication.Title; + Publisher = publication.Publisher; + RentalHistory = new List(0); + } + } +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Core/Library.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Core/Library.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using System.Linq; +using LibrarySystem.Interfaces; + +namespace LibrarySystem.Core +{ + public class Library : ILibrary + { + public string Location { get; set; } + public IList StockList { get; set; } + + public Library() + { + StockList = new List(0); + } + + public void AddStock(params IBook[] books) + { + var stock = new List(StockList.Count + books.Length); + + stock.AddRange(StockList); + + foreach (var book in books) + { + stock.Add(new Stock() { Book = book, IsAvailable = true }); + } + + StockList = stock; + } + + public bool IsBookAvailableByISBN(string isbn) + { + var qry = from books in StockList + where books.Book.ISBN == isbn + & books.IsAvailable + select books.IsAvailable; + + return qry.FirstOrDefault(); + } + + public IList FindBooks(string searchString) + { + searchString = searchString.ToLower(); + + var qry = from books in StockList + where books.Book.Title.ToLower().Contains(searchString) + || books.Book.Author.ToLower().Contains(searchString) + select books; + + return qry.ToList(); + } + + public void LendBook(IPerson person, IBook book) + { + throw new System.NotImplementedException(); + } + } +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Core/Publication.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Core/Publication.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,13 @@ +using LibrarySystem.Interfaces; + +namespace LibrarySystem.Core +{ + public class Publication : IPublication + { + public string Author { get; set; } + public string ISBN { get; set; } + public IPublisher Publisher { get; set; } + public string Title { get; set; } + } + +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Core/Publisher.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Core/Publisher.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,9 @@ +using LibrarySystem.Interfaces; + +namespace LibrarySystem.Core +{ + public class Publisher : IPublisher + { + public string Name { get; set; } + } +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Core/Rental.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Core/Rental.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,15 @@ +using System; +using LibrarySystem.Interfaces; + +namespace LibrarySystem.Core +{ + public class Rental : IRental + { + public DateTime ActualCheckIn { get; set; } + public IBook Book { get; set; } + public DateTime CheckOut { get; set; } + public DateTime ExpectedCheckIn { get; set; } + public decimal Fee { get; set; } + public IPerson Person { get; set; } + } +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Core/Stock.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Core/Stock.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,10 @@ +using LibrarySystem.Interfaces; + +namespace LibrarySystem.Core +{ + public class Stock : IStock + { + public bool IsAvailable { get; set; } + public IBook Book { get; set; } + } +} diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Diagrams/Overview.cd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Diagrams/Overview.cd Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,53 @@ + + + + + + AIAAAAAAAAAABABgACAAAAAAAgAAAAAAAAAAAAAAAAA= + Interfaces\IRental.cs + + + + + + AAAAAAAAAQAAAEAAiAAAAAAAAAAAAAAAAAAAAAAAAAA= + Interfaces\IPublication.cs + + + + + + AAACAAAAABAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAA= + Interfaces\IBook.cs + + + + + + AAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAIAAAAA= + Interfaces\IStock.cs + + + + + + AAAAAAAAAAAAAAAAAAIAgAAEAAAAAAAAAAIAABAAAgA= + Interfaces\ILibrary.cs + + + + + + AAAAAAAABAAAAAAAAAAAAAQAAAAAAIACAAAAAAAAAAA= + Interfaces\IPerson.cs + + + + + + AAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAA= + Interfaces\IPublisher.cs + + + + \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/IBook.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/IBook.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace LibrarySystem.Interfaces +{ + public interface IBook : IPublication + { + string Id { get; set; } + decimal CurrentFee { get; set; } + IList RentalHistory { get; set; } + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/ILibrary.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/ILibrary.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace LibrarySystem.Interfaces +{ + public interface ILibrary + { + string Location { get; set; } + IList StockList { get; set; } + + void AddStock(params IBook[] books); + bool IsBookAvailableByISBN(string isbn); + IList FindBooks(string searchString); + void LendBook(IPerson person, IBook book); + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/IPerson.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/IPerson.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using LibrarySystem.Core; + +namespace LibrarySystem.Interfaces +{ + public interface IPerson + { + string Address { get; set; } + decimal CurrentBalance { get; set; } + IList RentalHistory { get; set; } + string Name { get; set; } + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/IPublication.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/IPublication.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,10 @@ +namespace LibrarySystem.Interfaces +{ + public interface IPublication + { + string Author { get; set; } + string ISBN { get; set; } + IPublisher Publisher { get; set; } + string Title { get; set; } + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/IPublisher.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/IPublisher.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,7 @@ +namespace LibrarySystem.Interfaces +{ + public interface IPublisher + { + string Name { get; set; } + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/IRental.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/IRental.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,14 @@ +using System; + +namespace LibrarySystem.Interfaces +{ + public interface IRental + { + DateTime ActualCheckIn { get; set; } + IBook Book { get; set; } + DateTime CheckOut { get; set; } + DateTime ExpectedCheckIn { get; set; } + Decimal Fee { get; set; } + IPerson Person { get; set; } + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Interfaces/IStock.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Interfaces/IStock.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,8 @@ +namespace LibrarySystem.Interfaces +{ + public interface IStock + { + bool IsAvailable { get; set; } + IBook Book { get; set; } + } +} \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/LibrarySystem.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/LibrarySystem.csproj Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,64 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {36FBA53C-CC81-4670-9151-5AD0CED4F235} + Library + Properties + LibrarySystem + LibrarySystem + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 64c89891d7b6 -r dbd242eb9c33 Library/LibrarySystem/Properties/AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Library/LibrarySystem/Properties/AssemblyInfo.cs Tue Apr 03 23:29:32 2012 +0100 @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Library")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Library")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("17052e0b-9bab-4d0d-a13a-83f85843bea2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]