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
22 changes: 19 additions & 3 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,30 @@ public class UnitTests
[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
var libraryInstance1 = Library.GetInstance();
var libraryInstance2 = Library.GetInstance();

Assert.AreSame(libraryInstance1, libraryInstance2);
}

//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
var book = new Book("Jason Mark","Clean Code",1997,25);
var response = RegistrationRepository.Register(book);

Assert.IsTrue(response > -1);
}

//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
var customer = new Customer("Jason Mark","386 Broadway");
var response = RegistrationRepository.Register(customer);

Assert.IsTrue(response > -1);
}

//test that a book can be borrowed
Expand All @@ -32,7 +42,13 @@ 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.

int bookInInventory = 25;
var book = new Book("Jason Mark", "Clean Code", 1997, bookInInventory);
var borrowable = new BookBorrowable(book);

borrowable.BorrowBook();
Assert.IsTrue(book.AvailableAmount == bookInInventory - 1);

}
}
}
20 changes: 18 additions & 2 deletions DesignPatternsSolution/Exercise/BookBorrowable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
namespace Exercise
{
public class BookBorrowable
public class BookBorrowable : Book
{

private Book Book { get; set; }

public BookBorrowable(Book canBorrow) : base(canBorrow.Author, canBorrow.NameOrTitle, canBorrow.YearCreated, canBorrow.AvailableAmount)
{
Book = canBorrow;
}

public bool BorrowBook()
{
if (Book.AvailableAmount > 0)
{
Book.AvailableAmount--;
return true;
}

return false;
}
}
}
12 changes: 11 additions & 1 deletion DesignPatternsSolution/Exercise/LibObject.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
namespace Exercise
{
public abstract class LibObject
public abstract class LibObject : IRegistarable
{
public int ObjectId { get; set; }
public int AvailableAmount { get; set; }
public string NameOrTitle { get; set; }
public ObjectType ObjType { get; set; }
public int YearCreated { get; set; }

public RegisteredObject GetRegistrationInfo()
{
return new RegisteredObject
{
AvailableAmount = AvailableAmount,
Id = ObjectId,
Info = NameOrTitle
};
}
}

public enum ObjectType
Expand Down
9 changes: 8 additions & 1 deletion DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@
public class Library
{
//implement Singleton to make sure only one library will exist
private static Library Instance { get; set; }



private Library() { Instance = new Library(); }

public static Library GetInstance()
{
return Instance;
}

//Implement Register method by utilizing RegistrationRepository (complete missing parts)
public int Register()
Expand Down