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
12 changes: 12 additions & 0 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,30 @@ 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 L1 = Library.getInstance();
var L2 = Library.getInstance();

Assert.AreEqual(L1, L2);
}

//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
Book B1 = new Book("Hello", "World", 2017, 10);
int result = RegistrationRepository.Register(B1);

Assert.AreNotEqual(-1, result);
}

//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
Customer C1 = new Customer("Troy", "Winnipeg");
int result = RegistrationRepository.Register(C1);

Assert.AreNotEqual(-1, result);
}

//test that a book can be borrowed
Expand Down
9 changes: 7 additions & 2 deletions DesignPatternsSolution/Exercise/BookBorrowable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace Exercise
{
public class BookBorrowable
public class BookBorrowable
{

BookBorrowable borrowable;

public void BorrowOne()
{

}
}
}
1 change: 1 addition & 0 deletions DesignPatternsSolution/Exercise/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public Item(int amount, int year)

public class Book : Item
{

public Book(string author, string title, int year, int amount) : base(amount, year)
{
NameOrTitle = title;
Expand Down
14 changes: 13 additions & 1 deletion DesignPatternsSolution/Exercise/LibObject.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
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()
{
Info = NameOrTitle,
AvailableAmount = AvailableAmount,
Id = ObjectId
};
}
}

public enum ObjectType
{
Person,
Item
}


}
11 changes: 5 additions & 6 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
public class Library
{
//implement Singleton to make sure only one library will exist
static Library instance = new Library();


private Library() { }

public static Library getInstance() { return instance; }
//Implement Register method by utilizing RegistrationRepository (complete missing parts)
public int Register()
public int Register(IRegistarable registarable)
{
// return RegistrationRepository.Register();

//dummy, just to compile
return 0;
return RegistrationRepository.Register(registarable);
}
}
}