summaryrefslogtreecommitdiff
path: root/slips/src/test/Marina.Test
diff options
context:
space:
mode:
authormokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219>2009-02-21 21:44:27 +0000
committermokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219>2009-02-21 21:44:27 +0000
commit1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch)
tree4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/test/Marina.Test
parent42d66bcab8262c7b8b2452615df535e694a3ec1c (diff)
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/test/Marina.Test')
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Mappers/BoatDataMapperTest.cs78
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Mappers/CustomerDataMapperTest.cs25
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Mappers/LeaseDataMapperTest.cs44
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Mappers/RegistrationDataMapperTest.cs70
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Repositories/DockRepositoryTest.cs24
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Repositories/SlipRepositoryTest.cs32
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Utility/BoatMother.cs19
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Utility/CustomerMother.cs34
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Utility/LeaseMother.cs21
-rw-r--r--slips/src/test/Marina.Test/Integration/DataAccess/Utility/SlipMother.cs18
-rw-r--r--slips/src/test/Marina.Test/Integration/Task/CatalogTasksTest.cs19
-rw-r--r--slips/src/test/Marina.Test/Marina.Test.csproj136
-rw-r--r--slips/src/test/Marina.Test/Properties/AssemblyInfo.cs36
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/DatabaseCommandTest.cs48
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConfigurationTest.cs33
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConnectionTest.cs167
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/DatabaseGatewayTest.cs91
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/Mappers/CustomerDataMapperTest.cs86
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/Repositories/CustomerRepositoryTest.cs142
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/Repositories/DockRepositoryTest.cs38
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/Repositories/IdentityMapTest.cs71
-rw-r--r--slips/src/test/Marina.Test/Unit/DataAccess/Repositories/SlipRepositoryTest.cs50
-rw-r--r--slips/src/test/Marina.Test/Unit/Domain/CustomerRegistrationTest.cs50
-rw-r--r--slips/src/test/Marina.Test/Unit/Domain/CustomerTest.cs118
-rw-r--r--slips/src/test/Marina.Test/Unit/Domain/DockTest.cs24
-rw-r--r--slips/src/test/Marina.Test/Unit/Domain/LeaseDurationTest.cs45
-rw-r--r--slips/src/test/Marina.Test/Unit/Domain/SlipTest.cs78
-rw-r--r--slips/src/test/Marina.Test/Unit/Domain/UtilitiesTest.cs36
-rw-r--r--slips/src/test/Marina.Test/Unit/Infrastructure/Logging/Interfaces/LogTest.cs36
-rw-r--r--slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogFactoryTest.cs19
-rw-r--r--slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogTest.cs26
-rw-r--r--slips/src/test/Marina.Test/Unit/Infrastructure/TransformTest.cs37
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/AvailableSlipsPresenterTest.cs51
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/CurrentLeasesPresenterTest.cs63
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/CustomerRegistrationPresenterTest.cs69
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/DockPresenterTest.cs90
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/LeaseSlipPresenterTest.cs100
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/LoginPresenterTest.cs62
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/Mappers/CustomerRegistrationPresentationMapperTest.cs52
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/Mappers/LoginCredentialsMapperTest.cs35
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/Mappers/UpdateRegistrationPresentationMapperTest.cs57
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs45
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/RegisterBoatPresenterTest.cs67
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/UpdateRegistrationPresenterTest.cs92
-rw-r--r--slips/src/test/Marina.Test/Unit/Presentation/ViewRegisteredBoatsPresenterTest.cs62
-rw-r--r--slips/src/test/Marina.Test/Unit/Task/CatalogTasksTest.cs106
-rw-r--r--slips/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs181
-rw-r--r--slips/src/test/Marina.Test/Unit/Task/RegistrationTasksTest.cs217
-rw-r--r--slips/src/test/Marina.Test/Unit/Web/Commands/AvailableSlipsCommandTest.cs56
-rw-r--r--slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerSpecificationTest.cs53
-rw-r--r--slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerTest.cs49
-rw-r--r--slips/src/test/Marina.Test/Unit/Web/Views/Pages/AvailableSlipsWebViewTest.cs49
-rw-r--r--slips/src/test/Marina.Test/Unit/Web/Views/ViewTest.cs48
-rw-r--r--slips/src/test/Marina.Test/Utility/ObjectMother.cs69
-rw-r--r--slips/src/test/Marina.Test/Utility/RunInRealContainerAttribute.cs14
-rw-r--r--slips/src/test/Marina.Test/Utility/RunInRealContainerRunInvoker.cs18
56 files changed, 3456 insertions, 0 deletions
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/BoatDataMapperTest.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/BoatDataMapperTest.cs
new file mode 100644
index 0000000..20b881f
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/BoatDataMapperTest.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using Marina.DataAccess.DataMappers;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Test.Integration.DataAccess.Utility;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.DataAccess.Mappers {
+ [TestFixture]
+ public class BoatDataMapperTest {
+ public IBoatDataMapper CreateSUT() {
+ return new BoatDataMapper( );
+ }
+
+ [Test]
+ [RunInRealContainer]
+ [RollBack]
+ public void Should_return_3_boats() {
+ long customerId = CustomerMother.CreateCustomerRecord( );
+
+ BoatMother.AddBoatsFor( customerId );
+
+ IRichList< IBoat > boats = ListFactory.From( CreateSUT( ).AllBoatsFor( customerId ) );
+ Assert.AreEqual( 3, boats.Count );
+ }
+
+ [Test]
+ [RunInRealContainer]
+ [RollBack]
+ public void Should_be_able_to_insert_new_boats_for_customer() {
+ IBoat firstBoat = new Boat( "reg1", "TOYOTA", new DateTime( 2001, 1, 1 ), 100 );
+ IBoat secondBoat = new Boat( "reg2", "YAMAHA", new DateTime( 2005, 1, 1 ), 200 );
+
+ IList< IBoat > boats = new List< IBoat >( );
+ boats.Add( firstBoat );
+ boats.Add( secondBoat );
+
+ long customerId = CustomerMother.CreateCustomerRecord( );
+ IBoatDataMapper mapper = CreateSUT( );
+ mapper.Insert( boats, customerId );
+
+ IRichList< IBoat > insertedBoats = ListFactory.From( mapper.AllBoatsFor( customerId ) );
+ Assert.AreEqual( 2, insertedBoats.Count );
+ Assert.IsTrue( insertedBoats.Contains( firstBoat ) );
+ Assert.IsTrue( insertedBoats.Contains( secondBoat ) );
+ }
+
+ [Test]
+ [RollBack]
+ [RunInRealContainer]
+ public void Should_insert_new_boats_for_customer() {
+ long customerId = CustomerMother.CreateCustomerRecord( );
+ IList< IBoat > boats = CreateBoats( );
+
+ IBoatDataMapper mapper = CreateSUT( );
+ mapper.Insert( boats, customerId );
+
+ IBoat thirdBoat = new Boat( "reg3", "HONDA", new DateTime( 1999, 1, 1 ), 300 );
+ boats.Add( thirdBoat );
+
+ mapper.Update( boats, customerId );
+
+ IRichList< IBoat > insertedBoats = ListFactory.From( mapper.AllBoatsFor( customerId ) );
+ Assert.AreEqual( 3, insertedBoats.Count );
+ Assert.IsTrue( insertedBoats.Contains( thirdBoat ) );
+ }
+
+ private IList< IBoat > CreateBoats() {
+ IList< IBoat > boats = new List< IBoat >( );
+ boats.Add( new Boat( "reg1", "TOYOTA", new DateTime( 2001, 1, 1 ), 100 ) );
+ boats.Add( new Boat( "reg2", "YAMAHA", new DateTime( 2005, 1, 1 ), 200 ) );
+ return boats;
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/CustomerDataMapperTest.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/CustomerDataMapperTest.cs
new file mode 100644
index 0000000..ef32eac
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/CustomerDataMapperTest.cs
@@ -0,0 +1,25 @@
+using Marina.DataAccess.DataMappers;
+using Marina.Domain.Interfaces;
+using Marina.Test.Integration.DataAccess.Utility;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.DataAccess.Mappers {
+ public class CustomerDataMapperTest {
+ public ICustomerDataMapper CreateSUT() {
+ return new CustomerDataMapper( );
+ }
+
+ [Test]
+ [RollBack]
+ [RunInRealContainer]
+ public void Should_be_able_to_find_customer_by_username() {
+ string username = "mokhan";
+ long customerId = CustomerMother.CreateCustomerRecordWith( username );
+
+ ICustomer foundCustomer = CreateSUT( ).FindBy( username );
+ Assert.AreEqual( customerId, foundCustomer.ID( ) );
+ Assert.AreEqual( username, foundCustomer.Registration( ).Username( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/LeaseDataMapperTest.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/LeaseDataMapperTest.cs
new file mode 100644
index 0000000..c08577e
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/LeaseDataMapperTest.cs
@@ -0,0 +1,44 @@
+using System.Collections.Generic;
+using Marina.DataAccess.DataMappers;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Test.Integration.DataAccess.Utility;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.DataAccess.Mappers {
+ [TestFixture]
+ public class LeaseDataMapperTest {
+ public ILeaseDataMapper CreateSUT() {
+ return new LeaseDataMapper( );
+ }
+
+ [Test]
+ [RollBack]
+ [RunInRealContainer]
+ public void Should_return_all_leases_for_a_specific_customer() {
+ long customerId = CustomerMother.CreateCustomerRecord( );
+ LeaseMother.CreateLeaseFor( customerId );
+
+ IRichList< ISlipLease > leasesForCustomer = ListFactory.From( CreateSUT( ).AllLeasesFor( customerId ) );
+ Assert.AreEqual( 1, leasesForCustomer.Count );
+ }
+
+ [Test]
+ [RollBack]
+ [RunInRealContainer]
+ public void Should_be_able_to_insert_new_leases_for_customer() {
+ long customerId = CustomerMother.CreateCustomerRecord( );
+
+ IList< ISlipLease > leases = new List< ISlipLease >( );
+ leases.Add( new SlipLease( new Slip( 1000, null, 100, 100, true ), LeaseDurations.Daily ) );
+
+ ILeaseDataMapper mapper = CreateSUT( );
+ mapper.Insert( leases, customerId );
+
+ IRichList< ISlipLease > foundLeases = ListFactory.From( mapper.AllLeasesFor( customerId ) );
+ Assert.AreEqual( 1, foundLeases.Count );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/RegistrationDataMapperTest.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/RegistrationDataMapperTest.cs
new file mode 100644
index 0000000..d4beabf
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Mappers/RegistrationDataMapperTest.cs
@@ -0,0 +1,70 @@
+using Marina.DataAccess;
+using Marina.DataAccess.Builders;
+using Marina.DataAccess.DataMappers;
+using Marina.DataAccess.Schemas;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure.Container;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.DataAccess.Mappers {
+ [TestFixture]
+ public class RegistrationDataMapperTest {
+ public IRegistrationDataMapper CreateSUT() {
+ return new RegistrationDataMapper( );
+ }
+
+ [RunInRealContainer]
+ [Test]
+ public void Should_be_able_to_find_john() {
+ int customerId = 1000;
+ IRegistration registration = CreateSUT( ).For( customerId );
+ Assert.AreEqual( "John", registration.FirstName( ) );
+ Assert.AreEqual( "Doe", registration.LastName( ) );
+ Assert.AreEqual( "555-545-1212", registration.PhoneNumber( ) );
+ Assert.AreEqual( "Phoenix", registration.City( ) );
+ }
+
+ [RunInRealContainer]
+ [Test]
+ [RollBack]
+ public void Should_be_able_to_insert_new_registration_for_customer() {
+ IRegistrationDataMapper mapper = CreateSUT( );
+ long customerId = CreateCustomerRecord( );
+ IRegistration expectedRegistration =
+ new CustomerRegistration( "mokhan", "password", "mo", "khan", "4036813389", "calgary" );
+
+ mapper.Insert( expectedRegistration, customerId );
+ IRegistration actualRegistration = mapper.For( customerId );
+ Assert.AreEqual( expectedRegistration, actualRegistration );
+ }
+
+ [RunInRealContainer]
+ [Test]
+ [RollBack]
+ public void Should_be_able_to_update_record() {
+ IRegistrationDataMapper mapper = CreateSUT( );
+ long customerId = CreateCustomerRecord( );
+ IRegistration firstRegistration =
+ new CustomerRegistration( "mokhan", "password", "mo", "khan", "4036813389", "calgary" );
+ IRegistration expectedRegistration =
+ new CustomerRegistration( "khanmo", "wordpass", "om", "ankh", "1338940368", "garycal" );
+
+ mapper.Insert( firstRegistration, customerId );
+ mapper.Update( expectedRegistration, customerId );
+
+ IRegistration actualRegistration = mapper.For( customerId );
+ Assert.AreEqual( expectedRegistration, actualRegistration );
+ }
+
+ private long CreateCustomerRecord() {
+ IQuery query = DatabaseInsert.Into( CustomerTable.TableName )
+ .AddValue( CustomerTable.FirstName, string.Empty )
+ .AddValue( CustomerTable.LastName, string.Empty )
+ .AddValue( CustomerTable.Phone, string.Empty )
+ .AddValue( CustomerTable.City, string.Empty ).Build( );
+ return Resolve.DependencyFor< IDatabaseGateway >( ).ExecuteScalar( query );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Repositories/DockRepositoryTest.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Repositories/DockRepositoryTest.cs
new file mode 100644
index 0000000..7612f50
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Repositories/DockRepositoryTest.cs
@@ -0,0 +1,24 @@
+using Marina.DataAccess.Repositories;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.DataAccess.Repositories {
+ [TestFixture]
+ public class DockRepositoryTest {
+ public IDockRepository CreateSUT() {
+ return new DockRepository( );
+ }
+
+ [RunInRealContainer]
+ [RowTest]
+ [Row( 1 )]
+ [Row( 2 )]
+ [Row( 3 )]
+ public void Should_load_dock_by( long dockId ) {
+ IDock dock = CreateSUT( ).FindBy( dockId );
+ Assert.AreEqual( dockId, dock.ID( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Repositories/SlipRepositoryTest.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Repositories/SlipRepositoryTest.cs
new file mode 100644
index 0000000..ab4b907
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Repositories/SlipRepositoryTest.cs
@@ -0,0 +1,32 @@
+using Marina.DataAccess.Repositories;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.DataAccess.Repositories {
+ [TestFixture]
+ public class SlipRepositoryTest {
+ public ISlipsRepository CreateSUT() {
+ return new SlipsRepository( );
+ }
+
+ [RunInRealContainer]
+ [Test]
+ public void Should_return_at_least_one_available_slip() {
+ Assert.IsTrue( ListFactory.From( CreateSUT( ).AllAvailableSlips( ) ).Count > 0 );
+ }
+
+ [RunInRealContainer]
+ [Test]
+ public void Should_return_at_least_one_available_slip_for_the_dock() {
+ ISlipsRepository repository = CreateSUT( );
+ IDock dock = new Dock( 1, string.Empty, null, null );
+
+ IRichList< ISlip > slipsFound = ListFactory.From( repository.AllAvailableSlipsFor( dock ) );
+ Assert.IsTrue( slipsFound.Count > 0 );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Utility/BoatMother.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/BoatMother.cs
new file mode 100644
index 0000000..cb8d7b3
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/BoatMother.cs
@@ -0,0 +1,19 @@
+using Marina.DataAccess;
+using Marina.DataAccess.Builders;
+using Marina.DataAccess.Schemas;
+using Marina.Infrastructure.Container;
+
+namespace Marina.Test.Integration.DataAccess.Utility {
+ public static class BoatMother {
+ public static void AddBoatsFor( long customerId ) {
+ IInsertQueryBuilder builder = DatabaseInsert.Into( BoatTable.TableName )
+ .AddValue( BoatTable.RegistrationNumber, string.Empty )
+ .AddValue( BoatTable.Manufacturer, string.Empty )
+ .AddValue( BoatTable.ModelYear, string.Empty )
+ .AddValue( BoatTable.Length, string.Empty )
+ .AddValue( BoatTable.CustomerID, customerId.ToString( ) );
+
+ Resolve.DependencyFor< IDatabaseGateway >( ).Execute( builder.Build( ), builder.Build( ), builder.Build( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Utility/CustomerMother.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/CustomerMother.cs
new file mode 100644
index 0000000..923528a
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/CustomerMother.cs
@@ -0,0 +1,34 @@
+using Marina.DataAccess;
+using Marina.DataAccess.Builders;
+using Marina.DataAccess.Schemas;
+using Marina.Infrastructure.Container;
+
+namespace Marina.Test.Integration.DataAccess.Utility {
+ public static class CustomerMother {
+ public static long CreateCustomerRecord() {
+ IInsertQueryBuilder builder = DatabaseInsert.Into( CustomerTable.TableName )
+ .AddValue( CustomerTable.FirstName, string.Empty )
+ .AddValue( CustomerTable.LastName, string.Empty )
+ .AddValue( CustomerTable.Phone, string.Empty )
+ .AddValue( CustomerTable.City, string.Empty );
+ return Resolve.DependencyFor< IDatabaseGateway >( ).ExecuteScalar( builder.Build( ) );
+ }
+
+ public static long CreateCustomerRecordWith( string username ) {
+ IInsertQueryBuilder builder = DatabaseInsert.Into( CustomerTable.TableName )
+ .AddValue( CustomerTable.FirstName, string.Empty )
+ .AddValue( CustomerTable.LastName, string.Empty )
+ .AddValue( CustomerTable.Phone, string.Empty )
+ .AddValue( CustomerTable.City, string.Empty );
+ long customerId = Resolve.DependencyFor< IDatabaseGateway >( ).ExecuteScalar( builder.Build( ) );
+
+ IQuery insertToAuthTable = DatabaseInsert.Into( AuthorizationTable.TableName )
+ .AddValue( AuthorizationTable.UserName, username )
+ .AddValue( AuthorizationTable.Password, string.Empty )
+ .Build( );
+
+ Resolve.DependencyFor< IDatabaseGateway >( ).Execute( insertToAuthTable );
+ return customerId;
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Utility/LeaseMother.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/LeaseMother.cs
new file mode 100644
index 0000000..1c8b2ec
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/LeaseMother.cs
@@ -0,0 +1,21 @@
+using System;
+using Marina.DataAccess;
+using Marina.DataAccess.Builders;
+using Marina.DataAccess.Schemas;
+using Marina.Infrastructure.Container;
+
+namespace Marina.Test.Integration.DataAccess.Utility {
+ public static class LeaseMother {
+ public static void CreateLeaseFor( long customerId ) {
+ IQuery query = DatabaseInsert
+ .Into( LeaseTable.TableName )
+ .AddValue( LeaseTable.CustomerID, customerId )
+ .AddValue( LeaseTable.EndDate, DateTime.Now.AddDays( 1 ) )
+ .AddValue( LeaseTable.LeaseTypeID, 1 )
+ .AddValue( LeaseTable.SlipID, SlipMother.CreateSlip( ) )
+ .AddValue( LeaseTable.StartDate, DateTime.Now ).Build( );
+
+ Resolve.DependencyFor< IDatabaseGateway >( ).Execute( query );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/DataAccess/Utility/SlipMother.cs b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/SlipMother.cs
new file mode 100644
index 0000000..51cbecb
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/DataAccess/Utility/SlipMother.cs
@@ -0,0 +1,18 @@
+using Marina.DataAccess;
+using Marina.DataAccess.Builders;
+using Marina.DataAccess.Schemas;
+using Marina.Infrastructure.Container;
+
+namespace Marina.Test.Integration.DataAccess.Utility {
+ public static class SlipMother {
+ public static long CreateSlip() {
+ IQuery query = DatabaseInsert
+ .Into( SlipTable.TableName )
+ .AddValue( SlipTable.DockID, 1 )
+ .AddValue( SlipTable.Length, 100 )
+ .AddValue( SlipTable.Width, 100 ).Build( );
+
+ return Resolve.DependencyFor< IDatabaseGateway >( ).ExecuteScalar( query );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Integration/Task/CatalogTasksTest.cs b/slips/src/test/Marina.Test/Integration/Task/CatalogTasksTest.cs
new file mode 100644
index 0000000..fc5e09e
--- /dev/null
+++ b/slips/src/test/Marina.Test/Integration/Task/CatalogTasksTest.cs
@@ -0,0 +1,19 @@
+using Marina.Infrastructure;
+using Marina.Task;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Integration.Task {
+ [TestFixture]
+ public class CatalogTasksTest {
+ public ICatalogTasks CreateSUT() {
+ return new CatalogTasks( );
+ }
+
+ [RunInRealContainer]
+ [Test]
+ public void Should_return_at_least_one_available_slip() {
+ Assert.IsTrue( ListFactory.From( CreateSUT( ).GetAllAvailableSlips( ) ).Count > 0 );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Marina.Test.csproj b/slips/src/test/Marina.Test/Marina.Test.csproj
new file mode 100644
index 0000000..f06e22f
--- /dev/null
+++ b/slips/src/test/Marina.Test/Marina.Test.csproj
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.21022</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{D9BCEEBA-F4D1-4057-8070-5EB1640D618D}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Marina.Test</RootNamespace>
+ <AssemblyName>Marina.Test</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </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="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\build\lib\log4net\bin\log4net.dll</HintPath>
+ </Reference>
+ <Reference Include="MbUnit.Framework, Version=1.0.2700.29885, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\build\tools\mbunit\bin\MbUnit.Framework.dll</HintPath>
+ </Reference>
+ <Reference Include="Rhino.Mocks, Version=3.3.0.906, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\..\build\tools\rhino.mocks\bin\Rhino.Mocks.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.configuration" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Transactions" />
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data.DataSetExtensions">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Integration\DataAccess\Mappers\BoatDataMapperTest.cs" />
+ <Compile Include="Integration\DataAccess\Mappers\CustomerDataMapperTest.cs" />
+ <Compile Include="Integration\DataAccess\Mappers\LeaseDataMapperTest.cs" />
+ <Compile Include="Integration\DataAccess\Mappers\RegistrationDataMapperTest.cs" />
+ <Compile Include="Integration\DataAccess\Repositories\DockRepositoryTest.cs" />
+ <Compile Include="Integration\DataAccess\Repositories\SlipRepositoryTest.cs" />
+ <Compile Include="Integration\DataAccess\Utility\BoatMother.cs" />
+ <Compile Include="Integration\DataAccess\Utility\CustomerMother.cs" />
+ <Compile Include="Integration\DataAccess\Utility\LeaseMother.cs" />
+ <Compile Include="Integration\DataAccess\Utility\SlipMother.cs" />
+ <Compile Include="Integration\Task\CatalogTasksTest.cs" />
+ <Compile Include="Unit\DataAccess\DatabaseCommandTest.cs" />
+ <Compile Include="Unit\DataAccess\DatabaseConfigurationTest.cs" />
+ <Compile Include="Unit\DataAccess\DatabaseConnectionTest.cs" />
+ <Compile Include="Unit\DataAccess\DatabaseGatewayTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="Unit\DataAccess\Mappers\CustomerDataMapperTest.cs" />
+ <Compile Include="Unit\DataAccess\Repositories\CustomerRepositoryTest.cs" />
+ <Compile Include="Unit\DataAccess\Repositories\DockRepositoryTest.cs" />
+ <Compile Include="Unit\DataAccess\Repositories\IdentityMapTest.cs" />
+ <Compile Include="Unit\DataAccess\Repositories\SlipRepositoryTest.cs" />
+ <Compile Include="Unit\Domain\CustomerRegistrationTest.cs" />
+ <Compile Include="Unit\Domain\CustomerTest.cs" />
+ <Compile Include="Unit\Domain\DockTest.cs" />
+ <Compile Include="Unit\Domain\LeaseDurationTest.cs" />
+ <Compile Include="Unit\Domain\SlipTest.cs" />
+ <Compile Include="Unit\Domain\UtilitiesTest.cs" />
+ <Compile Include="Unit\Infrastructure\Logging\Interfaces\LogTest.cs" />
+ <Compile Include="Unit\Infrastructure\Logging\TextWriterLogging\TextWriterLogFactoryTest.cs" />
+ <Compile Include="Unit\Infrastructure\Logging\TextWriterLogging\TextWriterLogTest.cs" />
+ <Compile Include="Unit\Infrastructure\TransformTest.cs" />
+ <Compile Include="Unit\Presentation\AvailableSlipsPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\CurrentLeasesPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\CustomerRegistrationPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\DockPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\LeaseSlipPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\LoginPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\Mappers\CustomerRegistrationPresentationMapperTest.cs" />
+ <Compile Include="Unit\Presentation\Mappers\LoginCredentialsMapperTest.cs" />
+ <Compile Include="Unit\Presentation\Mappers\UpdateRegistrationPresentationMapperTest.cs" />
+ <Compile Include="Unit\Presentation\PayloadKeyTest.cs" />
+ <Compile Include="Unit\Presentation\RegisterBoatPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\UpdateRegistrationPresenterTest.cs" />
+ <Compile Include="Unit\Presentation\ViewRegisteredBoatsPresenterTest.cs" />
+ <Compile Include="Unit\Task\CatalogTasksTest.cs" />
+ <Compile Include="Unit\Task\LeaseTasksTest.cs" />
+ <Compile Include="Unit\Task\RegistrationTasksTest.cs" />
+ <Compile Include="Unit\Web\Commands\AvailableSlipsCommandTest.cs" />
+ <Compile Include="Unit\Web\Handlers\RequestHandlerSpecificationTest.cs" />
+ <Compile Include="Unit\Web\Handlers\RequestHandlerTest.cs" />
+ <Compile Include="Unit\Web\Views\Pages\AvailableSlipsWebViewTest.cs" />
+ <Compile Include="Unit\Web\Views\ViewTest.cs" />
+ <Compile Include="Utility\ObjectMother.cs" />
+ <Compile Include="Utility\RunInRealContainerAttribute.cs" />
+ <Compile Include="Utility\RunInRealContainerRunInvoker.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\app\Marina\Marina.csproj">
+ <Project>{F9AF658A-2A26-49DE-A964-7A846A8DCC2A}</Project>
+ <Name>Marina</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Folder Include="Unit\DataAccess\Builders\" />
+ <Folder Include="Unit\Infrastructure\Logging\Log4Net\" />
+ </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> \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Properties/AssemblyInfo.cs b/slips/src/test/Marina.Test/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..1d1a117
--- /dev/null
+++ b/slips/src/test/Marina.Test/Properties/AssemblyInfo.cs
@@ -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("Marina.Test")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Marina.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("fe5b2656-dda1-4db6-8bd4-e0c467729b9f")]
+
+// 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")]
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseCommandTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseCommandTest.cs
new file mode 100644
index 0000000..c08b272
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseCommandTest.cs
@@ -0,0 +1,48 @@
+using System.Data;
+using Marina.DataAccess;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess {
+ [TestFixture]
+ public class DatabaseCommandTest {
+ private MockRepository _mockery;
+ private IDbCommand _mockCommand;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockCommand = _mockery.DynamicMock< IDbCommand >( );
+ }
+
+ public IDatabaseCommand CreateSUT() {
+ return new DatabaseCommand( _mockCommand );
+ }
+
+ [Test]
+ public void Should_execute_the_command() {
+ IDataReader mockReader = _mockery.DynamicMock< IDataReader >( );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockCommand.ExecuteReader( ) ).Return( mockReader );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).ExecuteQuery( );
+ }
+ }
+
+ [Test]
+ public void Should_return_a_loaded_data_table() {
+ IDataReader mockReader = _mockery.DynamicMock< IDataReader >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockCommand.ExecuteReader( ) ).Return( mockReader );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.IsNotNull( CreateSUT( ).ExecuteQuery( ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConfigurationTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConfigurationTest.cs
new file mode 100644
index 0000000..3dc2d1f
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConfigurationTest.cs
@@ -0,0 +1,33 @@
+using System.Configuration;
+using Marina.DataAccess;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.DataAccess {
+ [TestFixture]
+ public class DatabaseConfigurationTest {
+ private ConnectionStringSettings _settings;
+
+ [SetUp]
+ public void Setup() {
+ _settings = new ConnectionStringSettings( "ConnectionName", string.Empty, string.Empty );
+ }
+
+ public IDatabaseConfiguration CreateSUT() {
+ return new DatabaseConfiguration( _settings );
+ }
+
+ [Test]
+ public void Should_return_connection_string() {
+ string connectionString = "MyConnectionString";
+ _settings.ConnectionString = connectionString;
+ Assert.AreEqual( connectionString, CreateSUT( ).ConnectionString( ) );
+ }
+
+ [Test]
+ public void Should_return_the_provider_name() {
+ string providerName = "MyProvider";
+ _settings.ProviderName = providerName;
+ Assert.AreEqual( providerName, CreateSUT( ).ProviderName( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConnectionTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConnectionTest.cs
new file mode 100644
index 0000000..8cd8ec1
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseConnectionTest.cs
@@ -0,0 +1,167 @@
+using System.Data;
+using Marina.DataAccess;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess {
+ [TestFixture]
+ public class DatabaseConnectionTest {
+ private MockRepository _mockery;
+ private IDatabaseConfiguration _mockConfiguration;
+ private IDatabaseProviderFactory _mockProviderFactory;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockConfiguration = _mockery.DynamicMock< IDatabaseConfiguration >( );
+ _mockProviderFactory = _mockery.DynamicMock< IDatabaseProviderFactory >( );
+ }
+
+ public IDatabaseConnection CreateSUT() {
+ return new DatabaseConnection( _mockConfiguration, _mockProviderFactory );
+ }
+
+ [Test]
+ public void Should_create_connection_for_provider_name() {
+ string providerName = "System.Data.SqlClient";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+
+ Expect.Call( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).CreateCommandFor( "" );
+ }
+ }
+
+ [RowTest]
+ [Row( "MyConnectionString" )]
+ [Row( "MyStringOfConnection" )]
+ [Row( "MyConnectionString3" )]
+ public void Should_set_the_connections_connection_string_to( string connectionString ) {
+ string providerName = "System.Data.SqlClient";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ConnectionString( ) ).Return( connectionString );
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+ SetupResult.For( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+
+ mockConnection.ConnectionString = connectionString;
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).CreateCommandFor( "" );
+ }
+ }
+
+ [Test]
+ public void Should_create_a_command_object_using_the_connection() {
+ string providerName = "System.Data.SqlClient";
+ string connectionString = "MyConnectionString";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+ IDbCommand mockCommand = _mockery.DynamicMock< IDbCommand >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ConnectionString( ) ).Return( connectionString );
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+ SetupResult.For( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+
+ Expect.Call( mockConnection.CreateCommand( ) ).Return( mockCommand );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).CreateCommandFor( "" );
+ }
+ }
+
+ [RowTest]
+ [Row( "Select * From Auctions" )]
+ [Row( "Select * From Pets" )]
+ public void Should_set_the_commands_text_and_type( string sqlQuery ) {
+ string providerName = "System.Data.SqlClient";
+ string connectionString = "MyConnectionString";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+ IDbCommand mockCommand = _mockery.DynamicMock< IDbCommand >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ConnectionString( ) ).Return( connectionString );
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+ SetupResult.For( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+ SetupResult.For( mockConnection.CreateCommand( ) ).Return( mockCommand );
+
+ mockCommand.CommandText = sqlQuery;
+ mockCommand.CommandType = CommandType.Text;
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).CreateCommandFor( sqlQuery );
+ }
+ }
+
+ [Test]
+ public void Should_return_new_database_command() {
+ string providerName = "System.Data.SqlClient";
+ string connectionString = "MyConnectionString";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+ IDbCommand mockCommand = _mockery.DynamicMock< IDbCommand >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ConnectionString( ) ).Return( connectionString );
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+ SetupResult.For( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+ SetupResult.For( mockConnection.CreateCommand( ) ).Return( mockCommand );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.IsNotNull( CreateSUT( ).CreateCommandFor( "" ) );
+ }
+ }
+
+ [Test]
+ public void Should_close_connection_when_disposed() {
+ string providerName = "System.Data.SqlClient";
+ string connectionString = "MyConnectionString";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ConnectionString( ) ).Return( connectionString );
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+ SetupResult.For( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+
+ mockConnection.Close( );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Dispose( );
+ }
+ }
+
+ [Test]
+ public void Should_open_connection_when_created() {
+ string providerName = "System.Data.SqlClient";
+ string connectionString = "MyConnectionString";
+
+ IDbConnection mockConnection = _mockery.DynamicMock< IDbConnection >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConfiguration.ConnectionString( ) ).Return( connectionString );
+ SetupResult.For( _mockConfiguration.ProviderName( ) ).Return( providerName );
+ SetupResult.For( _mockProviderFactory.CreateConnectionFor( providerName ) ).Return( mockConnection );
+
+ mockConnection.Open( );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseGatewayTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseGatewayTest.cs
new file mode 100644
index 0000000..f53d1ec
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/DatabaseGatewayTest.cs
@@ -0,0 +1,91 @@
+using System.Data;
+using Marina.DataAccess;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess {
+ [TestFixture]
+ public class DatabaseGatewayTest {
+ private MockRepository _mockery;
+ private IDatabaseConnectionFactory _mockConnectionFactory;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockConnectionFactory = _mockery.DynamicMock< IDatabaseConnectionFactory >( );
+ }
+
+ public IDatabaseGateway CreateSUT() {
+ return new DatabaseGateway( _mockConnectionFactory );
+ }
+
+ [Test]
+ public void Should_leverage_factory_to_create_a_new_connection() {
+ IDatabaseConnection mockConnection = _mockery.DynamicMock< IDatabaseConnection >( );
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockConnectionFactory.Create( ) ).Return( mockConnection );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).LoadTableUsing( "" );
+ }
+ }
+
+ [Test]
+ public void Should_create_command_using_database_connection() {
+ IDatabaseConnection mockConnection = _mockery.DynamicMock< IDatabaseConnection >( );
+ IDatabaseCommand mockCommand = _mockery.DynamicMock< IDatabaseCommand >( );
+ string sqlQuery = "SELECT * FROM ?";
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConnectionFactory.Create( ) ).Return( mockConnection );
+ Expect.Call( mockConnection.CreateCommandFor( sqlQuery ) ).Return( mockCommand );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).LoadTableUsing( sqlQuery );
+ }
+ }
+
+ [RowTest]
+ [Row( "SELECT * FROM Cars" )]
+ [Row( "SELECT * FROM Persons" )]
+ public void Should_execute_query_on_command( string sqlQuery ) {
+ IDatabaseConnection mockConnection = _mockery.DynamicMock< IDatabaseConnection >( );
+ IDatabaseCommand mockCommand = _mockery.DynamicMock< IDatabaseCommand >( );
+
+ DataTable table = new DataTable( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConnectionFactory.Create( ) ).Return( mockConnection );
+ SetupResult.For( mockConnection.CreateCommandFor( sqlQuery ) ).Return( mockCommand );
+ Expect.Call( mockCommand.ExecuteQuery( ) ).Return( table );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( table, CreateSUT( ).LoadTableUsing( sqlQuery ) );
+ }
+ }
+
+ [Test]
+ public void Should_close_the_connection_after_executing_the_command() {
+ IDatabaseConnection mockConnection = _mockery.DynamicMock< IDatabaseConnection >( );
+ IDatabaseCommand mockCommand = _mockery.DynamicMock< IDatabaseCommand >( );
+ string sqlQuery = "SELECT * FROM ?";
+
+ DataTable table = new DataTable( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockConnectionFactory.Create( ) ).Return( mockConnection );
+ SetupResult.For( mockConnection.CreateCommandFor( sqlQuery ) ).Return( mockCommand );
+
+ using ( _mockery.Ordered( ) ) {
+ Expect.Call( mockCommand.ExecuteQuery( ) ).Return( table );
+ mockConnection.Dispose( );
+ }
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).LoadTableUsing( sqlQuery );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/Mappers/CustomerDataMapperTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/Mappers/CustomerDataMapperTest.cs
new file mode 100644
index 0000000..81e170b
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/Mappers/CustomerDataMapperTest.cs
@@ -0,0 +1,86 @@
+using System.Collections.Generic;
+using Marina.DataAccess;
+using Marina.DataAccess.DataMappers;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess.Mappers {
+ [TestFixture]
+ public class CustomerDataMapperTest {
+ private MockRepository _mockery;
+ private IDatabaseGateway _mockGateway;
+ private IBoatDataMapper _boatMapper;
+ private ILeaseDataMapper _leaseDataMapper;
+ private IRegistrationDataMapper _registrationMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockGateway = _mockery.DynamicMock< IDatabaseGateway >( );
+ _boatMapper = _mockery.DynamicMock< IBoatDataMapper >( );
+ _leaseDataMapper = _mockery.DynamicMock< ILeaseDataMapper >( );
+ _registrationMapper = _mockery.DynamicMock< IRegistrationDataMapper >( );
+ }
+
+ public ICustomerDataMapper CreateSUT() {
+ return new CustomerDataMapper( _mockGateway, _boatMapper, _leaseDataMapper, _registrationMapper );
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_load_customers_boats() {
+ long customerId = 32;
+
+ IList< IBoat > boats = new List< IBoat >( );
+ IBoat boat = _mockery.DynamicMock< IBoat >( );
+ boats.Add( boat );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _boatMapper.AllBoatsFor( customerId ) ).Return( boats );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ ICustomer customer = CreateSUT( ).FindBy( customerId );
+ Assert.AreEqual( 1, ListFactory.From( customer.RegisteredBoats( ) ).Count );
+ Assert.IsTrue( ListFactory.From( customer.RegisteredBoats( ) ).Contains( boat ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_load_customer_leases() {
+ long customerId = 32;
+ IList< ISlipLease > leases = new List< ISlipLease >( );
+ ISlipLease lease = _mockery.DynamicMock< ISlipLease >( );
+ leases.Add( lease );
+
+ using ( _mockery.Record( ) ) {
+ Expect
+ .Call( _leaseDataMapper.AllLeasesFor( customerId ) )
+ .Return( leases );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ ICustomer customer = CreateSUT( ).FindBy( customerId );
+ Assert.AreEqual( 1, ListFactory.From( customer.Leases( ) ).Count );
+ Assert.IsTrue( ListFactory.From( customer.Leases( ) ).Contains( lease ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_load_customer_registration() {
+ long customerId = 59;
+
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _registrationMapper.For( customerId ) ).Return( registration );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ ICustomer customer = CreateSUT( ).FindBy( customerId );
+ Assert.AreEqual( registration, customer.Registration( ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/CustomerRepositoryTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/CustomerRepositoryTest.cs
new file mode 100644
index 0000000..afc21fc
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/CustomerRepositoryTest.cs
@@ -0,0 +1,142 @@
+using Marina.DataAccess;
+using Marina.DataAccess.DataMappers;
+using Marina.DataAccess.Repositories;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess.Repositories {
+ [TestFixture]
+ public class CustomerRepositoryTest {
+ private MockRepository _mockery;
+ private IIdentityMap< ICustomer > _mockIdentityMap;
+ private ICustomerDataMapper _mockMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockIdentityMap = _mockery.DynamicMock< IIdentityMap< ICustomer > >( );
+ _mockMapper = _mockery.DynamicMock< ICustomerDataMapper >( );
+ }
+
+ public ICustomerRepository CreateSUT() {
+ return CreateSUT( _mockIdentityMap, _mockMapper );
+ }
+
+ private ICustomerRepository CreateSUT( IIdentityMap< ICustomer > identityMap, ICustomerDataMapper mapper ) {
+ return new CustomerRepository( identityMap, mapper );
+ }
+
+ [Test]
+ public void Should_check_identity_map_to_see_if_customer_is_loaded() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ long customerId = 23455;
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockIdentityMap.ContainsObjectWithIdOf( customerId ) ).Return( true );
+ Expect.Call( _mockIdentityMap.FindObjectWithIdOf( customerId ) ).Return( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( customer, CreateSUT( ).FindBy( customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_load_customer_if_not_in_identity_map() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ long customerId = 23455;
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockIdentityMap.ContainsObjectWithIdOf( customerId ) ).Return( false );
+ Expect.Call( _mockMapper.FindBy( customerId ) ).Return( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( customer, CreateSUT( ).FindBy( customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_add_customer_to_identity_map_after_retrieving_from_mapper() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ long customerId = 23455;
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockIdentityMap.ContainsObjectWithIdOf( customerId ) ).Return( false );
+ SetupResult.For( _mockMapper.FindBy( customerId ) ).Return( customer );
+ _mockIdentityMap.Add( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( customer, CreateSUT( ).FindBy( customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_create_a_new_customer() {
+ using ( _mockery.Record( ) ) {}
+
+ using ( _mockery.Playback( ) ) {
+ ICustomer newCustomer = CreateSUT( ).NewCustomer( );
+ Assert.AreEqual( -1, newCustomer.ID( ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_insert_new_customer() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ long customerId = 34;
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.ID( ) ).Return( customerId );
+ SetupResult.For( _mockIdentityMap.ContainsObjectWithIdOf( customerId ) ).Return( false );
+
+ _mockMapper.Insert( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Save( customer );
+ }
+ }
+
+ [Test]
+ public void Should_add_new_customer_to_identity_map_after_insert() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ long customerId = 34;
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.ID( ) ).Return( customerId );
+ SetupResult.For( _mockIdentityMap.ContainsObjectWithIdOf( customerId ) ).Return( false );
+ using ( _mockery.Ordered( ) ) {
+ _mockMapper.Insert( customer );
+ _mockIdentityMap.Add( customer );
+ }
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Save( customer );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_update_customer() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ IIdentityMap< ICustomer > identityMap = _mockery.CreateMock< IIdentityMap< ICustomer > >( );
+ ICustomerDataMapper dataMapper = _mockery.CreateMock< ICustomerDataMapper >( );
+ long customerId = 46;
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.ID( ) ).Return( customerId );
+ SetupResult.For( identityMap.ContainsObjectWithIdOf( customerId ) ).Return( true );
+
+ dataMapper.Update( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( identityMap, dataMapper ).Save( customer );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/DockRepositoryTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/DockRepositoryTest.cs
new file mode 100644
index 0000000..5d17679
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/DockRepositoryTest.cs
@@ -0,0 +1,38 @@
+using Marina.DataAccess.DataMappers;
+using Marina.DataAccess.Repositories;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess.Repositories {
+ [TestFixture]
+ public class DockRepositoryTest {
+ private MockRepository _mockery;
+ private IDockDataMapper mockMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ mockMapper = _mockery.DynamicMock< IDockDataMapper >( );
+ }
+
+ public IDockRepository CreateSUT() {
+ return new DockRepository( mockMapper );
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_retrieve_dock_by_id() {
+ IDock dock = _mockery.DynamicMock< IDock >( );
+ long dockId = 2;
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( mockMapper.FindBy( dockId ) ).Return( dock );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( dock, CreateSUT( ).FindBy( dockId ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/IdentityMapTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/IdentityMapTest.cs
new file mode 100644
index 0000000..9ff01c8
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/IdentityMapTest.cs
@@ -0,0 +1,71 @@
+using Marina.DataAccess;
+using Marina.DataAccess.Exceptions;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.DataAccess.Repositories {
+ [TestFixture]
+ public class IdentityMapTest {
+ public IIdentityMap< IDomainObject > CreateSUT() {
+ return new IdentityMap< IDomainObject >( );
+ }
+
+ // should not be able to add an object with an id of -1
+
+ [Test]
+ public void Should_be_able_to_add_a_new_domain_object_to_the_identitiy_map() {
+ IDomainObject objectThatHasBeenAddedToMap = new DomainObject( 1 );
+ IDomainObject objectThatHasNotBeenAddedToMap = new DomainObject( 2 );
+
+ IIdentityMap< IDomainObject > map = CreateSUT( );
+ map.Add( objectThatHasBeenAddedToMap );
+
+ Assert.IsTrue( map.ContainsObjectWithIdOf( objectThatHasBeenAddedToMap.ID( ) ) );
+ Assert.IsFalse( map.ContainsObjectWithIdOf( objectThatHasNotBeenAddedToMap.ID( ) ) );
+ }
+
+ [Test]
+ public void Should_return_true_if_searching_for_a_() {
+ IIdentityMap< IDomainObject > map = CreateSUT( );
+
+ int id = 1;
+ map.Add( new DomainObject( id ) );
+
+ Assert.IsTrue( map.ContainsObjectWithIdOf( id ) );
+ Assert.IsFalse( map.ContainsObjectWithIdOf( 2 ) );
+ }
+
+ [Test]
+ public void Should_be_able_to_retrieve_an_object_that_has_been_added_to_the_map() {
+ IIdentityMap< IDomainObject > map = CreateSUT( );
+ IDomainObject objectAddedToMap = new DomainObject( 1 );
+ map.Add( objectAddedToMap );
+
+ Assert.AreEqual( objectAddedToMap, map.FindObjectWithIdOf( 1 ) );
+ }
+
+ [Test]
+ public void Should_return_null_if_the_object_is_not_in_the_map() {
+ Assert.IsNull( CreateSUT( ).FindObjectWithIdOf( 1 ) );
+ }
+
+ [Test]
+ [ExpectedException( typeof( ObjectAlreadyAddedToIdentityMapException ) )]
+ public void Should_not_be_able_to_add_an_object_that_has_already_been_added() {
+ IIdentityMap< IDomainObject > map = CreateSUT( );
+ IDomainObject addedObject = new DomainObject( 1 );
+ map.Add( addedObject );
+ map.Add( addedObject );
+ }
+
+ [Test]
+ [ExpectedException( typeof( ObjectAlreadyAddedToIdentityMapException ) )]
+ public void Should_not_be_able_to_add_an_object_with_the_same_id_as_one_that_was_already_added() {
+ IIdentityMap< IDomainObject > map = CreateSUT( );
+ int id = 1;
+ map.Add( new DomainObject( id ) );
+ map.Add( new DomainObject( id ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/SlipRepositoryTest.cs b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/SlipRepositoryTest.cs
new file mode 100644
index 0000000..31b5d7a
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/DataAccess/Repositories/SlipRepositoryTest.cs
@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using Marina.DataAccess.DataMappers;
+using Marina.DataAccess.Repositories;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.DataAccess.Repositories {
+ [TestFixture]
+ public class SlipRepositoryTest {
+ private MockRepository _mockery;
+ private ISlipDataMapper _mockMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockMapper = _mockery.DynamicMock< ISlipDataMapper >( );
+ }
+
+ public ISlipsRepository CreateSUT() {
+ return new SlipsRepository( _mockMapper );
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_convert_from_table_to_a_domain_object() {
+ ISlip unleasedSlip = _mockery.DynamicMock< ISlip >( );
+ ISlip leasedSlip = _mockery.DynamicMock< ISlip >( );
+
+ IList< ISlip > slips = new List< ISlip >( );
+ slips.Add( unleasedSlip );
+ slips.Add( leasedSlip );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( unleasedSlip.IsLeased( ) ).Return( false );
+ SetupResult.For( leasedSlip.IsLeased( ) ).Return( true );
+
+ Expect.Call( _mockMapper.AllSlips( ) ).Return( new RichEnumerable< ISlip >( slips ) );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ IRichList< ISlip > foundSlips = ListFactory.From( CreateSUT( ).AllAvailableSlips( ) );
+
+ Assert.IsTrue( foundSlips.Contains( unleasedSlip ) );
+ Assert.IsFalse( foundSlips.Contains( leasedSlip ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Domain/CustomerRegistrationTest.cs b/slips/src/test/Marina.Test/Unit/Domain/CustomerRegistrationTest.cs
new file mode 100644
index 0000000..dce27ad
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Domain/CustomerRegistrationTest.cs
@@ -0,0 +1,50 @@
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Domain {
+ [TestFixture]
+ public class CustomerRegistrationTest {
+ public IRegistration CreateSUT( string userName, string password ) {
+ return new CustomerRegistration( userName, password, "mo", "khan", "4036813389", "calgary" );
+ }
+
+ [Test]
+ public void Should_not_allow_blank_password() {
+ string blankPassword = string.Empty;
+ IRegistration registration = CreateSUT( "username", blankPassword );
+ IRichList< IBrokenRule > brokenRules = ListFactory.From( registration.BrokenRules( ) );
+
+ Assert.IsFalse( registration.IsValid( ) );
+ Assert.AreEqual( "Password cannot be blank", brokenRules[ 0 ].Message( ) );
+ }
+
+ [Test]
+ public void Should_not_allow_blank_username() {
+ string blankUserName = string.Empty;
+ IRegistration registration = CreateSUT( blankUserName, "password" );
+ IRichList< IBrokenRule > brokenRules = ListFactory.From( registration.BrokenRules( ) );
+
+ Assert.IsFalse( registration.IsValid( ) );
+ Assert.AreEqual( "Username cannot be blank", brokenRules[ 0 ].Message( ) );
+ }
+
+ [Test]
+ public void Should_be_valid() {
+ Assert.IsTrue( CreateSUT( "username", "password" ).IsValid( ) );
+ }
+
+ [Test]
+ public void Shoud_return_no_broken_rules() {
+ IRegistration registration = CreateSUT( "userName", "PASSWORD" );
+ IRichList< IBrokenRule > brokenRules = ListFactory.From( registration.BrokenRules( ) );
+ Assert.AreEqual( 0, brokenRules.Count );
+ }
+
+ [Test]
+ public void Should_be_equal() {
+ Assert.AreEqual( CreateSUT( "mokhan", "password" ), CreateSUT( "mokhan", "password" ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Domain/CustomerTest.cs b/slips/src/test/Marina.Test/Unit/Domain/CustomerTest.cs
new file mode 100644
index 0000000..604b049
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Domain/CustomerTest.cs
@@ -0,0 +1,118 @@
+using System;
+using Marina.Domain;
+using Marina.Domain.Exceptions;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Domain {
+ [TestFixture]
+ public class CustomerTest {
+ private MockRepository _mockery;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ }
+
+ public ICustomer CreateSUT() {
+ return new Customer( );
+ }
+
+ [Test]
+ public void Should_be_able_to_register_a_new_boat() {
+ ICustomer customer = CreateSUT( );
+
+ Assert.AreEqual( 0, ListFactory.From( customer.RegisteredBoats( ) ).Count );
+ customer.RegisterBoat( ObjectMother.Boat( ) );
+ Assert.AreEqual( 1, ListFactory.From( customer.RegisteredBoats( ) ).Count );
+ }
+
+ [Test]
+ public void Should_not_be_able_to_register_an_already_registered_boat() {
+ ICustomer customer = CreateSUT( );
+ IBoat boat = ObjectMother.Boat( );
+ customer.RegisterBoat( boat );
+ customer.RegisterBoat( boat );
+
+ Assert.AreEqual( 1, ListFactory.From( customer.RegisteredBoats( ) ).Count );
+ }
+
+ [Test]
+ public void Should_be_able_to_lease_a_slip() {
+ ICustomer customer = CreateSUT( );
+ ISlip slip = ObjectMother.Slip( );
+ ILeaseDuration duration = LeaseDurations.Monthly;
+
+ customer.Lease( slip, duration );
+
+ Assert.AreEqual( 1, ListFactory.From( customer.Leases( ) ).Count );
+ }
+
+ [Test]
+ [ExpectedException( typeof( SlipIsAlreadyLeasedException ) )]
+ public void Should_not_be_able_to_lease_a_slip_that_is_already_leased() {
+ ISlip slip = _mockery.DynamicMock< ISlip >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( slip.IsLeased( ) ).Return( true );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ ICustomer customer = CreateSUT( );
+ customer.Lease( slip, LeaseDurations.Yearly );
+ Assert.AreEqual( 0, ListFactory.From( customer.Leases( ) ).Count );
+ }
+ }
+
+ [Test]
+ public void Should_be_able_to_register_an_unregistered_boat() {
+ string registrationNumber = "435535";
+ string manufacturer = "YAMAHA";
+ DateTime yearOfModel = new DateTime( 1990, 01, 01 );
+ long lengthInFeet = 100;
+
+ ICustomer customer = CreateSUT( );
+ customer.RegisterBoat( registrationNumber, manufacturer, yearOfModel, lengthInFeet );
+
+ IRichList< IBoat > boats = ListFactory.From( customer.RegisteredBoats( ) );
+
+ Assert.AreEqual( 1, boats.Count );
+ Assert.AreEqual( registrationNumber, boats[ 0 ].RegistrationNumber( ) );
+ Assert.AreEqual( manufacturer, boats[ 0 ].Manufacturer( ) );
+ Assert.AreEqual( yearOfModel, boats[ 0 ].YearOfModel( ) );
+ Assert.AreEqual( lengthInFeet, boats[ 0 ].LengthInFeet( ) );
+ }
+
+ [Test]
+ public void Should_be_able_to_register_an_account() {
+ ICustomer customer = CreateSUT( );
+ customer.RegisterAccount( "username", "password", "mo", "khan", "4036813389", "calgary" );
+ IRegistration registration = customer.Registration( );
+
+ Assert.AreEqual( "username", registration.Username( ) );
+ Assert.AreEqual( "password", registration.Password( ) );
+ Assert.AreEqual( "mo", registration.FirstName( ) );
+ Assert.AreEqual( "khan", registration.LastName( ) );
+ Assert.AreEqual( "4036813389", registration.PhoneNumber( ) );
+ Assert.AreEqual( "calgary", registration.City( ) );
+ }
+
+ [Test]
+ public void should_have_no_registration_information() {
+ IRegistration registration = CreateSUT( ).Registration( );
+ Assert.AreEqual( "", registration.Username( ) );
+ Assert.AreEqual( "", registration.Password( ) );
+ }
+
+ [Test]
+ public void Should_be_able_to_update_the_registration_information() {
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+ ICustomer customer = CreateSUT( );
+ customer.UpdateRegistrationTo( registration );
+ Assert.AreEqual( registration, customer.Registration( ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Domain/DockTest.cs b/slips/src/test/Marina.Test/Unit/Domain/DockTest.cs
new file mode 100644
index 0000000..7d4405a
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Domain/DockTest.cs
@@ -0,0 +1,24 @@
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Domain {
+ [TestFixture]
+ public class DockTest {
+ private static IDock CreateSUT( params IUtility[] utilities ) {
+ return new Dock( 1, "dock a", ObjectMother.Location( ), Utilities.For( utilities ) );
+ }
+
+ [Test]
+ public void Should_be_able_to_tell_if_a_utility_is_enabled_at_the_dock() {
+ IDock dock = CreateSUT( Utilities.Water );
+ Assert.IsTrue( dock.IsUtilityEnabled( Utilities.Water ) );
+ Assert.IsFalse( dock.IsUtilityEnabled( Utilities.Electrical ) );
+
+ dock = CreateSUT( Utilities.Water, Utilities.Electrical );
+ Assert.IsTrue( dock.IsUtilityEnabled( Utilities.Water ) );
+ Assert.IsTrue( dock.IsUtilityEnabled( Utilities.Electrical ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Domain/LeaseDurationTest.cs b/slips/src/test/Marina.Test/Unit/Domain/LeaseDurationTest.cs
new file mode 100644
index 0000000..dab44f2
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Domain/LeaseDurationTest.cs
@@ -0,0 +1,45 @@
+using System;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Domain {
+ [TestFixture]
+ public class LeaseDurationTest {
+ [Test]
+ public void Should_return_daily_lease_duration() {
+ DateTime yesterday = DateTime.Now.AddDays( -1 );
+ DateTime today = DateTime.Now;
+
+ ILeaseDuration duration = LeaseDurations.FindFor( yesterday, today );
+ Assert.AreEqual( LeaseDurations.Daily, duration );
+ }
+
+ [Test]
+ public void Should_return_weekly_lease_duration() {
+ DateTime aWeekAgo = DateTime.Now.AddDays( -7 ).Date;
+ DateTime today = DateTime.Now.Date;
+
+ ILeaseDuration duration = LeaseDurations.FindFor( aWeekAgo, today );
+ Assert.AreEqual( LeaseDurations.Weekly, duration );
+ }
+
+ [Test]
+ public void Should_return_monthly_lease_duration() {
+ DateTime aMonthAgo = DateTime.Now.AddDays( -30 );
+ DateTime today = DateTime.Now;
+
+ ILeaseDuration duration = LeaseDurations.FindFor( aMonthAgo, today );
+ Assert.AreEqual( LeaseDurations.Monthly, duration );
+ }
+
+ [Test]
+ public void Should_return_yearly_lease_duration() {
+ DateTime aYearAgo = DateTime.Now.AddDays( -365 );
+ DateTime today = DateTime.Now;
+
+ ILeaseDuration duration = LeaseDurations.FindFor( aYearAgo, today );
+ Assert.AreEqual( LeaseDurations.Yearly, duration );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Domain/SlipTest.cs b/slips/src/test/Marina.Test/Unit/Domain/SlipTest.cs
new file mode 100644
index 0000000..300a441
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Domain/SlipTest.cs
@@ -0,0 +1,78 @@
+using System;
+using Marina.Domain;
+using Marina.Domain.Exceptions;
+using Marina.Domain.Interfaces;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Domain {
+ [TestFixture]
+ public class SlipTest {
+ public ISlip CreateSUT() {
+ return new Slip( -1, ObjectMother.Dock( ), 100, 100, false );
+ }
+
+ [Test]
+ public void Should_not_be_leased_to_anyone() {
+ Assert.IsFalse( CreateSUT( ).IsLeased( ) );
+ }
+
+ //[Test]
+ //public void Should_be_able_to_lease_to_a_customer()
+ //{
+ // ICustomer customer = ObjectMother.Customer();
+ // ISlip slip = CreateSUT();
+ // ILeaseDuration durationOfLease = LeaseDurations.Daily;
+
+ // ISlipLease lease = slip.LeaseTo(customer, durationOfLease);
+
+ // Assert.AreEqual(customer, lease.Owner());
+ // Assert.AreEqual(slip, lease.Slip());
+ // Assert.AreEqual(durationOfLease, lease.Duration());
+ // Assert.AreEqual(DateTime.Now.Date, lease.StartDate());
+ //}
+
+ [Test]
+ public void Lease_should_expire_at_11_am_the_following_day() {
+ DateTime elevenAmTomorrow = DateTime.Now.AddDays( 1 ).Date.AddHours( 11 );
+ ISlipLease lease = CreateSUT( ).LeaseTo( ObjectMother.Customer( ), LeaseDurations.Daily );
+ Assert.AreEqual( elevenAmTomorrow, lease.ExpiryDate( ) );
+ }
+
+ [Test]
+ public void Lease_should_expire_in_seven_days_on_the_eleventh_hour() {
+ DateTime oneWeekFromToday = DateTime.Now.AddDays( 7 ).Date.AddHours( 11 );
+ ISlipLease lease = CreateSUT( ).LeaseTo( ObjectMother.Customer( ), LeaseDurations.Weekly );
+ Assert.AreEqual( oneWeekFromToday, lease.ExpiryDate( ) );
+ }
+
+ [Test]
+ public void Lease_should_expire_in_thirty_days_on_the_eleventh_hour() {
+ DateTime oneMonthFromToday = DateTime.Now.AddDays( 30 ).Date.AddHours( 11 );
+ ISlipLease lease = CreateSUT( ).LeaseTo( ObjectMother.Customer( ), LeaseDurations.Monthly );
+ Assert.AreEqual( oneMonthFromToday, lease.ExpiryDate( ) );
+ }
+
+ [Test]
+ public void Lease_should_expire_in_365_days_on_the_eleventh_hour() {
+ DateTime oneYearFromToday = DateTime.Now.AddDays( 365 ).Date.AddHours( 11 );
+ ISlipLease lease = CreateSUT( ).LeaseTo( ObjectMother.Customer( ), LeaseDurations.Yearly );
+ Assert.AreEqual( oneYearFromToday, lease.ExpiryDate( ) );
+ }
+
+ [Test]
+ public void Should_be_leased_to_an_owner() {
+ ISlip slip = CreateSUT( );
+ slip.LeaseTo( ObjectMother.Customer( ), LeaseDurations.Yearly );
+ Assert.IsTrue( slip.IsLeased( ), "Should be leased to an owner" );
+ }
+
+ [Test]
+ [ExpectedException( typeof( SlipIsAlreadyLeasedException ) )]
+ public void Should_return_current_lease_if_it_is_already_leased_to_a_customer() {
+ ISlip slip = CreateSUT( );
+ slip.LeaseTo( ObjectMother.Customer( ), LeaseDurations.Yearly );
+ slip.LeaseTo( ObjectMother.Customer( ), LeaseDurations.Weekly );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Domain/UtilitiesTest.cs b/slips/src/test/Marina.Test/Unit/Domain/UtilitiesTest.cs
new file mode 100644
index 0000000..c01d5d4
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Domain/UtilitiesTest.cs
@@ -0,0 +1,36 @@
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Domain {
+ [TestFixture]
+ public class UtilitiesTest {
+ [Test]
+ public void Should_be_equal_to_a_single_utility() {
+ IUtility utility = Utilities.For( Utilities.Electrical );
+ Assert.IsTrue( utility.IsEnabled( Utilities.Electrical ) );
+ }
+
+ [Test]
+ public void Should_be_equal_to_two_utilities() {
+ IUtility utility = Utilities.For( Utilities.Electrical, Utilities.Water );
+
+ Assert.IsTrue( utility.IsEnabled( Utilities.Electrical ) );
+ Assert.IsTrue( utility.IsEnabled( Utilities.Water ) );
+ }
+
+ [Test]
+ public void Should_not_be_equal_to_either_utilities() {
+ IUtility utility = Utilities.For( null );
+
+ Assert.IsFalse( utility.IsEnabled( Utilities.Electrical ) );
+ Assert.IsFalse( utility.IsEnabled( Utilities.Water ) );
+ }
+
+ [Test]
+ public void Should_have_water_enabled() {
+ IUtility utility = Utilities.For( null, Utilities.Water );
+ Assert.IsTrue( utility.IsEnabled( Utilities.Water ) );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/Interfaces/LogTest.cs b/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/Interfaces/LogTest.cs
new file mode 100644
index 0000000..504d598
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/Interfaces/LogTest.cs
@@ -0,0 +1,36 @@
+using Marina.Infrastructure.Container;
+using Marina.Infrastructure.Logging.Interfaces;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Infrastructure.Logging.Interfaces {
+ [TestFixture]
+ public class LogTest {
+ private MockRepository mockery;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ }
+
+ [Test]
+ public void Should_leverage_factory_to_return_a_logger_to_the_client( ) {
+ ILog mockLog = mockery.DynamicMock< ILog >( );
+ ILogFactory mockLogFactory = mockery.DynamicMock< ILogFactory >( );
+
+ IDependencyContainer mockContainer = mockery.DynamicMock< IDependencyContainer >( );
+
+ using ( mockery.Record( ) ) {
+ Expect.Call( mockContainer.GetMeAnImplementationOfAn< ILogFactory >( ) ).Return( mockLogFactory );
+ Expect.Call( mockLogFactory.CreateFor( typeof( LogTest ) ) ).Return( mockLog );
+ }
+
+ using ( mockery.Playback( ) ) {
+ Resolve.InitializeWith( mockContainer );
+ ILog log = Log.For( this );
+ Assert.AreEqual( mockLog, log );
+ Resolve.InitializeWith( null );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogFactoryTest.cs b/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogFactoryTest.cs
new file mode 100644
index 0000000..7827274
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogFactoryTest.cs
@@ -0,0 +1,19 @@
+using Marina.Infrastructure.Logging.Interfaces;
+using Marina.Infrastructure.Logging.TextWriterLogging;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Infrastructure.TextWriterLogging {
+ [TestFixture]
+ public class TextWriterLogFactoryTest {
+ [Test]
+ public void Should_create_a_text_writer_log( ) {
+ ILog log = CreateSUT( ).CreateFor( this.GetType( ) );
+ Assert.IsNotNull( log );
+ Assert.IsInstanceOfType( typeof( TextWriterLog ), log );
+ }
+
+ private ILogFactory CreateSUT( ) {
+ return new TextWriterLogFactory( );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogTest.cs b/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogTest.cs
new file mode 100644
index 0000000..526590c
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Infrastructure/Logging/TextWriterLogging/TextWriterLogTest.cs
@@ -0,0 +1,26 @@
+using System.IO;
+using System.Text;
+using Marina.Infrastructure.Logging.Interfaces;
+using Marina.Infrastructure.Logging.TextWriterLogging;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Infrastructure.TextWriterLogging {
+ [TestFixture]
+ public class TextWriterLogTest {
+ [Test]
+ public void Should_log_message_to_backing_store( ) {
+ string expectedMessage = "Message";
+
+ StringWriter writer = new StringWriter( new StringBuilder( ) );
+
+ ILog consoleLogger = CreateSUT( writer );
+ consoleLogger.Informational( expectedMessage );
+
+ Assert.AreEqual( expectedMessage, writer.ToString( ).Trim( ) );
+ }
+
+ private ILog CreateSUT( TextWriter writer ) {
+ return new TextWriterLog( writer );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Infrastructure/TransformTest.cs b/slips/src/test/Marina.Test/Unit/Infrastructure/TransformTest.cs
new file mode 100644
index 0000000..49f67ac
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Infrastructure/TransformTest.cs
@@ -0,0 +1,37 @@
+using System;
+using System.Data;
+using Marina.Infrastructure;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Infrastructure {
+ [TestFixture]
+ public class TransformerTest {
+ [Test]
+ public void Should_be_able_to_cast_to_the_actual_type_of_the_underlying_object( ) {
+ object item = new Item( );
+
+ Item result = CreateSUT( item ).To< Item >( );
+ Assert.AreEqual( item, result );
+ }
+
+ [ExpectedException( typeof( NullReferenceException ) )]
+ [Test]
+ public void Should_not_be_able_to_cast_from_null_to_a_type( ) {
+ CreateSUT( null ).To< Item >( );
+ }
+
+ [ExpectedException( typeof( InvalidCastException ) )]
+ [Test]
+ public void Should_not_be_able_to_cast_from_one_instance_to_a_non_assignable_type( ) {
+ Item item = new Item( );
+
+ CreateSUT( item ).To< IDbConnection >( );
+ }
+
+ private ITransformer CreateSUT( object item ) {
+ return new Transformer( item );
+ }
+
+ private class Item {}
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/AvailableSlipsPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/AvailableSlipsPresenterTest.cs
new file mode 100644
index 0000000..5fa950a
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/AvailableSlipsPresenterTest.cs
@@ -0,0 +1,51 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class AvailableSlipsPresenterTest {
+ private MockRepository mockery;
+ private ICatalogTasks mockTask;
+ private IAvailableSlipsView mockView;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ mockTask = mockery.DynamicMock< ICatalogTasks >( );
+ mockView = mockery.DynamicMock< IAvailableSlipsView >( );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_retrieve_all_available_slips_on_initialize( ) {
+ using ( mockery.Record( ) ) {
+ Expect.Call( mockTask.GetAllAvailableSlips( ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_the_available_slips( ) {
+ IEnumerable< SlipDisplayDTO > availableSlips = new List< SlipDisplayDTO >( );
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockTask.GetAllAvailableSlips( ) ).Return( availableSlips );
+ mockView.Display( availableSlips );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ private IAvailableSlipsPresenter CreateSUT( ) {
+ return new AvailableSlipsPresenter( mockView, mockTask );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/CurrentLeasesPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/CurrentLeasesPresenterTest.cs
new file mode 100644
index 0000000..a9f2cb1
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/CurrentLeasesPresenterTest.cs
@@ -0,0 +1,63 @@
+using System.Collections.Generic;
+using Marina.Presentation;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class CurrentLeasesPresenterTest {
+ private MockRepository _mockery;
+ private ILeaseTasks task;
+ private IHttpRequest mockRequest;
+ private ICurrentLeasesView mockView;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ task = _mockery.DynamicMock< ILeaseTasks >( );
+ mockRequest = _mockery.DynamicMock< IHttpRequest >( );
+ mockView = _mockery.DynamicMock< ICurrentLeasesView >( );
+ }
+
+ public ICurrentLeasesPresenter CreateSUT() {
+ return new CurrentLeasesPresenter( mockView, mockRequest, task );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_retrieve_all_leases_for_customer_id() {
+ long customerId = 32;
+ IList< DisplayLeaseDTO > dtos = new List< DisplayLeaseDTO >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
+ Expect.Call( task.FindAllLeasesFor( customerId ) ).Return( dtos );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_the_found_leases_on_the_view() {
+ IList< DisplayLeaseDTO > dtos = new List< DisplayLeaseDTO >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult
+ .For( task.FindAllLeasesFor( 0 ) )
+ .IgnoreArguments( )
+ .Return( dtos );
+
+ mockView.Display( dtos );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/CustomerRegistrationPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/CustomerRegistrationPresenterTest.cs
new file mode 100644
index 0000000..e571683
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/CustomerRegistrationPresenterTest.cs
@@ -0,0 +1,69 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class CustomerRegistrationPresenterTest {
+ private MockRepository mockery;
+ private ICustomerRegistrationPresentationMapper mockMapper;
+ private ICustomerRegistrationView mockView;
+ private IRegistrationTasks mockTask;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ mockMapper = mockery.DynamicMock< ICustomerRegistrationPresentationMapper >( );
+ mockView = mockery.DynamicMock< ICustomerRegistrationView >( );
+ mockTask = mockery.DynamicMock< IRegistrationTasks >( );
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_convert_view_data_to_dto( ) {
+ using ( mockery.Record( ) ) {
+ Expect.Call( mockMapper.MapFrom( mockView ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).RegisterCustomer( );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_task_to_submit_new_registration_information( ) {
+ RegisterCustomerDTO customerRegistrationDTO = ObjectMother.CustomerRegistrationDTO( );
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockMapper.MapFrom( mockView ) ).Return( customerRegistrationDTO );
+ Expect.Call( mockTask.RegisterNew( customerRegistrationDTO ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).RegisterCustomer( );
+ }
+ }
+
+ [Test]
+ public void Should_display_response_on_view( ) {
+ IEnumerable< DisplayResponseLineDTO > responseDTO =
+ ObjectMother.EnumerableDisplayResponseLineDTO( );
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockTask.RegisterNew( null ) ).IgnoreArguments( ).Return( responseDTO );
+ mockView.Display( responseDTO );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).RegisterCustomer( );
+ }
+ }
+
+ private ICustomerRegistrationPresenter CreateSUT( ) {
+ return new CustomerRegistrationPresenter( mockView, mockMapper, mockTask );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/DockPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/DockPresenterTest.cs
new file mode 100644
index 0000000..1fc2a26
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/DockPresenterTest.cs
@@ -0,0 +1,90 @@
+using System.Collections.Generic;
+using Marina.Presentation;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Test.Utility;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class DockPresenterTest {
+ private MockRepository mockery;
+ private IDockView mockView;
+ private ICatalogTasks mockTask;
+ private IHttpRequest mockRequest;
+
+ private IDockPresenter CreateSUT( ) {
+ return new DockPresenter( mockView, mockRequest, mockTask );
+ }
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ mockView = mockery.DynamicMock< IDockView >( );
+ mockTask = mockery.DynamicMock< ICatalogTasks >( );
+ mockRequest = mockery.DynamicMock< IHttpRequest >( );
+ }
+
+ [Test]
+ public void Should_leverage_its_task_to_retrieve_the_dock_information( ) {
+ long dockId = 1;
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.DockId ) ).Return( dockId );
+ Expect.Call( mockTask.GetDockInformationBy( dockId ) ).Return( null );
+ }
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_dock_information( ) {
+ DockDisplayDTO dto = ObjectMother.DockDisplayDTO( );
+ int dockId = 2;
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.DockId ) ).Return( dockId );
+ SetupResult.For( mockTask.GetDockInformationBy( dockId ) ).Return( dto );
+ mockView.Display( dto );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_task_to__load_list_of_locations_on_initialize( ) {
+ long dockId = 1;
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.DockId ) ).Return( dockId );
+ Expect.Call( mockTask.GetAvailableSlipsForDockBy( dockId ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_the_available_slips( ) {
+ IEnumerable< SlipDisplayDTO > availableSlips = new List< SlipDisplayDTO >( );
+ long dockId = 2;
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.DockId ) ).Return( dockId );
+ SetupResult.For( mockTask.GetAvailableSlipsForDockBy( dockId ) ).Return( availableSlips );
+ mockView.Display( availableSlips );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/LeaseSlipPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/LeaseSlipPresenterTest.cs
new file mode 100644
index 0000000..d53f9f9
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/LeaseSlipPresenterTest.cs
@@ -0,0 +1,100 @@
+using Marina.Presentation;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Test.Utility;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class LeaseSlipPresenterTest {
+ private MockRepository _mockery;
+ private IHttpRequest _mockRequest;
+ private ICatalogTasks _mockTask;
+ private ILeaseSlipView _mockView;
+ private ILeaseTasks _mockLeaseTasks;
+ private ILeaseRequestDtoFromHttpRequestMapper _mockMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockRequest = _mockery.DynamicMock< IHttpRequest >( );
+ _mockTask = _mockery.DynamicMock< ICatalogTasks >( );
+ _mockLeaseTasks = _mockery.DynamicMock< ILeaseTasks >( );
+ _mockView = _mockery.DynamicMock< ILeaseSlipView >( );
+
+ _mockMapper = _mockery.DynamicMock< ILeaseRequestDtoFromHttpRequestMapper >( );
+ }
+
+ public ILeaseSlipPresenter CreateSUT() {
+ return new LeaseSlipPresenter( _mockView, _mockRequest, _mockTask, _mockLeaseTasks, _mockMapper );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_retrieve_information_on_slip() {
+ long slipId = 66;
+ SlipDisplayDTO slip = ObjectMother.SlipDisplayDTO( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockRequest.ParsePayloadFor( PayloadKeys.SlipId ) ).Return( slipId );
+ Expect.Call( _mockTask.FindSlipBy( slipId ) ).Return( slip );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_found_slip_on_view() {
+ SlipDisplayDTO slip = ObjectMother.SlipDisplayDTO( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockTask.FindSlipBy( 0 ) ).IgnoreArguments( ).Return( slip );
+ _mockView.Display( slip );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_save_lease_slip_when_customer_submits_a_request() {
+ long customerId = 2;
+ long slipId = 3;
+
+ SubmitLeaseRequestDTO request = new SubmitLeaseRequestDTO( customerId, slipId, "weekly" );
+ DisplayResponseLineDTO response = new DisplayResponseLineDTO( "" );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockMapper.MapFrom( _mockRequest ) ).Return( request );
+ Expect.Call( _mockLeaseTasks.RequestLeaseUsing( request ) ).Return( response );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).SubmitLeaseRequest( );
+ }
+ }
+
+ [Test]
+ public void Should_display_response_from_lease_request_on_the_view() {
+ SubmitLeaseRequestDTO request = new SubmitLeaseRequestDTO( 1, 1, "weekly" );
+ DisplayResponseLineDTO response = new DisplayResponseLineDTO( "" );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult
+ .For( _mockLeaseTasks.RequestLeaseUsing( request ) )
+ .IgnoreArguments( )
+ .Return( response );
+ _mockView.Display( response );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).SubmitLeaseRequest( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/LoginPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/LoginPresenterTest.cs
new file mode 100644
index 0000000..d5dd994
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/LoginPresenterTest.cs
@@ -0,0 +1,62 @@
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Test.Utility;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class LoginPresenterTest {
+ private MockRepository mockery;
+ private ILoginView mockView;
+ private IAuthenticationTask mockTask;
+ private ILoginCredentialsMapper mockMapper;
+ private IHttpRequest mockRequest;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository( );
+ mockView = mockery.DynamicMock< ILoginView >( );
+ mockTask = mockery.DynamicMock< IAuthenticationTask >( );
+ mockRequest = mockery.DynamicMock< IHttpRequest >( );
+ mockMapper = mockery.DynamicMock< ILoginCredentialsMapper >( );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_check_if_credentials_are_correct() {
+ LoginCredentialsDTO credentials = ObjectMother.LoginCredentialsDTO( );
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockMapper.MapFrom( mockRequest ) ).Return( credentials );
+ Expect.Call( mockTask.AuthenticateUserUsing( credentials ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Login( );
+ }
+ }
+
+ [Test]
+ public void Should_display_response_messages_from_task() {
+ DisplayResponseLineDTO responseMessage = ObjectMother.DisplayResponseLineDTO( );
+ using ( mockery.Record( ) ) {
+ SetupResult
+ .For( mockTask.AuthenticateUserUsing( null ) )
+ .IgnoreArguments( )
+ .Return( responseMessage );
+ mockView.Display( responseMessage );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Login( );
+ }
+ }
+
+ private ILoginPresenter CreateSUT() {
+ return new LoginPresenter( mockView, mockRequest, mockTask, mockMapper );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/Mappers/CustomerRegistrationPresentationMapperTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/Mappers/CustomerRegistrationPresentationMapperTest.cs
new file mode 100644
index 0000000..29f9d21
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/Mappers/CustomerRegistrationPresentationMapperTest.cs
@@ -0,0 +1,52 @@
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Presentation.Views;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation.Mappers {
+ [TestFixture]
+ public class CustomerRegistrationPresentationMapperTest {
+ private MockRepository mockery;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ }
+
+ [Test]
+ public void Should_map_view_data_to_dto( ) {
+ ICustomerRegistrationView mockView = mockery.DynamicMock< ICustomerRegistrationView >( );
+ string userName = "mrMO";
+ string password = "password";
+ string firstName = "mo";
+ string lastName = "khan";
+ string phoneNumber = "(403)6813389";
+ string city = "calgary";
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockView.UserName( ) ).Return( userName );
+ SetupResult.For( mockView.Password( ) ).Return( password );
+ SetupResult.For( mockView.FirstName( ) ).Return( firstName );
+ SetupResult.For( mockView.LastName( ) ).Return( lastName );
+ SetupResult.For( mockView.PhoneNumber( ) ).Return( phoneNumber );
+ SetupResult.For( mockView.City( ) ).Return( city );
+ }
+
+ using ( mockery.Playback( ) ) {
+ RegisterCustomerDTO mappedDTO = CreateSUT( ).MapFrom( mockView );
+
+ Assert.AreEqual( mappedDTO.UserName, userName );
+ Assert.AreEqual( mappedDTO.Password, password );
+ Assert.AreEqual( mappedDTO.FirstName, firstName );
+ Assert.AreEqual( mappedDTO.LastName, lastName );
+ Assert.AreEqual( mappedDTO.Phone, phoneNumber );
+ Assert.AreEqual( mappedDTO.City, city );
+ }
+ }
+
+ private ICustomerRegistrationPresentationMapper CreateSUT( ) {
+ return new CustomerRegistrationPresentationMapper( );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/Mappers/LoginCredentialsMapperTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/Mappers/LoginCredentialsMapperTest.cs
new file mode 100644
index 0000000..4dae259
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/Mappers/LoginCredentialsMapperTest.cs
@@ -0,0 +1,35 @@
+using Marina.Presentation;
+using Marina.Presentation.Mappers;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation.Mappers {
+ [TestFixture]
+ public class LoginCredentialsMapperTest {
+ private MockRepository mockery;
+ private IHttpRequest mockRequest;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ mockRequest = mockery.DynamicMock< IHttpRequest >( );
+ }
+
+ [Test]
+ public void Should_map_username_from_request( ) {
+ using ( mockery.Record( ) ) {
+ Expect.Call( mockRequest.ParsePayloadFor( PayloadKeys.For( "uxUserNameTextBox" ) ) ).Return( null );
+ Expect.Call( mockRequest.ParsePayloadFor( PayloadKeys.For( "uxPasswordTextBox" ) ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).MapFrom( mockRequest );
+ }
+ }
+
+ private LoginCredentialsMapper CreateSUT( ) {
+ return new LoginCredentialsMapper( );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/Mappers/UpdateRegistrationPresentationMapperTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/Mappers/UpdateRegistrationPresentationMapperTest.cs
new file mode 100644
index 0000000..510756f
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/Mappers/UpdateRegistrationPresentationMapperTest.cs
@@ -0,0 +1,57 @@
+using Marina.Presentation;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation.Mappers {
+ [TestFixture]
+ public class UpdateRegistrationPresentationMapperTest {
+ private MockRepository mockery;
+ private IHttpRequest mockRequest;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ mockRequest = mockery.DynamicMock< IHttpRequest >( );
+ }
+
+ [RowTest]
+ [Row( 0, "username", "password", "mo", "khan", "4036813389", "calgary" )]
+ [Row( 0, "username1", "p@ssword", "m0", "khAAn", "d33d9", "toronto" )]
+ [Row( 0, "username2", "passw0rd", "m1", "kh@n", "4036d333389", "new york" )]
+ public void Should_map_the_data_from_the_view_to_the_dto( long customerId, string userName, string password,
+ string firstName,
+ string lastName, string phone, string city ) {
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
+ SetupResult.For( mockRequest.ParsePayloadFor( Create( "uxUserNameTextBox" ) ) ).Return( userName );
+ SetupResult.For( mockRequest.ParsePayloadFor( Create( "uxPasswordTextBox" ) ) ).Return( password );
+ SetupResult.For( mockRequest.ParsePayloadFor( Create( "uxFirstNameTextBox" ) ) ).Return( firstName );
+ SetupResult.For( mockRequest.ParsePayloadFor( Create( "uxLastNameTextBox" ) ) ).Return( lastName );
+ SetupResult.For( mockRequest.ParsePayloadFor( Create( "uxPhoneNumberTextBox" ) ) ).Return( phone );
+ SetupResult.For( mockRequest.ParsePayloadFor( Create( "uxCityTextBox" ) ) ).Return( city );
+ }
+
+ using ( mockery.Playback( ) ) {
+ UpdateCustomerRegistrationDTO dto = CreateSUT( ).MapFrom( mockRequest );
+ Assert.AreEqual( customerId, dto.CustomerId );
+ Assert.AreEqual( userName, dto.Username );
+ Assert.AreEqual( password, dto.Password );
+ Assert.AreEqual( firstName, dto.FirstName );
+ Assert.AreEqual( lastName, dto.LastName );
+ Assert.AreEqual( phone, dto.PhoneNumber );
+ Assert.AreEqual( city, dto.City );
+ }
+ }
+
+ public PayloadKey< string > Create( string controlId ) {
+ return PayloadKeys.For( controlId );
+ }
+
+ private IUpdateRegistrationPresentationMapper CreateSUT( ) {
+ return new UpdateRegistrationPresentationMapper( );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs
new file mode 100644
index 0000000..b7a3540
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/PayloadKeyTest.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Specialized;
+using Marina.Presentation;
+using MbUnit.Framework;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class PayloadKeyTest {
+ [Test]
+ public void Should_be_able_to_convert_an_item_from_the_payload_into_an_item_of_the_correct_type( ) {
+ string key = "DID";
+ int expectedValue = 1;
+
+ NameValueCollection payload = new NameValueCollection( );
+ payload.Add( key, expectedValue.ToString( ) );
+
+ int actualValue = CreateSUT< int >( key ).ParseFrom( payload );
+ Assert.AreEqual( expectedValue, actualValue );
+ }
+
+ [Test]
+ [ExpectedException( typeof( Exception ) )]
+ public void Should_not_be_able_to_parse_if_the_item_in_the_payload_does_not_match_the_data_type_for_the_key( ) {
+ NameValueCollection payload = new NameValueCollection( );
+ payload.Add( "DID", "NotAnInt" );
+ CreateSUT< int >( "DID" ).ParseFrom( payload );
+ }
+
+ [Test]
+ public void Should_be_able_to_implicitly_cast_to_a_string( ) {
+ string implictlyCasted = CreateSUT< int >( "DID" );
+ Assert.AreEqual( "DID", implictlyCasted );
+ }
+
+ [Test]
+ [ExpectedException( typeof( PayloadKeyNotFoundException ) )]
+ public void Should_return_default_value_if_key_is_not_in_payload( ) {
+ CreateSUT< string >( "NOTINPAYLOAD" ).ParseFrom( new NameValueCollection( ) );
+ }
+
+ private PayloadKey< T > CreateSUT< T >( string key ) {
+ return new PayloadKey< T >( key );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/RegisterBoatPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/RegisterBoatPresenterTest.cs
new file mode 100644
index 0000000..2daf6f2
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/RegisterBoatPresenterTest.cs
@@ -0,0 +1,67 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Test.Utility;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class RegisterBoatPresenterTest {
+ private MockRepository mockery;
+ private IRegisterBoatView mockView;
+ private IRegistrationTasks mockTask;
+ private IHttpRequest mockRequest;
+ private INewBoatRegistrationMapper mockMapper;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository( );
+ mockView = mockery.DynamicMock< IRegisterBoatView >( );
+ mockTask = mockery.DynamicMock< IRegistrationTasks >( );
+ mockRequest = mockery.DynamicMock< IHttpRequest >( );
+ mockMapper = mockery.DynamicMock< INewBoatRegistrationMapper >( );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_submit_new_boat_registration() {
+ IEnumerable< DisplayResponseLineDTO > response = ObjectMother.EnumerableDisplayResponseLineDTO( );
+ BoatRegistrationDTO boat = ObjectMother.BoatRegistrationDTO( );
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockMapper.MapFrom( mockRequest ) ).Return( boat );
+
+ Expect.Call( mockTask.AddNewBoatUsing( boat ) ).Return( response );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).SubmitRegistration( );
+ }
+ }
+
+ [Test]
+ public void Should_display_response_from_task_on_view() {
+ IEnumerable< DisplayResponseLineDTO > response = ObjectMother.EnumerableDisplayResponseLineDTO( );
+ BoatRegistrationDTO boat = ObjectMother.BoatRegistrationDTO( );
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockMapper.MapFrom( mockRequest ) ).Return( boat );
+ SetupResult.For( mockTask.AddNewBoatUsing( boat ) ).Return( response );
+
+ mockView.Display( response );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).SubmitRegistration( );
+ }
+ }
+
+ private IRegisterBoatPresenter CreateSUT() {
+ return new RegisterBoatPresenter( mockView, mockRequest, mockTask, mockMapper );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/UpdateRegistrationPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/UpdateRegistrationPresenterTest.cs
new file mode 100644
index 0000000..753ee83
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/UpdateRegistrationPresenterTest.cs
@@ -0,0 +1,92 @@
+using System.Collections.Generic;
+using Marina.Presentation;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Mappers;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Test.Utility;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class UpdateRegistrationPresenterTest {
+ private MockRepository mockery;
+ private IRegistrationTasks mockTask;
+ private IUpdateRegistrationView mockView;
+ private IUpdateRegistrationPresentationMapper mockMapper;
+ private IHttpRequest mockRequest;
+
+ [SetUp]
+ public void SetUp( ) {
+ mockery = new MockRepository( );
+ mockView = mockery.DynamicMock< IUpdateRegistrationView >( );
+ mockTask = mockery.DynamicMock< IRegistrationTasks >( );
+ mockMapper = mockery.DynamicMock< IUpdateRegistrationPresentationMapper >( );
+ mockRequest = mockery.DynamicMock< IHttpRequest >( );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_load_current_registration_information_for_customer( ) {
+ int customerId = 1;
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
+ Expect.Call( mockTask.LoadRegistrationFor( customerId ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_the_customer_registration_information_in_the_view( ) {
+ int customerId = 1;
+ CustomerRegistrationDisplayDTO customerRegistration = ObjectMother.DisplayCustomerRegistrationDTO( );
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
+ SetupResult.For( mockTask.LoadRegistrationFor( customerId ) ).Return( customerRegistration );
+ mockView.Display( customerRegistration );
+ }
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_task_to_submit_changed_registration_information( ) {
+ UpdateCustomerRegistrationDTO customer = ObjectMother.UpdateCustomerRegistrationDTO( );
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockMapper.MapFrom( mockRequest ) ).Return( customer );
+ Expect.Call( mockTask.UpdateRegistrationFor( customer ) ).Return( null );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).UpdateRegistration( );
+ }
+ }
+
+ [Test]
+ public void Should_display_response_on_view( ) {
+ IEnumerable< DisplayResponseLineDTO > responseDTO =
+ ObjectMother.EnumerableDisplayResponseLineDTO( );
+
+ using ( mockery.Record( ) ) {
+ SetupResult.For( mockTask.UpdateRegistrationFor( null ) ).IgnoreArguments( ).Return( responseDTO );
+ mockView.Display( responseDTO );
+ }
+
+ using ( mockery.Playback( ) ) {
+ CreateSUT( ).UpdateRegistration( );
+ }
+ }
+
+ private IUpdateCustomerRegistrationPresenter CreateSUT( ) {
+ return new UpdateCustomerRegistrationPresenter( mockView, mockRequest, mockTask, mockMapper );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Presentation/ViewRegisteredBoatsPresenterTest.cs b/slips/src/test/Marina.Test/Unit/Presentation/ViewRegisteredBoatsPresenterTest.cs
new file mode 100644
index 0000000..1443153
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Presentation/ViewRegisteredBoatsPresenterTest.cs
@@ -0,0 +1,62 @@
+using System.Collections.Generic;
+using Marina.Presentation;
+using Marina.Presentation.DTO;
+using Marina.Presentation.Presenters;
+using Marina.Presentation.Views;
+using Marina.Task;
+using Marina.Web;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Presentation {
+ [TestFixture]
+ public class ViewRegisteredBoatsPresenterTest {
+ private MockRepository _mockery;
+ private IRegistrationTasks _mockTask;
+ private IHttpRequest _mockRequest;
+ private IRegisteredBoatsView _mockView;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockTask = _mockery.DynamicMock< IRegistrationTasks >( );
+ _mockRequest = _mockery.DynamicMock< IHttpRequest >( );
+ _mockView = _mockery.DynamicMock< IRegisteredBoatsView >( );
+ }
+
+ public IViewRegisteredBoatsPresenter CreateSUT() {
+ return new ViewRegisteredBoatsPresenter( _mockView, _mockTask, _mockRequest );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_retrieve_all_registered_boats_for_customer() {
+ long customerId = 23;
+ IList< BoatRegistrationDTO > boats = new List< BoatRegistrationDTO >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
+ Expect.Call( _mockTask.AllBoatsFor( customerId ) ).Return( boats );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+
+ [Test]
+ public void Should_display_registered_boats_on_view() {
+ IList< BoatRegistrationDTO > boats = new List< BoatRegistrationDTO >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockTask.AllBoatsFor( 0 ) )
+ .IgnoreArguments( )
+ .Return( boats );
+
+ _mockView.Display( boats );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Initialize( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Task/CatalogTasksTest.cs b/slips/src/test/Marina.Test/Unit/Task/CatalogTasksTest.cs
new file mode 100644
index 0000000..1eae132
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Task/CatalogTasksTest.cs
@@ -0,0 +1,106 @@
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+using Marina.Task;
+using Marina.Task.Mappers;
+using Marina.Test.Utility;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Task {
+ [TestFixture]
+ public class CatalogTasksTest {
+ private MockRepository _mockery;
+ private ISlipsRepository _slipRepository;
+ private ISlipsToDisplayDTOMapper _slipMapper;
+ private IDockRepository _dockRepository;
+ private IDockToDisplayDTOMapper _dockMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _slipRepository = _mockery.DynamicMock< ISlipsRepository >( );
+ _dockRepository = _mockery.DynamicMock< IDockRepository >( );
+ _slipMapper = _mockery.DynamicMock< ISlipsToDisplayDTOMapper >( );
+ _dockMapper = _mockery.DynamicMock< IDockToDisplayDTOMapper >( );
+ }
+
+ public ICatalogTasks CreateSUT() {
+ return new CatalogTasks( _slipRepository, _slipMapper, _dockRepository, _dockMapper );
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_map_all_slips() {
+ IList< ISlip > availableSlips = new List< ISlip >( );
+ ISlip slip = _mockery.DynamicMock< ISlip >( );
+
+ availableSlips.Add( slip );
+
+ SlipDisplayDTO slipDTO = ObjectMother.SlipDisplayDTO( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _slipRepository.AllAvailableSlips( ) ).Return( availableSlips );
+ Expect.Call( _slipMapper.MapFrom( slip ) ).Return( slipDTO );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ IEnumerable< SlipDisplayDTO > allAvailableSlips = CreateSUT( ).GetAllAvailableSlips( );
+ Assert.IsTrue( ListFactory.From( allAvailableSlips ).Contains( slipDTO ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_repository_to_find_dock_by_id() {
+ long dockId = 1;
+ IDock dock = _mockery.DynamicMock< IDock >( );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _dockRepository.FindBy( dockId ) ).Return( dock );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).GetDockInformationBy( dockId );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_return_dto() {
+ long dockId = 1;
+ IDock dock = _mockery.DynamicMock< IDock >( );
+
+ DockDisplayDTO dto = ObjectMother.DockDisplayDTO( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _dockRepository.FindBy( dockId ) ).Return( dock );
+ Expect.Call( _dockMapper.MapFrom( dock ) ).Return( dto );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( dto, CreateSUT( ).GetDockInformationBy( dockId ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_repository_to_find_dock() {
+ long dockId = 1;
+ IDock dock = _mockery.DynamicMock< IDock >( );
+ ISlip slip = _mockery.DynamicMock< ISlip >( );
+
+ IList< ISlip > availableSlipsForDock = new List< ISlip >( );
+ availableSlipsForDock.Add( slip );
+
+ SlipDisplayDTO dto = ObjectMother.SlipDisplayDTO( );
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _dockRepository.FindBy( dockId ) ).Return( dock );
+ Expect.Call( _slipRepository.AllAvailableSlipsFor( dock ) ).Return( availableSlipsForDock );
+ Expect.Call( _slipMapper.MapFrom( slip ) ).Return( dto );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ IRichList< SlipDisplayDTO > slipsFound = ListFactory.From( CreateSUT( ).GetAvailableSlipsForDockBy( dockId ) );
+ Assert.IsTrue( slipsFound.Contains( dto ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs b/slips/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs
new file mode 100644
index 0000000..e645640
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs
@@ -0,0 +1,181 @@
+using Marina.Domain;
+using Marina.Domain.Exceptions;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+using Marina.Task;
+using Marina.Task.Mappers;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Task {
+ [TestFixture]
+ public class LeaseTasksTest {
+ private MockRepository _mockery;
+ private ICustomerRepository _customers;
+ private ILeaseToDtoMapper _mapper;
+ private ISlipsRepository _slips;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _customers = _mockery.DynamicMock< ICustomerRepository >( );
+ _slips = _mockery.DynamicMock< ISlipsRepository >( );
+ _mapper = _mockery.DynamicMock< ILeaseToDtoMapper >( );
+ }
+
+ public ILeaseTasks CreateSUT() {
+ return new LeaseTasks( _customers, _slips, _mapper );
+ }
+
+ [Test]
+ public void Should_leverage_repository_to_find_customer() {
+ long customerId = 87;
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _customers.FindBy( customerId ) ).Return( _mockery.DynamicMock< ICustomer >( ) );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).FindAllLeasesFor( customerId );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_mapper_to_convert_to_dto() {
+ long customerId = 99;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ ISlipLease lease = _mockery.DynamicMock< ISlipLease >( );
+ DisplayLeaseDTO dto = new DisplayLeaseDTO( "", "", "" );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.Leases( ) ).Return( ListFactory.For( lease ) );
+ SetupResult.For( _customers.FindBy( customerId ) ).Return( customer );
+ Expect.Call( _mapper.MapFrom( lease ) ).Return( dto );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ IRichList< DisplayLeaseDTO > returnedDtos = ListFactory.From( CreateSUT( ).FindAllLeasesFor( customerId ) );
+ Assert.AreEqual( 1, returnedDtos.Count );
+ Assert.IsTrue( returnedDtos.Contains( dto ) );
+ }
+ }
+
+ [Test]
+ public void Should_lookup_customer_from_repository_when_requesting_a_lease() {
+ long customerId = 87;
+ long slipId = 32;
+ SubmitLeaseRequestDTO request = new SubmitLeaseRequestDTO( customerId, slipId, "daily" );
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _customers.FindBy( customerId ) ).Return( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).RequestLeaseUsing( request );
+ }
+ }
+
+ [RowTest]
+ [Row( 99 )]
+ [Row( 87 )]
+ public void Should_lookup_slip_from_repository_when_requesting_a_lease( long slipId ) {
+ long customerId = 87;
+ SubmitLeaseRequestDTO request = new SubmitLeaseRequestDTO( customerId, slipId, "weekly" );
+ ISlip slip = _mockery.DynamicMock< ISlip >( );
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _customers.FindBy( 0 ) ).IgnoreArguments( ).Return( customer );
+ Expect.Call( _slips.FindBy( slipId ) ).Return( slip );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).RequestLeaseUsing( request );
+ }
+ }
+
+ [Test]
+ public void customer_should_attempt_to_lease_slip() {
+ long customerId = 87;
+ long slipId = 32;
+
+ string duration = "weekly";
+ SubmitLeaseRequestDTO request = new SubmitLeaseRequestDTO( customerId, slipId, duration );
+ ISlip slip = _mockery.DynamicMock< ISlip >( );
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _customers.FindBy( customerId ) ).Return( customer );
+ SetupResult.For( _slips.FindBy( slipId ) ).Return( slip );
+
+ customer.Lease( slip, LeaseDurations.FindBy( duration ) );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).RequestLeaseUsing( request );
+ }
+ }
+
+ [Test]
+ public void should_return_success_response_message() {
+ long customerId = 87;
+ long slipId = 32;
+
+ string duration = LeaseDurations.Daily.Name( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _customers.FindBy( customerId ) ).Return( _mockery.DynamicMock< ICustomer >( ) );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ DisplayResponseLineDTO response =
+ CreateSUT( ).RequestLeaseUsing( new SubmitLeaseRequestDTO( customerId, slipId, duration ) );
+ Assert.AreEqual( response.Message, "Success!" );
+ }
+ }
+
+ [Test]
+ public void Should_return_error_message_if_the_slip_is_already_leased() {
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult
+ .For( _customers.FindBy( 0 ) )
+ .IgnoreArguments( )
+ .Return( customer );
+
+ customer.Lease( null, null );
+ LastCall
+ .IgnoreArguments( )
+ .Throw( new SlipIsAlreadyLeasedException( ) );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ SubmitLeaseRequestDTO request = new SubmitLeaseRequestDTO( 1, 2, "weekly" );
+ DisplayResponseLineDTO response = CreateSUT( ).RequestLeaseUsing( request );
+ Assert.AreEqual( "Slip is already leased!", response.Message );
+ }
+ }
+
+ [Test]
+ public void Should_save_customer_back_to_repository() {
+ long customerId = 87;
+ long slipId = 32;
+
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult
+ .For( _customers.FindBy( customerId ) )
+ .Return( customer );
+ _customers.Save( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).RequestLeaseUsing( new SubmitLeaseRequestDTO( customerId, slipId, LeaseDurations.Daily.Name( ) ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Task/RegistrationTasksTest.cs b/slips/src/test/Marina.Test/Unit/Task/RegistrationTasksTest.cs
new file mode 100644
index 0000000..226fae0
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Task/RegistrationTasksTest.cs
@@ -0,0 +1,217 @@
+using System;
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+using Marina.Domain.Repositories;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+using Marina.Task;
+using Marina.Task.Mappers;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Task {
+ [TestFixture]
+ public class RegistrationTasksTest {
+ private MockRepository _mockery;
+ private ICustomerRepository _mockCustomerRepository;
+ private IBrokenRulesToDisplayItemMapper _mockMapper;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockCustomerRepository = _mockery.DynamicMock< ICustomerRepository >( );
+ _mockMapper = _mockery.DynamicMock< IBrokenRulesToDisplayItemMapper >( );
+ }
+
+ public IRegistrationTasks CreateSUT() {
+ return new RegistrationTasks( _mockMapper, _mockCustomerRepository );
+ }
+
+ [Test]
+ public void Should_leverage_repository_to_create_a_new_customer() {
+ string username = "username";
+ string password = "password";
+ string firstName = "mo";
+ string lastName = "khan";
+ string phoneNumber = "4036813389";
+ string city = "calgary";
+ RegisterCustomerDTO customerDTO =
+ new RegisterCustomerDTO( username, password, firstName, lastName, phoneNumber, city );
+
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.Registration( ) ).Return( registration );
+ SetupResult.For( registration.IsValid( ) ).Return( true );
+
+ Expect.Call( _mockCustomerRepository.NewCustomer( ) ).Return( customer );
+ customer.RegisterAccount( username, password, firstName, lastName, phoneNumber, city );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ ListFactory.From( CreateSUT( ).RegisterNew( customerDTO ) );
+ }
+ }
+
+ private RegisterCustomerDTO RegisterCustomerDTO() {
+ string username = "username";
+ string password = "password";
+ string firstName = "mo";
+ string lastName = "khan";
+ string phoneNumber = "4036813389";
+ string city = "calgary";
+ return new RegisterCustomerDTO( username, password, firstName, lastName, phoneNumber, city );
+ }
+
+ [Test]
+ public void Should_return_registration_messages() {
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+
+ IList< DisplayResponseLineDTO > brokenRulesDtos = new List< DisplayResponseLineDTO >( );
+ IList< IBrokenRule > brokenRules = new List< IBrokenRule >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockCustomerRepository.NewCustomer( ) ).Return( customer );
+ SetupResult.For( customer.Registration( ) ).Return( registration );
+
+ using ( _mockery.Ordered( ) ) {
+ Expect.Call( registration.IsValid( ) ).Return( false );
+ Expect.Call( registration.BrokenRules( ) ).Return( brokenRules );
+ Expect.Call( _mockMapper.MapFrom( brokenRules ) ).Return( brokenRulesDtos );
+ }
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( brokenRulesDtos, CreateSUT( ).RegisterNew( RegisterCustomerDTO( ) ) );
+ }
+ }
+
+ [Test]
+ public void Should_return_a_success_message_if_there_are_no_broken_rules() {
+ IRegistration registration = _mockery.CreateMock< IRegistration >( );
+
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockCustomerRepository.NewCustomer( ) ).Return( customer );
+ SetupResult.For( customer.Registration( ) ).Return( registration );
+ Expect
+ .Call( registration.IsValid( ) )
+ .Return( true );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ IRichList< DisplayResponseLineDTO > lineItems =
+ ListFactory.From( CreateSUT( ).RegisterNew( RegisterCustomerDTO( ) ) );
+ Assert.IsTrue( lineItems.Contains( new DisplayResponseLineDTO( "Success!" ) ) );
+ }
+ }
+
+ [Test]
+ public void Should_lookup_customer_from_repository_using_customer_id() {
+ int customerId = 1;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockCustomerRepository.FindBy( customerId ) ).Return( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).AddNewBoatUsing( new BoatRegistrationDTO( "reg#", "YAMAHA", "2007", "100", customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_register_boat_with_customer() {
+ int customerId = 1;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockCustomerRepository.FindBy( customerId ) ).Return( customer );
+ customer.RegisterBoat( "reg#", "YAMAHA", new DateTime( 2007, 01, 01 ), 100 );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).AddNewBoatUsing( new BoatRegistrationDTO( "reg#", "YAMAHA", "2007", "100", customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_save_the_changed_customer_to_the_repository() {
+ int customerId = 1;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ using ( _mockery.Record( ) ) {
+ using ( _mockery.Ordered( ) ) {
+ SetupResult.For( _mockCustomerRepository.FindBy( customerId ) ).Return( customer );
+ customer.RegisterBoat( "reg#", "YAMAHA", new DateTime( 2007, 01, 01 ), 100 );
+ _mockCustomerRepository.Save( customer );
+ }
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).AddNewBoatUsing( new BoatRegistrationDTO( "reg#", "YAMAHA", "2007", "100", customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_repository_to_find_customer() {
+ int customerId = 1;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( registration.FirstName( ) ).Return( "mo" );
+ SetupResult.For( registration.Username( ) ).Return( "mokhan" );
+ SetupResult.For( registration.LastName( ) ).Return( "khan" );
+ SetupResult.For( registration.PhoneNumber( ) ).Return( "4036813389" );
+ SetupResult.For( registration.City( ) ).Return( "calgary" );
+
+ SetupResult.For( customer.Registration( ) ).Return( registration );
+ Expect.Call( _mockCustomerRepository.FindBy( customerId ) ).Return( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual(
+ new CustomerRegistrationDisplayDTO( "1", "mokhan", "mo", "khan", "4036813389", "calgary" ),
+ CreateSUT( ).LoadRegistrationFor( customerId ) );
+ }
+ }
+
+ [Test]
+ public void Should_leverage_repository_to_update_the_customer_information() {
+ int customerId = 1;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.Registration( ) ).Return( registration );
+ SetupResult.For( registration.IsValid( ) ).Return( true );
+
+ using ( _mockery.Ordered( ) ) {
+ Expect.Call( _mockCustomerRepository.FindBy( customerId ) ).Return( customer );
+ customer.UpdateRegistrationTo( "mokhan", "password", "mo", "khan", "4036813389", "calgary" );
+ _mockCustomerRepository.Save( customer );
+ }
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).UpdateRegistrationFor(
+ new UpdateCustomerRegistrationDTO( 1, "mokhan", "password", "mo", "khan", "4036813389", "calgary" ) );
+ }
+ }
+
+ [Test]
+ public void Should_not_save_customer_if_registration_information_is_incorrect() {
+ int customerId = 1;
+ ICustomer customer = _mockery.DynamicMock< ICustomer >( );
+ IRegistration registration = _mockery.DynamicMock< IRegistration >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( customer.Registration( ) ).Return( registration );
+ SetupResult.For( registration.IsValid( ) ).Return( false );
+ SetupResult.For( _mockCustomerRepository.FindBy( customerId ) ).Return( customer );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).UpdateRegistrationFor(
+ new UpdateCustomerRegistrationDTO( 1, "mokhan", "password", "mo", "khan", "4036813389", "calgary" ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Web/Commands/AvailableSlipsCommandTest.cs b/slips/src/test/Marina.Test/Unit/Web/Commands/AvailableSlipsCommandTest.cs
new file mode 100644
index 0000000..c3ca810
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Web/Commands/AvailableSlipsCommandTest.cs
@@ -0,0 +1,56 @@
+using System.Collections.Generic;
+using Marina.Infrastructure;
+using Marina.Presentation.DTO;
+using Marina.Task;
+using Marina.Web.Commands;
+using Marina.Web.Views.Pages;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Web.Commands {
+ [TestFixture]
+ public class AvailableSlipsCommandTest {
+ private MockRepository _mockery;
+ private ICatalogTasks _mockTask;
+ private IAvailableSlipsWebView _mockView;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockTask = _mockery.DynamicMock< ICatalogTasks >( );
+ _mockView = _mockery.DynamicMock< IAvailableSlipsWebView >( );
+ }
+
+ private ICommand CreateSUT() {
+ return new AvailableSlipsCommand( _mockView, _mockTask );
+ }
+
+ [Test]
+ public void Should_leverage_task_to_retrieve_all_available_slips_on_initialize() {
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockTask.GetAllAvailableSlips( ) ).Return( null );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Execute( );
+ }
+ }
+
+ [Test]
+ public void Should_add_available_slips_to_bag_and_render_view() {
+ IEnumerable< SlipDisplayDTO > slips = new List< SlipDisplayDTO >( );
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( _mockTask.GetAllAvailableSlips( ) ).Return( slips );
+ using ( _mockery.Ordered( ) ) {
+ _mockView.AddToBag( slips );
+ _mockView.Render( );
+ }
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Execute( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerSpecificationTest.cs b/slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerSpecificationTest.cs
new file mode 100644
index 0000000..8b6c4fd
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerSpecificationTest.cs
@@ -0,0 +1,53 @@
+using Marina.Infrastructure;
+using Marina.Web.Handlers;
+using Marina.Web.Http;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Web.Handlers {
+ [TestFixture]
+ public class RequestHandlerSpecificationTest {
+ private MockRepository _mockery;
+
+ [SetUp]
+ public void Setup( ) {
+ _mockery = new MockRepository( );
+ }
+
+ [TearDown]
+ public void TearDown( ) {
+ _mockery.VerifyAll( );
+ }
+
+ [Test]
+ public void Should_return_true_if_destination_contains_command_name( ) {
+ IHttpGateway mockRequest = _mockery.DynamicMock< IHttpGateway >( );
+ string commandName = "test.marina";
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( mockRequest.Destination( ) ).Return( commandName );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ Assert.IsTrue( CreateSUT( commandName ).IsSatisfiedBy( mockRequest ) );
+ }
+ }
+
+ [Test]
+ public void Should_return_false_if_destination_does_not_contain_command_name( ) {
+ IHttpGateway mockRequest = _mockery.DynamicMock< IHttpGateway >( );
+ string firstCommandName = "test.marina";
+ string secondCommandName = "test2.marina";
+
+ using ( _mockery.Record( ) ) {
+ SetupResult.For( mockRequest.Destination( ) ).Return( secondCommandName );
+ }
+ using ( _mockery.Playback( ) ) {
+ Assert.IsFalse( CreateSUT( firstCommandName ).IsSatisfiedBy( mockRequest ) );
+ }
+ }
+
+ private ISpecification< IHttpGateway > CreateSUT( string commandName ) {
+ return new RequestHandlerSpecification( commandName );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerTest.cs b/slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerTest.cs
new file mode 100644
index 0000000..b4a15ef
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Web/Handlers/RequestHandlerTest.cs
@@ -0,0 +1,49 @@
+using Marina.Infrastructure;
+using Marina.Web.Handlers;
+using Marina.Web.Http;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Web.Handlers {
+ [TestFixture]
+ public class RequestHandlerTest {
+ private MockRepository _mockery;
+ private ISpecification< IHttpGateway > _mockSpecification;
+ private ICommand _mockCommand;
+
+ [SetUp]
+ public void Setup( ) {
+ _mockery = new MockRepository( );
+ _mockSpecification = _mockery.DynamicMock< ISpecification< IHttpGateway > >( );
+ _mockCommand = _mockery.DynamicMock< ICommand >( );
+ }
+
+ [Test]
+ public void Should_delegate_to_specification_to_see_if_criteria_is_satisfied( ) {
+ IHttpGateway request = _mockery.DynamicMock< IHttpGateway >( );
+
+ using ( _mockery.Record( ) ) {
+ Expect.Call( _mockSpecification.IsSatisfiedBy( request ) ).Return( true );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).IsSatisfiedBy( request );
+ }
+ }
+
+ [Test]
+ public void Should_delegate_to_command_when_told_to_execute( ) {
+ using ( _mockery.Record( ) ) {
+ _mockCommand.Execute( );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Execute( );
+ }
+ }
+
+ private IRequestHandler CreateSUT( ) {
+ return new RequestHandler( _mockSpecification, _mockCommand );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Web/Views/Pages/AvailableSlipsWebViewTest.cs b/slips/src/test/Marina.Test/Unit/Web/Views/Pages/AvailableSlipsWebViewTest.cs
new file mode 100644
index 0000000..2a40745
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Web/Views/Pages/AvailableSlipsWebViewTest.cs
@@ -0,0 +1,49 @@
+using System.Collections.Generic;
+using Marina.Presentation.DTO;
+using Marina.Web.Http;
+using Marina.Web.Views;
+using Marina.Web.Views.Pages;
+using MbUnit.Framework;
+using Rhino.Mocks;
+
+namespace Marina.Test.Unit.Web.Views.Pages {
+ [TestFixture]
+ public class AvailableSlipsWebViewTest {
+ private MockRepository _mockery;
+ private IViewLuggageTransporter< IEnumerable< SlipDisplayDTO > > _mockViewBag;
+ private IHttpGateway _mockGateway;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockViewBag = _mockery.DynamicMock< IViewLuggageTransporter< IEnumerable< SlipDisplayDTO > > >( );
+ _mockGateway = _mockery.DynamicMock< IHttpGateway >( );
+ }
+
+ public IAvailableSlipsWebView CreateSUT() {
+ return new AvailableSlipsWebView( _mockViewBag, _mockGateway );
+ }
+
+ [Test]
+ public void Should_add_item_to_view_bag() {
+ IEnumerable< SlipDisplayDTO > slips = new List< SlipDisplayDTO >( );
+
+ using ( _mockery.Record( ) ) {
+ _mockViewBag.Add( slips );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).AddToBag( slips );
+ }
+ }
+
+ [Test]
+ public void Should_return_the_name_of_the_page() {
+ using ( _mockery.Record( ) ) {}
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( "AvailableSlips.aspx", CreateSUT( ).Name( ) );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Unit/Web/Views/ViewTest.cs b/slips/src/test/Marina.Test/Unit/Web/Views/ViewTest.cs
new file mode 100644
index 0000000..a3b2d08
--- /dev/null
+++ b/slips/src/test/Marina.Test/Unit/Web/Views/ViewTest.cs
@@ -0,0 +1,48 @@
+using Marina.Web.Http;
+using Marina.Web.Views;
+using MbUnit.Framework;
+using Rhino.Mocks;
+using Rhino.Mocks.Constraints;
+
+namespace Marina.Test.Unit.Web.Views {
+ [TestFixture]
+ public class ViewTest {
+ private MockRepository _mockery;
+ private string _pageName;
+ private IHttpGateway _mockGateway;
+
+ [SetUp]
+ public void Setup() {
+ _mockery = new MockRepository( );
+ _mockGateway = _mockery.DynamicMock< IHttpGateway >( );
+ _pageName = string.Empty;
+ }
+
+ public IView CreateSUT() {
+ return new View( _pageName, _mockGateway );
+ }
+
+ [Test]
+ public void Should_return_the_name_of_the_page_it_was_created_with() {
+ _pageName = "TestPage.aspx";
+
+ using ( _mockery.Record( ) ) {}
+
+ using ( _mockery.Playback( ) ) {
+ Assert.AreEqual( _pageName, CreateSUT( ).Name( ) );
+ }
+ }
+
+ [Test]
+ public void Should_redirect_to_page() {
+ using ( _mockery.Record( ) ) {
+ _mockGateway.RedirectTo( null );
+ LastCall.Constraints( Is.NotNull( ) );
+ }
+
+ using ( _mockery.Playback( ) ) {
+ CreateSUT( ).Render( );
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Utility/ObjectMother.cs b/slips/src/test/Marina.Test/Utility/ObjectMother.cs
new file mode 100644
index 0000000..d98bfd7
--- /dev/null
+++ b/slips/src/test/Marina.Test/Utility/ObjectMother.cs
@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using Marina.Domain;
+using Marina.Domain.Interfaces;
+using Marina.Presentation.DTO;
+
+namespace Marina.Test.Utility {
+ public class ObjectMother {
+ public static RegisterCustomerDTO CustomerRegistrationDTO() {
+ return
+ new RegisterCustomerDTO( string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty );
+ }
+
+ public static IEnumerable< DisplayResponseLineDTO > EnumerableDisplayResponseLineDTO() {
+ return new List< DisplayResponseLineDTO >( );
+ }
+
+ public static DockDisplayDTO DockDisplayDTO() {
+ return new DockDisplayDTO( string.Empty, string.Empty, string.Empty, string.Empty );
+ }
+
+ public static CustomerRegistrationDisplayDTO DisplayCustomerRegistrationDTO() {
+ return
+ new CustomerRegistrationDisplayDTO( string.Empty, string.Empty, string.Empty, string.Empty,
+ string.Empty, string.Empty );
+ }
+
+ public static UpdateCustomerRegistrationDTO UpdateCustomerRegistrationDTO() {
+ return new UpdateCustomerRegistrationDTO( 0, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
+ string.Empty );
+ }
+
+ public static BoatRegistrationDTO BoatRegistrationDTO() {
+ return new BoatRegistrationDTO( string.Empty, string.Empty, string.Empty, string.Empty, 0 );
+ }
+
+ public static LoginCredentialsDTO LoginCredentialsDTO() {
+ return new LoginCredentialsDTO( string.Empty, string.Empty );
+ }
+
+ public static SlipDisplayDTO SlipDisplayDTO() {
+ return new SlipDisplayDTO( "1", "dock a", "100", "100", "location a", "2" );
+ }
+
+ public static ILocation Location() {
+ return new Location( "location a" );
+ }
+
+ public static IBoat Boat() {
+ return new Boat( -1, string.Empty, string.Empty, DateTime.Now, 100 );
+ }
+
+ public static ISlip Slip() {
+ return new Slip( -1, null, 100, 100, false );
+ }
+
+ public static ICustomer Customer() {
+ return new Customer( );
+ }
+
+ public static IDock Dock() {
+ return new Dock( -1, "dock a", null, null );
+ }
+
+ public static DisplayResponseLineDTO DisplayResponseLineDTO() {
+ return new DisplayResponseLineDTO( string.Empty );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Utility/RunInRealContainerAttribute.cs b/slips/src/test/Marina.Test/Utility/RunInRealContainerAttribute.cs
new file mode 100644
index 0000000..d161100
--- /dev/null
+++ b/slips/src/test/Marina.Test/Utility/RunInRealContainerAttribute.cs
@@ -0,0 +1,14 @@
+using System;
+using MbUnit.Core.Framework;
+using MbUnit.Core.Invokers;
+
+namespace Marina.Test.Utility
+{
+ public class RunInRealContainerAttribute : DecoratorPatternAttribute
+ {
+ public override IRunInvoker GetInvoker( IRunInvoker wrapper )
+ {
+ return new RunInRealContainerRunInvoker( wrapper );
+ }
+ }
+} \ No newline at end of file
diff --git a/slips/src/test/Marina.Test/Utility/RunInRealContainerRunInvoker.cs b/slips/src/test/Marina.Test/Utility/RunInRealContainerRunInvoker.cs
new file mode 100644
index 0000000..cea4049
--- /dev/null
+++ b/slips/src/test/Marina.Test/Utility/RunInRealContainerRunInvoker.cs
@@ -0,0 +1,18 @@
+using System.Collections;
+using Marina.Infrastructure.Container;
+using Marina.Task;
+using MbUnit.Core.Invokers;
+
+namespace Marina.Test.Utility {
+ public class RunInRealContainerRunInvoker : DecoratorRunInvoker {
+ public RunInRealContainerRunInvoker( IRunInvoker invoker )
+ : base( invoker ) {}
+
+ public override object Execute( object o, IList args ) {
+ ApplicationStartupTask.ApplicationBegin( );
+ object result = base.Invoker.Execute( o, args );
+ Resolve.InitializeWith( null );
+ return result;
+ }
+ }
+} \ No newline at end of file