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
24 changes: 20 additions & 4 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ 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
Library lib1 = Library.Instance;
Library lib2 = Library.Instance;
Assert.ReferenceEquals(lib1, lib2);
}

//test that an book was registered successfully by checking the returned Id value is not -1
//test that a book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
Library lib1 = Library.Instance;
Book book1 = new Book("I am Great", "Donald Trump", 2017, 19);
int result = lib1.Register(book1);
Assert.AreNotEqual(result, -1);
}

//test that an customer was registered successfully by checking the returned Id value is not -1
//test that a customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
Library lib1 = Library.Instance;
Customer cust1 = new Customer("Daffy Duck", "123 Dippy Lane, Disneyland, CA");
int result = lib1.Register(cust1);
Assert.AreNotEqual(result, -1);
}

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

}
Library lib1 = Library.Instance;
Book book1 = new Book("I am Great", "Donald Trump", 2017, 19);
int result = lib1.Register(book1);

Assert.AreNotEqual(result, -1);

}
}
}
2 changes: 1 addition & 1 deletion DesignPatternsSolution/Exercise/BookBorrowable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public class BookBorrowable
{

// find book in Registration Repository as class RegisteredObject and return Available Amount?
}
}
23 changes: 21 additions & 2 deletions DesignPatternsSolution/Exercise/Item.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
namespace Exercise
{
public abstract class Item : LibObject
public abstract class Item : LibObject, IRegistarable
{
public Item(int amount, int year)
{
AvailableAmount = amount;
ObjType = ObjectType.Item;
YearCreated = year;
}

//public int Register()
//{
// return 0;
//}

public abstract RegisteredObject GetRegistrationInfo();

}

public class Book : Item
{
public Book(string author, string title, int year, int amount) : base(amount, year)
public Book(string author, string title, int year, int amount)
: base(amount, year)
{
NameOrTitle = title;
Author = author;
}
public string Author { get; set; }

//my code
public override RegisteredObject GetRegistrationInfo()
{
return new RegisteredObject
{
Info = "Book Name: " + NameOrTitle + " , Author: " + Author + " Year: " + YearCreated,
AvailableAmount = AvailableAmount
};
}
}
}
24 changes: 19 additions & 5 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
namespace Exercise
{
public class Library
public sealed class Library
{
//implement Singleton to make sure only one library will exist
private static Library instance;
private Library() { }



public static Library Instance
{
get
{
if (instance == null)
{
instance = new Library();
}
return instance;
}
}

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

//dummy, just to compile
return 0;
//return 0;
}
}
}
11 changes: 10 additions & 1 deletion DesignPatternsSolution/Exercise/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Exercise
{
public class Customer : LibObject
public class Customer : LibObject, IRegistarable
{
public string Address { get; set; }
public DateTime RegisteredAt { get; set; }
Expand All @@ -19,5 +19,14 @@ public void SetId(int id)
{
ObjectId = id;
}

public RegisteredObject GetRegistrationInfo()
{
return new RegisteredObject
{
Info = "Customer Name: " + NameOrTitle + " , Address: " + Address + " Date Registered: " + RegisteredAt,
AvailableAmount = AvailableAmount
};
}
}
}