summaryrefslogtreecommitdiff
path: root/slips/src/test/Marina.Test/Integration/DataAccess
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/Integration/DataAccess
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/Integration/DataAccess')
-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
10 files changed, 365 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