diff options
Diffstat (limited to 'slips/src/test/Marina.Test/Integration/DataAccess/Mappers')
4 files changed, 217 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 |
