summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64>2008-01-06 22:49:41 +0000
committermo.khan <mo.khan@a0a4a051-f042-0410-9e78-9fae330bdb64>2008-01-06 22:49:41 +0000
commit8dfa917860144317a58f8c4f44c1e75fcaa3e07b (patch)
treecf80b93029d6bd860a39e71a9d6b9e4240665ff9
parent4be9b7516d14867f5e70100c5a93714617724659 (diff)
updated leasetask to save customer back to repository when the customer leases a new slip.
git-svn-id: http://mokhan.googlecode.com/svn/trunk@12 a0a4a051-f042-0410-9e78-9fae330bdb64
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx25
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx.cs4
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/windsor.config.xml12
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Domain/Customer.cs12
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/AuthenticationTask.cs10
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/CatalogTasks.cs18
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/LeaseTasks.cs1
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/RegistrationTasks.cs24
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Domain/CustomerTest.cs2
-rw-r--r--Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs19
10 files changed, 85 insertions, 42 deletions
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx
index fc2fd00..8dd0ba6 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx
@@ -5,18 +5,6 @@
<h1>Would you like to lease slip: <%= Slip.SlipId %></h1>
- Select Lease Duration:
- <select name="uxLeaseDuration">
- <option value="Daily">Daily</option>
- <option value="Weekly">Weekly</option>
- <option value="Monthly">Monthly</option>
- <option value="Yearly">Yearly</option>
- </select>
-
- <asp:Button ID="uxSubmitButton" runat="server" />
- <p>
- <%= ResponseMessage %>
- </p>
<table>
<thead>
<tr>
@@ -36,5 +24,18 @@
</tbody>
</table>
+ Select Lease Duration:
+ <select name="uxLeaseDuration">
+ <option value="Daily">Daily</option>
+ <option value="Weekly">Weekly</option>
+ <option value="Monthly">Monthly</option>
+ <option value="Yearly">Yearly</option>
+ </select>
+
+ <asp:Button ID="uxSubmitButton" runat="server" Text="Lease Now!" />
+ <p>
+ <%= ResponseMessage %>
+ </p>
+
</asp:Content>
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx.cs b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx.cs
index 1a63c35..c5ead9b 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/LeaseSlip.aspx.cs
@@ -7,7 +7,9 @@ using Marina.Presentation.Views;
namespace Marina.Web.UI {
public partial class LeaseSlip : Page, ILeaseSlipView {
protected void Page_Load( object sender, EventArgs e ) {
- new LeaseSlipPresenter( this ).Initialize( );
+ ILeaseSlipPresenter presenter = new LeaseSlipPresenter( this );
+ presenter.Initialize( );
+ uxSubmitButton.Click += delegate { presenter.SubmitLeaseRequest( ); };
}
public SlipDisplayDTO Slip;
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/windsor.config.xml b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/windsor.config.xml
index 2878868..906f419 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/windsor.config.xml
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina.Web.UI/windsor.config.xml
@@ -100,5 +100,17 @@
<component id="IHttpRequest"
service="Marina.Web.IHttpRequest, Marina"
type="Marina.Web.CurrentHttpRequest, Marina" />
+
+ <component id="ILeaseTasks"
+ service="Marina.Task.ILeaseTasks, Marina"
+ type="Marina.Task.LeaseTasks, Marina" />
+
+ <component id="ILeaseToDtoMapper"
+ service="Marina.Task.Mappers.ILeaseToDtoMapper, Marina"
+ type="Marina.Task.Mappers.LeaseToDtoMapper, Marina" />
+
+ <component id="ILeaseRequestDtoFromHttpRequestMapper"
+ service="Marina.Presentation.Mappers.ILeaseRequestDtoFromHttpRequestMapper, Marina"
+ type="Marina.Presentation.Mappers.LeaseRequestDtoFromHttpRequestMapper, Marina" />
</components>
</configuration>
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Domain/Customer.cs b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Domain/Customer.cs
index 31d5a32..8b9911c 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Domain/Customer.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Domain/Customer.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using Marina.Domain.Exceptions;
using Marina.Domain.Interfaces;
using Marina.Infrastructure;
@@ -49,15 +50,20 @@ namespace Marina.Domain {
}
public void Lease( ISlip slip, ILeaseDuration duration ) {
- if ( !slip.IsLeased( ) ) {
- _leases.Add( slip.LeaseTo( this, duration ) );
- }
+ EnsureSlipIsNotLeased( slip );
+ _leases.Add( slip.LeaseTo( this, duration ) );
}
public IEnumerable< ISlipLease > Leases() {
return _leases.All( );
}
+ private void EnsureSlipIsNotLeased( ISlip slip ) {
+ if ( slip.IsLeased( ) ) {
+ throw new SlipIsAlreadyLeasedException( );
+ }
+ }
+
private bool IsBoatRegistered( IBoat boat ) {
return _registeredBoats.Contains( boat );
}
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/AuthenticationTask.cs b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/AuthenticationTask.cs
index 1b99966..75424a9 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/AuthenticationTask.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/AuthenticationTask.cs
@@ -5,14 +5,14 @@ using Marina.Web.Http;
namespace Marina.Task {
public class AuthenticationTask : IAuthenticationTask {
- public AuthenticationTask( ICustomerRepository repository, IHttpGateway gateway ) {
- _repository = repository;
+ public AuthenticationTask( ICustomerRepository customers, IHttpGateway gateway ) {
+ _customers = customers;
_gateway = gateway;
}
public DisplayResponseLineDTO AuthenticateUserUsing( LoginCredentialsDTO credentials ) {
- if ( CheckIfPasswordMatches( credentials, _repository.FindBy( credentials.Username ) ) ) {
- _gateway.AddAuthenticationCookieFor( credentials.Username, _repository.FindBy( credentials.Username ).ID( ) );
+ if ( CheckIfPasswordMatches( credentials, _customers.FindBy( credentials.Username ) ) ) {
+ _gateway.AddAuthenticationCookieFor( credentials.Username, _customers.FindBy( credentials.Username ).ID( ) );
return ValidCredentialsMessage( credentials.Username );
}
else {
@@ -35,7 +35,7 @@ namespace Marina.Task {
return false;
}
- private readonly ICustomerRepository _repository;
+ private readonly ICustomerRepository _customers;
private readonly IHttpGateway _gateway;
}
} \ No newline at end of file
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/CatalogTasks.cs b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/CatalogTasks.cs
index cf2e80a..e3c18a2 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/CatalogTasks.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/CatalogTasks.cs
@@ -17,36 +17,36 @@ namespace Marina.Task {
public CatalogTasks( ISlipsRepository slipRepository, ISlipsToDisplayDTOMapper slipMapper,
IDockRepository dockRepository, IDockToDisplayDTOMapper dockMapper ) {
- _slipsRepository = slipRepository;
+ _slips = slipRepository;
_slipMapper = slipMapper;
- _dockRepository = dockRepository;
+ _docks = dockRepository;
_dockMapper = dockMapper;
}
public IEnumerable< SlipDisplayDTO > GetAvailableSlipsForDockBy( long dockId ) {
- IDock dock = _dockRepository.FindBy( dockId );
- foreach ( ISlip slip in _slipsRepository.AllAvailableSlipsFor( dock ) ) {
+ IDock dock = _docks.FindBy( dockId );
+ foreach ( ISlip slip in _slips.AllAvailableSlipsFor( dock ) ) {
yield return _slipMapper.MapFrom( slip );
}
}
public DockDisplayDTO GetDockInformationBy( long dockId ) {
- return _dockMapper.MapFrom( _dockRepository.FindBy( dockId ) );
+ return _dockMapper.MapFrom( _docks.FindBy( dockId ) );
}
public IEnumerable< SlipDisplayDTO > GetAllAvailableSlips() {
- foreach ( ISlip availableSlip in _slipsRepository.AllAvailableSlips( ) ) {
+ foreach ( ISlip availableSlip in _slips.AllAvailableSlips( ) ) {
yield return _slipMapper.MapFrom( availableSlip );
}
}
public SlipDisplayDTO FindSlipBy( long slipId ) {
- return _slipMapper.MapFrom( _slipsRepository.FindBy( slipId ) );
+ return _slipMapper.MapFrom( _slips.FindBy( slipId ) );
}
- private readonly ISlipsRepository _slipsRepository;
+ private readonly ISlipsRepository _slips;
private readonly ISlipsToDisplayDTOMapper _slipMapper;
- private readonly IDockRepository _dockRepository;
+ private readonly IDockRepository _docks;
private readonly IDockToDisplayDTOMapper _dockMapper;
}
} \ No newline at end of file
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/LeaseTasks.cs b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/LeaseTasks.cs
index 3d3deef..1dfb592 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/LeaseTasks.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/LeaseTasks.cs
@@ -24,6 +24,7 @@ namespace Marina.Task {
ICustomer customer = _customers.FindBy( request.CustomerId );
try {
customer.Lease( _slips.FindBy( request.SlipId ), LeaseDurations.FindBy( request.Duration ) );
+ _customers.Save( customer );
return new DisplayResponseLineDTO( "Success!" );
}
catch ( SlipIsAlreadyLeasedException ) {
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/RegistrationTasks.cs b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/RegistrationTasks.cs
index 2c5fbdc..ea9f34a 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/RegistrationTasks.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/app/Marina/Task/RegistrationTasks.cs
@@ -15,14 +15,14 @@ namespace Marina.Task {
Resolve.DependencyFor< ICustomerRepository >( )
) {}
- public RegistrationTasks( IBrokenRulesToDisplayItemMapper mapper, ICustomerRepository customerRepository ) {
+ public RegistrationTasks( IBrokenRulesToDisplayItemMapper mapper, ICustomerRepository customers ) {
_mapper = mapper;
- _customerRepository = customerRepository;
+ _customers = customers;
}
public IEnumerable< DisplayResponseLineDTO > RegisterNew( RegisterCustomerDTO customer ) {
- if ( null == _customerRepository.FindBy( customer.UserName ) ) {
- ICustomer newCustomer = _customerRepository.NewCustomer( );
+ if ( null == _customers.FindBy( customer.UserName ) ) {
+ ICustomer newCustomer = _customers.NewCustomer( );
newCustomer.RegisterAccount( customer.UserName,
customer.Password,
customer.FirstName,
@@ -33,7 +33,7 @@ namespace Marina.Task {
return _mapper.MapFrom( newCustomer.Registration( ).BrokenRules( ) );
}
else {
- _customerRepository.Save( newCustomer );
+ _customers.Save( newCustomer );
return new DisplayResponseLines( "Success!" );
}
}
@@ -45,17 +45,17 @@ namespace Marina.Task {
}
public IEnumerable< DisplayResponseLineDTO > AddNewBoatUsing( BoatRegistrationDTO boat ) {
- ICustomer customer = _customerRepository.FindBy( boat.CustomerId );
+ ICustomer customer = _customers.FindBy( boat.CustomerId );
customer.RegisterBoat( boat.RegistrationNumber,
boat.Manufacturer,
new DateTime( Convert.ToInt32( boat.ModelYear ), 1, 1 ),
Convert.ToInt64( boat.Length ) );
- _customerRepository.Save( customer );
+ _customers.Save( customer );
return new DisplayResponseLines( "Success!" );
}
public CustomerRegistrationDisplayDTO LoadRegistrationFor( long customerId ) {
- IRegistration registration = _customerRepository.FindBy( customerId ).Registration( );
+ IRegistration registration = _customers.FindBy( customerId ).Registration( );
return
new CustomerRegistrationDisplayDTO( customerId.ToString( ),
registration.Username( ),
@@ -67,18 +67,18 @@ namespace Marina.Task {
}
public IEnumerable< DisplayResponseLineDTO > UpdateRegistrationFor( UpdateCustomerRegistrationDTO registration ) {
- ICustomer customer = _customerRepository.FindBy( registration.CustomerId );
+ ICustomer customer = _customers.FindBy( registration.CustomerId );
customer.UpdateRegistrationTo( registration.Username, registration.Password, registration.FirstName,
registration.LastName, registration.PhoneNumber, registration.City );
if ( customer.Registration( ).IsValid( ) ) {
- _customerRepository.Save( customer );
+ _customers.Save( customer );
}
return _mapper.MapFrom( customer.Registration( ).BrokenRules( ) );
}
public IEnumerable< BoatRegistrationDTO > AllBoatsFor( long customerId ) {
- ICustomer customer = _customerRepository.FindBy( customerId );
+ ICustomer customer = _customers.FindBy( customerId );
foreach ( IBoat boat in customer.RegisteredBoats( ) ) {
yield return
@@ -88,6 +88,6 @@ namespace Marina.Task {
}
private readonly IBrokenRulesToDisplayItemMapper _mapper;
- private readonly ICustomerRepository _customerRepository;
+ private readonly ICustomerRepository _customers;
}
} \ No newline at end of file
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Domain/CustomerTest.cs b/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Domain/CustomerTest.cs
index d08711c..604b049 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Domain/CustomerTest.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Domain/CustomerTest.cs
@@ -1,5 +1,6 @@
using System;
using Marina.Domain;
+using Marina.Domain.Exceptions;
using Marina.Domain.Interfaces;
using Marina.Infrastructure;
using Marina.Test.Utility;
@@ -51,6 +52,7 @@ namespace Marina.Test.Unit.Domain {
}
[Test]
+ [ExpectedException( typeof( SlipIsAlreadyLeasedException ) )]
public void Should_not_be_able_to_lease_a_slip_that_is_already_leased() {
ISlip slip = _mockery.DynamicMock< ISlip >( );
diff --git a/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs b/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs
index a2991a2..e645640 100644
--- a/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs
+++ b/Sait/Cmpp299/Assignment1/trunk/src/test/Marina.Test/Unit/Task/LeaseTasksTest.cs
@@ -158,5 +158,24 @@ namespace Marina.Test.Unit.Task {
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