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

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise", "Exercise\Exercise.csproj", "{EA98A53A-F8CD-4539-9E57-1FEF2D64F13A}"
EndProject
Expand All @@ -13,6 +13,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Documents", "Documents", "{
..\Documents\GitHubQuickStart.docx = ..\Documents\GitHubQuickStart.docx
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExerciseInterfaces", "ExerciseInterfaces\ExerciseInterfaces.csproj", "{B26A05D5-9CEC-4339-92DD-9B42DEE8C028}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Enumerables", "Enumerables\Enumerables.csproj", "{216AA6BC-F503-4172-8FD8-F1DDCC2788DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +31,14 @@ Global
{464FBD03-CA8B-4926-8F69-66726819DA02}.Debug|Any CPU.Build.0 = Debug|Any CPU
{464FBD03-CA8B-4926-8F69-66726819DA02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{464FBD03-CA8B-4926-8F69-66726819DA02}.Release|Any CPU.Build.0 = Release|Any CPU
{B26A05D5-9CEC-4339-92DD-9B42DEE8C028}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B26A05D5-9CEC-4339-92DD-9B42DEE8C028}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B26A05D5-9CEC-4339-92DD-9B42DEE8C028}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B26A05D5-9CEC-4339-92DD-9B42DEE8C028}.Release|Any CPU.Build.0 = Release|Any CPU
{216AA6BC-F503-4172-8FD8-F1DDCC2788DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{216AA6BC-F503-4172-8FD8-F1DDCC2788DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{216AA6BC-F503-4172-8FD8-F1DDCC2788DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{216AA6BC-F503-4172-8FD8-F1DDCC2788DD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
53 changes: 53 additions & 0 deletions DesignPatternsSolution/Enumerables/Enumerables.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{216AA6BC-F503-4172-8FD8-F1DDCC2788DD}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Enumerables</RootNamespace>
<AssemblyName>Enumerables</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Type.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
36 changes: 36 additions & 0 deletions DesignPatternsSolution/Enumerables/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Enumerables")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("VMS")]
[assembly: AssemblyProduct("Enumerables")]
[assembly: AssemblyCopyright("Copyright © VMS 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5d38fac3-f3ee-4942-8b8a-e460f8f53625")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
9 changes: 9 additions & 0 deletions DesignPatternsSolution/Enumerables/Type.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace ExerciseEnums
{
// Re-namned from ObjectType -- "Object" is implied...
public enum Type
{
Person,
Item
}
}
4 changes: 4 additions & 0 deletions DesignPatternsSolution/Execise.Tests/Execise.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ExerciseInterfaces\ExerciseInterfaces.csproj">
<Project>{b26a05d5-9cec-4339-92dd-9b42dee8c028}</Project>
<Name>ExerciseInterfaces</Name>
</ProjectReference>
<ProjectReference Include="..\Exercise\Exercise.csproj">
<Project>{ea98a53a-f8cd-4539-9e57-1fef2d64f13a}</Project>
<Name>Exercise</Name>
Expand Down
83 changes: 78 additions & 5 deletions DesignPatternsSolution/Execise.Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Exercise;
using System.Linq.Expressions;
using Exercise;
using ExerciseInterfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Execise.Tests
Expand All @@ -12,27 +14,98 @@ 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 lib1 = Library.Instance();
Library lib2 = Library.Instance();

Assert.AreSame(lib1, lib2);
}

//test that an book was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void BookShouldRegister()
{
int returnVal = Library.Instance().Register(new Book("Daryl Haase","Memoirs of Daryl", 2001, 4));

Assert.IsFalse(returnVal==-1);
}

//test that an customer was registered successfully by checking the returned Id value is not -1
[TestMethod]
public void CustomerShouldRegister()
{
int returnVal = Library.Instance().Register(new Customer("Daryl Haase","123 Street"));

Assert.IsFalse(returnVal == -1);
}

//test that a book can be borrowed
[TestMethod]
public void CanBorrowBook()
public void CanBorrowBook_OneOfThreeAvailable()
{
int quantity = 3;
int numberToBorrow = 1;
int numberBorrowed = 0;

//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.

}
//Run BorrowOne method of the Borrowable instance. Check that total amount was reduced by one.
ILibraryObject chickenLittle = new Book("Dunno ThinkItsAFable", "Chicken Little", 1910, quantity);
Borrowable chickenLittleBorrowable = new Borrowable(chickenLittle);

numberBorrowed = chickenLittleBorrowable.BorrowOne();

Assert.AreEqual(numberBorrowed, numberToBorrow);
Assert.AreEqual(chickenLittle.AvailableAmount, quantity - numberToBorrow);
}

//test that a book can be borrowed
[TestMethod]
public void CanBorrowBook_TwoOfThreeAvailable()
{
int quantity = 3;
int numberToBorrow = 2;
int numberBorrowed = 0;

ILibraryObject chickenLittle = new Book("Dunno ThinkItsAFable", "Chicken Little", 1910, quantity);
Borrowable chickenLittleBorrowable = new Borrowable(chickenLittle);

numberBorrowed = chickenLittleBorrowable.Borrow(numberToBorrow);

Assert.AreEqual(numberBorrowed, numberToBorrow);
Assert.AreEqual(chickenLittle.AvailableAmount, quantity - numberToBorrow);
}

//test that a book can be borrowed
[TestMethod]
public void CanBorrowBook_ThreeOfThreeAvailable()
{
int quantity = 3;
int numberToBorrow = 3;
int numberBorrowed = 0;

ILibraryObject chickenLittle = new Book("Dunno ThinkItsAFable", "Chicken Little", 1910, quantity);
Borrowable chickenLittleBorrowable = new Borrowable(chickenLittle);

numberBorrowed = chickenLittleBorrowable.Borrow(numberToBorrow);

Assert.AreEqual(numberBorrowed, numberToBorrow);
Assert.AreEqual(chickenLittle.AvailableAmount, quantity - numberToBorrow);
}

//test that we cannot borrow more books than the library has copies
[TestMethod]
public void CanBorrowBook_FourOfThreeAvailable()
{
int quantity = 3;
int numberToBorrow = 4;
int numberBorrowed = 0;

ILibraryObject chickenLittle = new Book("Dunno ThinkItsAFable", "Chicken Little", 1910, quantity);
Borrowable chickenLittleBorrowable = new Borrowable(chickenLittle);

numberBorrowed = chickenLittleBorrowable.Borrow(numberToBorrow);

Assert.AreEqual(numberBorrowed, 0);
Assert.AreEqual(chickenLittle.AvailableAmount, quantity);
}
}
}
15 changes: 15 additions & 0 deletions DesignPatternsSolution/Exercise/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ExerciseInterfaces;

namespace Exercise
{
// Relocated from LibraryItem.cs -- Poor practice to define a concrete class within the abstract class file
public class Book : LibraryItem, IBook
{
public Book(string author, string title, int year, int amount) : base(amount, year)
{
NameOrTitle = title;
Author = author;
}
public string Author { get; set; }
}
}
7 changes: 0 additions & 7 deletions DesignPatternsSolution/Exercise/BookBorrowable.cs

This file was deleted.

28 changes: 28 additions & 0 deletions DesignPatternsSolution/Exercise/Borrowable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using ExerciseInterfaces;

namespace Exercise
{
public class Borrowable : IBorrowable
{
private readonly ILibraryObject _decoratedLibraryObject;

public Borrowable(ILibraryObject libraryObject)
{
_decoratedLibraryObject = libraryObject;
}

public new int BorrowOne()
{
return this.Borrow(1);
}

public new int Borrow(int numberOfCopiesToBorrow)
{
if (_decoratedLibraryObject.AvailableAmount < numberOfCopiesToBorrow)
return 0;

_decoratedLibraryObject.AvailableAmount -= numberOfCopiesToBorrow;
return numberOfCopiesToBorrow;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
using System;
using ExerciseInterfaces;
using Type = ExerciseEnums.Type;

namespace Exercise
{
public class Customer : LibObject
public class Customer : LibraryObject, ICustomer
{
public string Address { get; set; }
public DateTime RegisteredAt { get; set; }

//Exercise states "Customer class - extending Person abstract class". There is no Person class -- it's just a property type of the LibraryObject
public Customer(string name, string addr)
{
NameOrTitle = name;
Address = addr;
RegisteredAt = DateTime.Now;
ObjType = ObjectType.Person;
Type = Type.Person;
}

public void SetId(int id)
{
ObjectId = id;
Id = id;
}
}
}
22 changes: 16 additions & 6 deletions DesignPatternsSolution/Exercise/Exercise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,29 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BookBorrowable.cs" />
<Compile Include="Item.cs" />
<Compile Include="LibObject.cs" />
<Compile Include="Book.cs" />
<Compile Include="Borrowable.cs" />
<Compile Include="LibraryItem.cs" />
<Compile Include="LibraryObject.cs" />
<Compile Include="Library.cs" />
<Compile Include="Person.cs" />
<Compile Include="Customer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Registration.cs" />
<Compile Include="Video.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Enumerables\Enumerables.csproj">
<Project>{216aa6bc-f503-4172-8fd8-f1ddcc2788dd}</Project>
<Name>Enumerables</Name>
</ProjectReference>
<ProjectReference Include="..\ExerciseInterfaces\ExerciseInterfaces.csproj">
<Project>{b26a05d5-9cec-4339-92dd-9b42dee8c028}</Project>
<Name>ExerciseInterfaces</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Loading