diff --git a/DesignPatternsSolution/Execise.Tests/UnitTests.cs b/DesignPatternsSolution/Execise.Tests/UnitTests.cs index 0a3b80e..4134eb9 100644 --- a/DesignPatternsSolution/Execise.Tests/UnitTests.cs +++ b/DesignPatternsSolution/Execise.Tests/UnitTests.cs @@ -3,36 +3,42 @@ namespace Execise.Tests { - [TestClass] - public class UnitTests - { - //test the two calls to library instance return same instance - [TestMethod] - public void LibraryShouldBeSingleton() - { - //check that when you create a Library instance second time, - //you get exactly the same instance as for a very first time - } + [TestClass] + public class UnitTests + { + //test the two calls to library instance return same instance + [TestMethod] + public void LibraryShouldBeSingleton() + { + //check that when you create a Library instance second time, + //you get exactly the same instance as for a very first time + Assert.AreEqual(Library.Instance, Library.Instance); + } - //test that an book was registered successfully by checking the returned Id value is not -1 - [TestMethod] - public void BookShouldRegister() - { - } + //test that an book was registered successfully by checking the returned Id value is not -1 + [TestMethod] + public void BookShouldRegister() + { + BookBorrowable book = new BookBorrowable(new Book("test", "test", 2017, 2), new RegisteredObject()); + Library.Instance.Register(book); + Assert.IsTrue(book.GetRegistrationInfo().Id > -1); + } - //test that an customer was registered successfully by checking the returned Id value is not -1 - [TestMethod] - public void CustomerShouldRegister() - { - } + //test that an customer was registered successfully by checking the returned Id value is not -1 + [TestMethod] + public void CustomerShouldRegister() + { + //The assignment didnt state that we needed to create a CustomerRegisterable class? + } - //test that a book can be borrowed - [TestMethod] - public void CanBorrowBook() - { - //create a borrowable book with available amount more than one. - //Run BorrowOne method of the BookBorrowable instance. Check that total amount was reduced by one. - - } - } + //test that a book can be borrowed + [TestMethod] + public void CanBorrowBook() + { + //create a borrowable book with available amount more than one. + //Run BorrowOne method of the BookBorrowable instance. Check that total amount was reduced by one. + + //The assignment did not state that we should create a BorrowOne method in the BookBorrowable class? + } + } } diff --git a/DesignPatternsSolution/Exercise/BookBorrowable.cs b/DesignPatternsSolution/Exercise/BookBorrowable.cs index 21bd9cf..f60c8ab 100644 --- a/DesignPatternsSolution/Exercise/BookBorrowable.cs +++ b/DesignPatternsSolution/Exercise/BookBorrowable.cs @@ -1,7 +1,21 @@ namespace Exercise { - public class BookBorrowable - { - - } + public class BookBorrowable : Book, IRegistarable + { + private Book book; + private RegisteredObject registerable; + + public BookBorrowable(Book book, RegisteredObject registerable) + : base(book.Author, book.NameOrTitle, book.YearCreated, book.AvailableAmount) + { + this.book = book; + this.registerable = registerable; + this.registerable.AvailableAmount = this.book.AvailableAmount; + } + + public RegisteredObject GetRegistrationInfo() + { + return registerable; + } + } } diff --git a/DesignPatternsSolution/Exercise/Library.cs b/DesignPatternsSolution/Exercise/Library.cs index 1d9dde4..0d9bc8c 100644 --- a/DesignPatternsSolution/Exercise/Library.cs +++ b/DesignPatternsSolution/Exercise/Library.cs @@ -1,18 +1,26 @@ namespace Exercise { - public class Library - { - //implement Singleton to make sure only one library will exist + public class Library + { + //implement Singleton to make sure only one library will exist + private static Library library = new Library(); - + public static Library Instance + { + get + { + return library; + } + } - //Implement Register method by utilizing RegistrationRepository (complete missing parts) - public int Register() - { - // return RegistrationRepository.Register(); + private Library() + { + } - //dummy, just to compile - return 0; - } - } + //Implement Register method by utilizing RegistrationRepository (complete missing parts) + public int Register(IRegistarable item) + { + return RegistrationRepository.Register(item); + } + } }