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
12 changes: 11 additions & 1 deletion DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Exercise;
using System;
using Exercise;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Execise.Tests
Expand All @@ -12,18 +13,27 @@ 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 a = Library.getLibInstance();
var b = Library.getLibInstance();
var bSameObject = ReferenceEquals(a, b);
Assert.AreEqual(true, bSameObject, "Objects returned are different");
}

//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
var registeredId = RegistrationRepository.Register(new Book("bill", "bill's book", 1995, 5));
Assert.AreNotEqual(-1, registeredId);

}

//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
var registeredId = RegistrationRepository.Register(new Customer("bill", "bill's addr"));
Assert.AreNotEqual(-1, registeredId);
}

//test that a book can be borrowed
Expand Down
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
31 changes: 30 additions & 1 deletion DesignPatternsSolution/Exercise/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,42 @@ 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)
{
NameOrTitle = title;
Author = author;
}
public string Author { get; set; }

public RegisteredObject GetRegistrationInfo()
{
return new RegisteredObject()
{
AvailableAmount = AvailableAmount,
Info = NameOrTitle
};
}
}

public class Video : Item, IRegistarable
{
public Video(string director, string title, int year, int amount)
: base(amount, year)
{
NameOrTitle = title;
Director = director;
}
public string Director { get; set; }

public RegisteredObject GetRegistrationInfo()
{
return new RegisteredObject()
{
AvailableAmount = AvailableAmount,
Info = NameOrTitle
};
}
}
}
22 changes: 15 additions & 7 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
namespace Exercise
using System.Runtime.Remoting.Messaging;

namespace Exercise
{
public class Library
{
//implement Singleton to make sure only one library will exist
private static Library libInstance = new Library();


private Library()
{
}

//Implement Register method by utilizing RegistrationRepository (complete missing parts)
public int Register()
public static Library getLibInstance()
{
// return RegistrationRepository.Register();
return libInstance;
}


//dummy, just to compile
return 0;
//Implement Register method by utilizing RegistrationRepository (complete missing parts)
public int Register(IRegistarable libObject)
{
return RegistrationRepository.Register(libObject);
}
}
}
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()
{
AvailableAmount = 1,
Info = NameOrTitle
};
}
}
}