From 8c137f229c36a777ead5cacb3350cb8692646292 Mon Sep 17 00:00:00 2001 From: "mo.khan" Date: Sat, 5 Jan 2008 07:16:52 +0000 Subject: git-svn-id: http://mokhan.googlecode.com/svn/trunk@9 a0a4a051-f042-0410-9e78-9fae330bdb64 --- .../test/DesignPatterns.Test/BankAccountTest.cs | 53 ++++++++++++++++++ .../DesignPatterns.Test/DesignPatterns.Test.csproj | 63 ++++++++++++++++++++++ .../src/test/DesignPatterns.Test/MoneyTest.cs | 52 ++++++++++++++++++ .../test/DesignPatterns.Test/PosTerminalTest.cs | 17 ++++++ .../DesignPatterns.Test/Properties/AssemblyInfo.cs | 35 ++++++++++++ 5 files changed, 220 insertions(+) create mode 100644 DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs create mode 100644 DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj create mode 100644 DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs create mode 100644 DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs create mode 100644 DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs (limited to 'DesignPatterns/src/test/DesignPatterns.Test') diff --git a/DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs b/DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs new file mode 100644 index 0000000..0c7357a --- /dev/null +++ b/DesignPatterns/src/test/DesignPatterns.Test/BankAccountTest.cs @@ -0,0 +1,53 @@ +using System; +using DesignPatterns.Test; +using MbUnit.Framework; + +namespace DesignPatterns.Factory { + [TestFixture] + public class BankAccountTest { + [Test] + public void Should_Create_A_Cibc_Chequing_Account( ) { + IBank bank = new CibcBank( ); + IBankAccountFactory factory = bank.GetAccountFactory( ); + IBankAccount chequingAccount = factory.CreateChequingAccount( ); + Assert.IsTrue( chequingAccount.Balance.Amount == 0, "Should be zero but was: " + chequingAccount.Balance.Amount ); + } + + [Test] + public void Should_Create_A_Cibc_Savings_Account( ) { + IBank bank = new CibcBank( ); + IBankAccountFactory factory = bank.GetAccountFactory( ); + IBankAccount savingsAccount = factory.CreateSavingsAccount( ); + Assert.IsTrue( savingsAccount.Balance.Amount == 0, "Should be zero but was: " + savingsAccount.Balance.Amount ); + } + + [Test] + public void Should_Create_A_Royal_Bank_Chequing_Account( ) { + IBank bank = new RoyalBank( ); + IBankAccountFactory factory = bank.GetAccountFactory( ); + IBankAccount chequingAccount = factory.CreateChequingAccount( ); + Assert.IsTrue( chequingAccount.Balance.Amount == 0, "Should be zero but was: " + chequingAccount.Balance.Amount ); + } + + [Test] + public void Should_Create_A_Royal_Bank_Savings_Account( ) { + IBank bank = new RoyalBank( ); + IBankAccountFactory factory = bank.GetAccountFactory( ); + IBankAccount savingsAccount = factory.CreateSavingsAccount( ); + Assert.IsTrue( savingsAccount.Balance.Amount == 0, "Should be zero but was: " + savingsAccount.Balance.Amount ); + } + + [Test] + public void _Should_Have_A_Balance( ) { + IBankAccount account = new BankAccount( new Money( 5 ) ); + Assert.IsTrue( account.Balance.Equals( new Money( 5 ) ) ); + } + + [Test] + public void Should_Have_Account_Number( ) { + string accountNumber = Guid.NewGuid( ).ToString( ); + IBankAccount account = new BankAccount( new Money( 500 ), accountNumber ); + Assert.IsTrue( accountNumber == account.AccountNumber ); + } + } +} \ No newline at end of file diff --git a/DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj b/DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj new file mode 100644 index 0000000..afd60e7 --- /dev/null +++ b/DesignPatterns/src/test/DesignPatterns.Test/DesignPatterns.Test.csproj @@ -0,0 +1,63 @@ + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {51D18D95-959C-499E-8363-7FEFF817797F} + Library + Properties + DesignPatterns.Test + DesignPatterns.Test + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\tools\MbUnit\MbUnit.Framework.dll + + + + + + + + + + + + + + {0AAEDFE4-421D-4B3B-8629-5A20EC13F379} + DesignPatterns.Factory + + + {21E02E54-3D4F-457A-B521-D2472ABC55CE} + DesignPatterns.State + + + + + \ No newline at end of file diff --git a/DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs b/DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs new file mode 100644 index 0000000..4f999e5 --- /dev/null +++ b/DesignPatterns/src/test/DesignPatterns.Test/MoneyTest.cs @@ -0,0 +1,52 @@ +using DesignPatterns.Factory; +using MbUnit.Framework; + +namespace DesignPatterns.Test { + [TestFixture] + public class MoneyTest { + [Test] + public void Should_Be_Equal( ) { + Assert.IsTrue( new Money( 5 ).Equals( new Money( 5 ) ) ); + } + + [Test] + public void _Should_Be_Able_To_Add_Two_Monies_Together( ) { + IMoney sum = new Money( 5 ).Add( new Money( 5 ) ); + Assert.IsTrue( sum.Equals( new Money( 10 ) ) ); + } + + [Test] + public void _Should_Be_Able_To_Subtract_Two_Monies( ) { + IMoney balance = new Money( 5 ).Subtract( new Money( 3 ) ); + Assert.IsTrue( balance.Equals( new Money( 2 ) ), "Should have a 2 monies" ); + } + + [Test] + public void _Should_Be_Able_To_Subtract_Many_Monies( ) { + IMoney balance = new Money( 5 ).Subtract( new Money( 3 ) ).Subtract( new Money( 1 ) ); + Assert.IsTrue( balance.Equals( new Money( 1 ) ), "Should have 1 monies" ); + } + + [Test] + public void Should_Have_A_Currency( ) { + new Money( 5, Currency.Canadian ); + } + + [Test] + [ExpectedException( typeof( CannotAddMoniesException ) )] + public void Should_Only_Add_Monies_Of_The_Same_Currency( ) { + new Money( 5, Currency.Canadian ).Add( new Money( 5, Currency.American ) ); + } + + [Test] + [ExpectedException( typeof( NegativeMoneyException ) )] + public void Should_Not_Be_Able_To_Construct_Negative_Money( ) { + new Money( -5 ); + } + + [Test] + public void Should_Return_5_Monies( ) { + Assert.IsTrue( new Money( 5 ).Equals( new Money( 5 ).Add( null ) ) ); + } + } +} \ No newline at end of file diff --git a/DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs b/DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs new file mode 100644 index 0000000..f69e45c --- /dev/null +++ b/DesignPatterns/src/test/DesignPatterns.Test/PosTerminalTest.cs @@ -0,0 +1,17 @@ +using DesignPatterns.State; +using MbUnit.Framework; + +namespace DesignPatterns.Test { + [TestFixture] + public class PosTerminalTest { + [Test] + public void Should_( ) { + IPosTerminal terminal = new PosTerminal( ); + terminal.SwipeCard( "6278080000008205" ); + terminal.EnterAmount( 99.99 ); + terminal.EnterPin( "8012" ); + terminal.ProcessTransaction( ); + terminal.PrintReceipt( ); + } + } +} \ No newline at end of file diff --git a/DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs b/DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bcb5b5d --- /dev/null +++ b/DesignPatterns/src/test/DesignPatterns.Test/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +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("DesignPatterns.Test")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DesignPatterns.Test")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[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("a9a41066-98c3-4ecf-b37f-3fdfb035b12d")] + +// 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 Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] -- cgit v1.2.3