Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
}
}
22 changes: 18 additions & 4 deletions DesignPatternsSolution/Exercise/BookBorrowable.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
32 changes: 20 additions & 12 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}