diff --git a/DesignPatternsSolution/Execise.Tests/Execise.Tests.csproj b/DesignPatternsSolution/Execise.Tests/Execise.Tests.csproj
index 71e68ac..4f78f0d 100644
--- a/DesignPatternsSolution/Execise.Tests/Execise.Tests.csproj
+++ b/DesignPatternsSolution/Execise.Tests/Execise.Tests.csproj
@@ -8,7 +8,7 @@
Properties
Execise.Tests
Execise.Tests
- v4.5.2
+ v4.5
512
{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
10.0
@@ -16,6 +16,7 @@
$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
False
UnitTest
+
true
diff --git a/DesignPatternsSolution/Execise.Tests/UnitTests.cs b/DesignPatternsSolution/Execise.Tests/UnitTests.cs
index 0a3b80e..cc1f627 100644
--- a/DesignPatternsSolution/Execise.Tests/UnitTests.cs
+++ b/DesignPatternsSolution/Execise.Tests/UnitTests.cs
@@ -12,24 +12,38 @@ 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 firstInstanceLibrary = Library.getLibrary();
+ var secondInstanceLibrary = Library.getLibrary();
+
+ Assert.AreSame(firstInstanceLibrary, secondInstanceLibrary);
+
}
//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
+ var library = Library.getLibrary();
+ var value = library.Register(new Book("Bob", "The Book", 1922, 10));
+ Assert.AreNotEqual(-1, value);
}
//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
+ var library = Library.getLibrary();
+ var value = library.Register(new Customer("bob", "200 street"));
+ Assert.AreNotEqual(-1, value);
}
//test that a book can be borrowed
[TestMethod]
public void CanBorrowBook()
{
+ var books = new BookBorrowable("bob", "The book", 1822, 8);
+ books.BorrowOne();
+ Assert.AreEqual(7, books.getAvailableAmount());
//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.
diff --git a/DesignPatternsSolution/Exercise/BookBorrowable.cs b/DesignPatternsSolution/Exercise/BookBorrowable.cs
index 21bd9cf..d68d276 100644
--- a/DesignPatternsSolution/Exercise/BookBorrowable.cs
+++ b/DesignPatternsSolution/Exercise/BookBorrowable.cs
@@ -1,7 +1,20 @@
namespace Exercise
{
- public class BookBorrowable
+ public class BookBorrowable: Book
{
-
+ public BookBorrowable(string author, string title, int year, int amount): base(author, title, year, amount)
+ {
+
+ }
+
+ public void BorrowOne() {
+ this.AvailableAmount--;
+ }
+
+ public int getAvailableAmount()
+ {
+ return this.AvailableAmount;
+ }
}
+
}
diff --git a/DesignPatternsSolution/Exercise/Exercise.csproj b/DesignPatternsSolution/Exercise/Exercise.csproj
index d2cc582..87a49ae 100644
--- a/DesignPatternsSolution/Exercise/Exercise.csproj
+++ b/DesignPatternsSolution/Exercise/Exercise.csproj
@@ -9,9 +9,10 @@
Properties
Exercise
Exercise
- v4.5.2
+ v4.5
512
true
+
AnyCPU
diff --git a/DesignPatternsSolution/Exercise/Item.cs b/DesignPatternsSolution/Exercise/Item.cs
index 92c21e1..5c3dee5 100644
--- a/DesignPatternsSolution/Exercise/Item.cs
+++ b/DesignPatternsSolution/Exercise/Item.cs
@@ -10,13 +10,23 @@ public Item(int amount, int year)
}
}
- public class Book : Item
+ public class Book : Item, IRegistarable
{
+ private RegisteredObject registeredObject;
+
public Book(string author, string title, int year, int amount) : base(amount, year)
{
NameOrTitle = title;
Author = author;
+ registeredObject = new RegisteredObject();
+ registeredObject.Info = "Book";
+ registeredObject.AvailableAmount = amount;
}
public string Author { get; set; }
+
+ public RegisteredObject GetRegistrationInfo()
+ {
+ return registeredObject;
+ }
}
}
diff --git a/DesignPatternsSolution/Exercise/Library.cs b/DesignPatternsSolution/Exercise/Library.cs
index 1d9dde4..38c6fac 100644
--- a/DesignPatternsSolution/Exercise/Library.cs
+++ b/DesignPatternsSolution/Exercise/Library.cs
@@ -3,16 +3,18 @@
public class Library
{
//implement Singleton to make sure only one library will exist
+ static Library library = new Library();
+
+ private Library() { }
+
+ public static Library getLibrary() { return library; }
//Implement Register method by utilizing RegistrationRepository (complete missing parts)
- public int Register()
+ public int Register(IRegistarable register)
{
- // return RegistrationRepository.Register();
-
- //dummy, just to compile
- return 0;
+ return RegistrationRepository.Register(register);
}
}
}
diff --git a/DesignPatternsSolution/Exercise/Person.cs b/DesignPatternsSolution/Exercise/Person.cs
index 2c2ed21..addf5c1 100644
--- a/DesignPatternsSolution/Exercise/Person.cs
+++ b/DesignPatternsSolution/Exercise/Person.cs
@@ -2,10 +2,11 @@
namespace Exercise
{
- public class Customer : LibObject
+ public class Customer : LibObject, IRegistarable
{
public string Address { get; set; }
public DateTime RegisteredAt { get; set; }
+ private RegisteredObject registeredObject;
public Customer(string name, string addr)
{
@@ -13,11 +14,19 @@ public Customer(string name, string addr)
Address = addr;
RegisteredAt = DateTime.Now;
ObjType = ObjectType.Person;
+ registeredObject = new RegisteredObject();
+ registeredObject.Info = "information";
}
public void SetId(int id)
{
ObjectId = id;
}
+
+ public RegisteredObject GetRegistrationInfo()
+ {
+ return registeredObject;
+ }
+
}
}