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
3 changes: 2 additions & 1 deletion DesignPatternsSolution/Execise.Tests/Execise.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Execise.Tests</RootNamespace>
<AssemblyName>Execise.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
14 changes: 14 additions & 0 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
17 changes: 15 additions & 2 deletions DesignPatternsSolution/Exercise/BookBorrowable.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
3 changes: 2 additions & 1 deletion DesignPatternsSolution/Exercise/Exercise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Exercise</RootNamespace>
<AssemblyName>Exercise</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
12 changes: 11 additions & 1 deletion DesignPatternsSolution/Exercise/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
12 changes: 7 additions & 5 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
11 changes: 10 additions & 1 deletion DesignPatternsSolution/Exercise/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@

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)
{
NameOrTitle = name;
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;
}

}
}