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
6 changes: 3 additions & 3 deletions DesignPatternsSolution/DesignPatternsSolution.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise", "Exercise\Exercise.csproj", "{EA98A53A-F8CD-4539-9E57-1FEF2D64F13A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Execise.Tests", "Execise.Tests\Execise.Tests.csproj", "{464FBD03-CA8B-4926-8F69-66726819DA02}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise.Tests", "Execise.Tests\Exercise.Tests.csproj", "{464FBD03-CA8B-4926-8F69-66726819DA02}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{8C88EFFA-EC68-42ED-A482-A7B8964538E8}"
ProjectSection(SolutionItems) = preProject
Expand Down
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
26 changes: 23 additions & 3 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Exercise;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Execise.Tests
namespace Exercise.Tests
{
[TestClass]
public class UnitTests
Expand All @@ -12,18 +12,28 @@ 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 library1 = Library.getInstance();
Library library2 = Library.getInstance();

Assert.AreEqual(library1, library2);
}

//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
Book book = new Book("Mr. Smart", "My Book", 1985, 20);
int result = RegistrationRepository.Register(book);
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 customer = new Customer("John Doe", "123 Fourth St.");
int result = RegistrationRepository.Register(customer);
Assert.AreNotEqual(-1, result);
}

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

}

Book myBook = new Book("Glen Miller", "My Book", 1990, 50);

int oldCount = myBook.AvailableAmount;

Borrowable bookBorrowable = new Borrowable(null, new BorrowOne(myBook));
bookBorrowable.BorrowOne();

int newCount = myBook.AvailableAmount;

Assert.AreEqual(oldCount - 1, newCount);
}
}
}
45 changes: 43 additions & 2 deletions DesignPatternsSolution/Exercise/BookBorrowable.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
namespace Exercise
{
public class BookBorrowable
public abstract class ABorrowable
{

public virtual void BorrowOne() { }
protected BorrowOne borrowOneProcedure;
public ABorrowable(BorrowOne borrowOneProcedure)
{
this.borrowOneProcedure = borrowOneProcedure;
}
}

public class Borrowable : ABorrowable
{
private ABorrowable borrowableToExtend;

public Borrowable(ABorrowable borrowable, BorrowOne borrowOneProcedure)
: base(borrowOneProcedure)
{
borrowableToExtend = borrowable;
}

public override void BorrowOne()
{
if (borrowableToExtend != null)
{
borrowableToExtend.BorrowOne();
}

borrowOneProcedure.borrowOne();
}
}

public class BorrowOne
{
private LibObject libObject;

public BorrowOne(LibObject libObject)
{
this.libObject = libObject;
}

public void borrowOne()
{
this.libObject.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
14 changes: 12 additions & 2 deletions 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
{
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; }

public RegisteredObject GetRegistrationInfo()
{
RegisteredObject registeredObject = new RegisteredObject();
registeredObject.Info = this.NameOrTitle;
registeredObject.AvailableAmount = this.AvailableAmount;

return registeredObject;
}
}
}
9 changes: 7 additions & 2 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
{
public class Library
{
//implement Singleton to make sure only one library will exist
private static Library library = new Library();


private Library() { }

public static Library getInstance()
{
return library;
}

//Implement Register method by utilizing RegistrationRepository (complete missing parts)
public int Register()
Expand Down
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()
{
RegisteredObject registeredObject = new RegisteredObject();
registeredObject.Info = this.NameOrTitle;
registeredObject.AvailableAmount = this.AvailableAmount;

return registeredObject;
}
}
}