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
11 changes: 11 additions & 0 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
var lib1 = Library.getInstance();
var lib2 = Library.getInstance();

Assert.AreEqual(lib1, lib2);

}

//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
var lib = Library.getInstance();
var book = new Book("one","wolf",1999,1);
Assert.AreNotEqual(-1,lib.Register(book));
}

//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
var lib = Library.getInstance();
var cust = new Customer("Bad Man", "123 Street");
Assert.AreNotEqual(-1, lib.Register(cust));
}

//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
7 changes: 6 additions & 1 deletion DesignPatternsSolution/Exercise/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ 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 };
}
}
}
14 changes: 10 additions & 4 deletions DesignPatternsSolution/Exercise/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
public class Library
{
//implement Singleton to make sure only one library will exist
static Library instance = new Library();

private Library() { }

public static Library getInstance() { return instance; }
// private IRegistarable _registerObject;


//Implement Register method by utilizing RegistrationRepository (complete missing parts)
public int Register()
//Implement Register method by utilizing RegistrationRepository ()
public int Register(IRegistarable _registerObject)
{
// return RegistrationRepository.Register();

return RegistrationRepository.Register(_registerObject);

//dummy, just to compile
return 0;
//return 0;
}
}
}
7 changes: 6 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,10 @@ public void SetId(int id)
{
ObjectId = id;
}

public RegisteredObject GetRegistrationInfo()
{
return new RegisteredObject() { AvailableAmount = 1, Info = NameOrTitle };
}
}
}
5 changes: 5 additions & 0 deletions DesignPatternsSolution/Exercise/Registration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static int DeleteAllRegisteredItems()

return size;
}


}

public class RegisteredObject
Expand All @@ -56,4 +58,7 @@ public override string ToString()
return Info + " " + "Available: " + AvailableAmount;
}
}



}