diff options
| author | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
|---|---|---|
| committer | mokhan <mokhan@da190166-9cfc-4ee1-ae03-434a172be219> | 2009-02-21 21:44:27 +0000 |
| commit | 1dfdccb8118aeaa3cd844ac8de2a672c93312166 (patch) | |
| tree | 4b19e7f816ab1019f180a46b68572af4b66fe4bc /slips/src/app/Marina/Domain | |
| parent | 42d66bcab8262c7b8b2452615df535e694a3ec1c (diff) | |
git-svn-id: http://svn.xp-dev.com/svn/mokhan-sait@2 da190166-9cfc-4ee1-ae03-434a172be219
Diffstat (limited to 'slips/src/app/Marina/Domain')
33 files changed, 916 insertions, 0 deletions
diff --git a/slips/src/app/Marina/Domain/Boat.cs b/slips/src/app/Marina/Domain/Boat.cs new file mode 100644 index 0000000..3f07174 --- /dev/null +++ b/slips/src/app/Marina/Domain/Boat.cs @@ -0,0 +1,72 @@ +using System;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class Boat : DomainObject, IBoat, IEquatable< Boat > {
+ public Boat( string registrationNumber, string manufacturer, DateTime yearOfModel, long length )
+ : this( -1, registrationNumber, manufacturer, yearOfModel, length ) {}
+
+ public Boat( long id, string registrationNumber, string manufacturer, DateTime yearOfModel, long length )
+ : base( id ) {
+ _registrationNumber = registrationNumber;
+ _manufacturer = manufacturer;
+ _yearOfModel = yearOfModel;
+ _length = length;
+ }
+
+ public string RegistrationNumber() {
+ return _registrationNumber;
+ }
+
+ public string Manufacturer() {
+ return _manufacturer;
+ }
+
+ public DateTime YearOfModel() {
+ return _yearOfModel;
+ }
+
+ public long LengthInFeet() {
+ return _length;
+ }
+
+ public bool Equals( Boat boat ) {
+ if ( boat == null ) {
+ return false;
+ }
+ if ( !Equals( _registrationNumber, boat._registrationNumber ) ) {
+ return false;
+ }
+ if ( !Equals( _manufacturer, boat._manufacturer ) ) {
+ return false;
+ }
+ if ( !Equals( _yearOfModel, boat._yearOfModel ) ) {
+ return false;
+ }
+ if ( _length != boat._length ) {
+ return false;
+ }
+ return true;
+ }
+
+ public override bool Equals( object obj ) {
+ if ( ReferenceEquals( this, obj ) ) {
+ return true;
+ }
+ return Equals( obj as Boat );
+ }
+
+ public override int GetHashCode() {
+ int result = _registrationNumber != null ? _registrationNumber.GetHashCode( ) : 0;
+ result = 29*result + ( _manufacturer != null ? _manufacturer.GetHashCode( ) : 0 );
+ result = 29*result + _yearOfModel.GetHashCode( );
+ result = 29*result + ( int )_length;
+ return result;
+ }
+
+ private readonly string _registrationNumber;
+ private readonly string _manufacturer;
+ private readonly DateTime _yearOfModel;
+ private readonly long _length;
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/BrokenRule.cs b/slips/src/app/Marina/Domain/BrokenRule.cs new file mode 100644 index 0000000..1d7d56b --- /dev/null +++ b/slips/src/app/Marina/Domain/BrokenRule.cs @@ -0,0 +1,15 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ internal class BrokenRule : IBrokenRule {
+ public BrokenRule( string message ) {
+ _message = message;
+ }
+
+ public string Message() {
+ return _message;
+ }
+
+ private readonly string _message;
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Customer.cs b/slips/src/app/Marina/Domain/Customer.cs new file mode 100644 index 0000000..8b9911c --- /dev/null +++ b/slips/src/app/Marina/Domain/Customer.cs @@ -0,0 +1,76 @@ +using System;
+using System.Collections.Generic;
+using Marina.Domain.Exceptions;
+using Marina.Domain.Interfaces;
+using Marina.Infrastructure;
+
+namespace Marina.Domain {
+ public class Customer : DomainObject, ICustomer {
+ public Customer()
+ : this( -1, new RichList< IBoat >( ), new RichList< ISlipLease >( ), CustomerRegistration.BlankRegistration( ) ) {}
+
+ public Customer( long id, IEnumerable< IBoat > registeredBoats, IEnumerable< ISlipLease > leases,
+ IRegistration registration ) : base( id ) {
+ _registeredBoats = ListFactory.From( registeredBoats );
+ _leases = ListFactory.From( leases );
+ _registration = registration;
+ }
+
+ public IRegistration Registration() {
+ return _registration;
+ }
+
+ public void RegisterAccount( string username, string password, string firstName, string lastName, string phoneNumber,
+ string city ) {
+ _registration = new CustomerRegistration( username, password, firstName, lastName, phoneNumber, city );
+ }
+
+ public void UpdateRegistrationTo( string username, string password, string firstName, string lastName,
+ string phoneNumber,
+ string city ) {
+ UpdateRegistrationTo( new CustomerRegistration( username, password, firstName, lastName, phoneNumber, city ) );
+ }
+
+ public void UpdateRegistrationTo( IRegistration registration ) {
+ _registration = registration ?? _registration;
+ }
+
+ public void RegisterBoat( string registrationNumber, string manufacturer, DateTime yearOfModel, long length ) {
+ RegisterBoat( new Boat( registrationNumber, manufacturer, yearOfModel, length ) );
+ }
+
+ public void RegisterBoat( IBoat unregisteredBoat ) {
+ if ( !IsBoatRegistered( unregisteredBoat ) ) {
+ _registeredBoats.Add( unregisteredBoat );
+ }
+ }
+
+ public IEnumerable< IBoat > RegisteredBoats() {
+ return _registeredBoats.All( );
+ }
+
+ public void Lease( ISlip slip, ILeaseDuration 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 );
+ }
+
+ private readonly IRichList< IBoat > _registeredBoats;
+ private readonly IRichList< ISlipLease > _leases;
+ private IRegistration _registration;
+ public static readonly ICustomer Unknown = new UnknownCustomer( );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/CustomerRegistration.cs b/slips/src/app/Marina/Domain/CustomerRegistration.cs new file mode 100644 index 0000000..9e7b13b --- /dev/null +++ b/slips/src/app/Marina/Domain/CustomerRegistration.cs @@ -0,0 +1,151 @@ +using System;
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class CustomerRegistration : IRegistration, IEquatable< CustomerRegistration > {
+ private CustomerRegistration()
+ : this( string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty ) {}
+
+ public CustomerRegistration( string userName, string password, string firstName, string lastName, string phoneNumber,
+ string city ) {
+ _userName = userName;
+ _password = password;
+ _firstName = firstName;
+ _lastName = lastName;
+ _phoneNumber = phoneNumber;
+ _city = city;
+ }
+
+ public string Username() {
+ return _userName;
+ }
+
+ public string Password() {
+ return _password;
+ }
+
+ public string FirstName() {
+ return _firstName;
+ }
+
+ public string LastName() {
+ return _lastName;
+ }
+
+ public string PhoneNumber() {
+ return _phoneNumber;
+ }
+
+ public string City() {
+ return _city;
+ }
+
+ public bool IsValid() {
+ foreach ( IBusinessRule businessRule in AllRules( ) ) {
+ if ( !businessRule.IsBroken( ) ) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public IEnumerable< IBrokenRule > BrokenRules() {
+ foreach ( IBusinessRule businessRule in AllRules( ) ) {
+ if ( !businessRule.IsBroken( ) ) {
+ yield return businessRule.Description( );
+ }
+ }
+ }
+
+ private IEnumerable< IBusinessRule > AllRules() {
+ yield return new PasswordRule( _password );
+ yield return new UserNameRule( _userName );
+ }
+
+ public bool Equals( CustomerRegistration customerRegistration ) {
+ if ( customerRegistration == null ) {
+ return false;
+ }
+ if ( !Equals( _userName, customerRegistration._userName ) ) {
+ return false;
+ }
+ if ( !Equals( _password, customerRegistration._password ) ) {
+ return false;
+ }
+ if ( !Equals( _firstName, customerRegistration._firstName ) ) {
+ return false;
+ }
+ if ( !Equals( _lastName, customerRegistration._lastName ) ) {
+ return false;
+ }
+ if ( !Equals( _phoneNumber, customerRegistration._phoneNumber ) ) {
+ return false;
+ }
+ if ( !Equals( _city, customerRegistration._city ) ) {
+ return false;
+ }
+ return true;
+ }
+
+ public override bool Equals( object obj ) {
+ if ( ReferenceEquals( this, obj ) ) {
+ return true;
+ }
+ return Equals( obj as CustomerRegistration );
+ }
+
+ public override int GetHashCode() {
+ int result = _userName != null ? _userName.GetHashCode( ) : 0;
+ result = 29*result + ( _password != null ? _password.GetHashCode( ) : 0 );
+ result = 29*result + ( _firstName != null ? _firstName.GetHashCode( ) : 0 );
+ result = 29*result + ( _lastName != null ? _lastName.GetHashCode( ) : 0 );
+ result = 29*result + ( _phoneNumber != null ? _phoneNumber.GetHashCode( ) : 0 );
+ result = 29*result + ( _city != null ? _city.GetHashCode( ) : 0 );
+ return result;
+ }
+
+ private readonly string _userName;
+ private readonly string _password;
+ private readonly string _firstName;
+ private readonly string _lastName;
+ private readonly string _phoneNumber;
+ private readonly string _city;
+
+ private class PasswordRule : IBusinessRule {
+ private readonly string _password;
+
+ public PasswordRule( string password ) {
+ _password = password;
+ }
+
+ public bool IsBroken() {
+ return !string.IsNullOrEmpty( _password );
+ }
+
+ public IBrokenRule Description() {
+ return new BrokenRule( "Password cannot be blank" );
+ }
+ }
+
+ private class UserNameRule : IBusinessRule {
+ private readonly string _userName;
+
+ public UserNameRule( string userName ) {
+ _userName = userName;
+ }
+
+ public bool IsBroken() {
+ return !string.IsNullOrEmpty( _userName );
+ }
+
+ public IBrokenRule Description() {
+ return new BrokenRule( "Username cannot be blank" );
+ }
+ }
+
+ public static IRegistration BlankRegistration() {
+ return new CustomerRegistration( );
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/DateRange.cs b/slips/src/app/Marina/Domain/DateRange.cs new file mode 100644 index 0000000..7460489 --- /dev/null +++ b/slips/src/app/Marina/Domain/DateRange.cs @@ -0,0 +1,22 @@ +using System;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ internal class DateRange : IDateRange {
+ public DateRange( DateTime startDate, DateTime endDate ) {
+ _startDate = startDate;
+ _endDate = endDate;
+ }
+
+ public DateTime Start() {
+ return _startDate;
+ }
+
+ public DateTime End() {
+ return _endDate;
+ }
+
+ private readonly DateTime _startDate;
+ private readonly DateTime _endDate;
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Dock.cs b/slips/src/app/Marina/Domain/Dock.cs new file mode 100644 index 0000000..6900cec --- /dev/null +++ b/slips/src/app/Marina/Domain/Dock.cs @@ -0,0 +1,33 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class Dock : IDock {
+ private readonly long _id;
+ private readonly string _name;
+ private readonly ILocation _location;
+ private readonly IUtility _utility;
+
+ public Dock( long id, string name, ILocation location, IUtility utility ) {
+ _id = id;
+ _name = name;
+ _location = location;
+ _utility = utility;
+ }
+
+ public long ID() {
+ return _id;
+ }
+
+ public string Name() {
+ return _name;
+ }
+
+ public ILocation Location() {
+ return _location;
+ }
+
+ public bool IsUtilityEnabled( IUtility utility ) {
+ return _utility.IsEnabled( utility );
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/DomainObject.cs b/slips/src/app/Marina/Domain/DomainObject.cs new file mode 100644 index 0000000..2fefda9 --- /dev/null +++ b/slips/src/app/Marina/Domain/DomainObject.cs @@ -0,0 +1,19 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class DomainObject : IDomainObject {
+ private long _id;
+
+ public DomainObject( long id ) {
+ _id = id;
+ }
+
+ public long ID() {
+ return _id;
+ }
+
+ void IDomainObject.ChangeIdTo( long id ) {
+ _id = id;
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Exceptions/SlipIsAlreadyLeasedException.cs b/slips/src/app/Marina/Domain/Exceptions/SlipIsAlreadyLeasedException.cs new file mode 100644 index 0000000..be492b7 --- /dev/null +++ b/slips/src/app/Marina/Domain/Exceptions/SlipIsAlreadyLeasedException.cs @@ -0,0 +1,5 @@ +using System;
+
+namespace Marina.Domain.Exceptions {
+ public class SlipIsAlreadyLeasedException : Exception {}
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IBoat.cs b/slips/src/app/Marina/Domain/Interfaces/IBoat.cs new file mode 100644 index 0000000..1baf363 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IBoat.cs @@ -0,0 +1,13 @@ +using System;
+
+namespace Marina.Domain.Interfaces {
+ public interface IBoat : IDomainObject {
+ string RegistrationNumber();
+
+ string Manufacturer();
+
+ DateTime YearOfModel();
+
+ long LengthInFeet();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IBrokenRule.cs b/slips/src/app/Marina/Domain/Interfaces/IBrokenRule.cs new file mode 100644 index 0000000..190dc0b --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IBrokenRule.cs @@ -0,0 +1,5 @@ +namespace Marina.Domain.Interfaces {
+ public interface IBrokenRule {
+ string Message();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IBusinessRule.cs b/slips/src/app/Marina/Domain/Interfaces/IBusinessRule.cs new file mode 100644 index 0000000..c0d3a79 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IBusinessRule.cs @@ -0,0 +1,9 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain.Interfaces {
+ internal interface IBusinessRule {
+ bool IsBroken();
+
+ IBrokenRule Description();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/ICustomer.cs b/slips/src/app/Marina/Domain/Interfaces/ICustomer.cs new file mode 100644 index 0000000..677194c --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/ICustomer.cs @@ -0,0 +1,27 @@ +using System;
+using System.Collections.Generic;
+
+namespace Marina.Domain.Interfaces {
+ public interface ICustomer : IDomainObject {
+ void RegisterBoat( string registrationNumber, string manufacturer, DateTime yearOfModel, long length );
+
+ void RegisterBoat( IBoat unregisteredBoat );
+
+ IEnumerable< IBoat > RegisteredBoats();
+
+ void Lease( ISlip slip, ILeaseDuration duration );
+
+ IEnumerable< ISlipLease > Leases();
+
+ IRegistration Registration();
+
+ void RegisterAccount( string username, string password, string firstName,
+ string lastName, string phoneNumber, string city );
+
+ void UpdateRegistrationTo( IRegistration registration );
+
+ void UpdateRegistrationTo( string username, string password, string firstName, string lastName,
+ string phoneNumber,
+ string city );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IDateRange.cs b/slips/src/app/Marina/Domain/Interfaces/IDateRange.cs new file mode 100644 index 0000000..ec53b90 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IDateRange.cs @@ -0,0 +1,9 @@ +using System;
+
+namespace Marina.Domain.Interfaces {
+ public interface IDateRange {
+ DateTime Start();
+
+ DateTime End();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IDock.cs b/slips/src/app/Marina/Domain/Interfaces/IDock.cs new file mode 100644 index 0000000..add87fb --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IDock.cs @@ -0,0 +1,11 @@ +namespace Marina.Domain.Interfaces {
+ public interface IDock {
+ long ID();
+
+ string Name();
+
+ ILocation Location();
+
+ bool IsUtilityEnabled( IUtility utility );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IDomainObject.cs b/slips/src/app/Marina/Domain/Interfaces/IDomainObject.cs new file mode 100644 index 0000000..c8a2c17 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IDomainObject.cs @@ -0,0 +1,7 @@ +namespace Marina.Domain.Interfaces {
+ public interface IDomainObject {
+ long ID();
+
+ void ChangeIdTo( long id );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/ILeaseDuration.cs b/slips/src/app/Marina/Domain/Interfaces/ILeaseDuration.cs new file mode 100644 index 0000000..402398d --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/ILeaseDuration.cs @@ -0,0 +1,10 @@ +using System;
+using Marina.Infrastructure;
+
+namespace Marina.Domain.Interfaces {
+ public interface ILeaseDuration : IDomainObject, ISpecification< IDateRange > {
+ DateTime CalculateExpiryDateFrom( DateTime startDate );
+
+ string Name();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/ILeaseType.cs b/slips/src/app/Marina/Domain/Interfaces/ILeaseType.cs new file mode 100644 index 0000000..1fb50b9 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/ILeaseType.cs @@ -0,0 +1,7 @@ +namespace Marina.Domain.Interfaces {
+ public interface ILeaseType {
+ string Name();
+
+ double Rate();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/ILocation.cs b/slips/src/app/Marina/Domain/Interfaces/ILocation.cs new file mode 100644 index 0000000..2464e8c --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/ILocation.cs @@ -0,0 +1,5 @@ +namespace Marina.Domain.Interfaces {
+ public interface ILocation {
+ string Name();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IRange.cs b/slips/src/app/Marina/Domain/Interfaces/IRange.cs new file mode 100644 index 0000000..e18cc33 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IRange.cs @@ -0,0 +1,11 @@ +using System;
+
+namespace Marina.Domain.Interfaces {
+ public interface IRange< T > where T : IComparable< T > {
+ T Start();
+
+ T End();
+
+ bool Contains( T value );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IRegistration.cs b/slips/src/app/Marina/Domain/Interfaces/IRegistration.cs new file mode 100644 index 0000000..de470c6 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IRegistration.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain.Interfaces {
+ public interface IRegistration {
+ string Username();
+
+ string Password();
+
+ string FirstName();
+
+ string LastName();
+
+ string PhoneNumber();
+
+ string City();
+
+ bool IsValid();
+
+ IEnumerable< IBrokenRule > BrokenRules();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/ISlip.cs b/slips/src/app/Marina/Domain/Interfaces/ISlip.cs new file mode 100644 index 0000000..8ae576c --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/ISlip.cs @@ -0,0 +1,15 @@ +namespace Marina.Domain.Interfaces {
+ public interface ISlip : IDomainObject {
+ IDock Dock();
+
+ ILocation Location();
+
+ int Width();
+
+ int Length();
+
+ ISlipLease LeaseTo( ICustomer customer, ILeaseDuration duration );
+
+ bool IsLeased();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/ISlipLease.cs b/slips/src/app/Marina/Domain/Interfaces/ISlipLease.cs new file mode 100644 index 0000000..219fb27 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/ISlipLease.cs @@ -0,0 +1,13 @@ +using System;
+
+namespace Marina.Domain.Interfaces {
+ public interface ISlipLease {
+ ILeaseDuration Duration();
+
+ DateTime StartDate();
+
+ DateTime ExpiryDate();
+
+ ISlip Slip();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Interfaces/IUtility.cs b/slips/src/app/Marina/Domain/Interfaces/IUtility.cs new file mode 100644 index 0000000..77954d9 --- /dev/null +++ b/slips/src/app/Marina/Domain/Interfaces/IUtility.cs @@ -0,0 +1,5 @@ +namespace Marina.Domain.Interfaces {
+ public interface IUtility {
+ bool IsEnabled( IUtility utility );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/LeaseDurations.cs b/slips/src/app/Marina/Domain/LeaseDurations.cs new file mode 100644 index 0000000..e87e567 --- /dev/null +++ b/slips/src/app/Marina/Domain/LeaseDurations.cs @@ -0,0 +1,62 @@ +using System;
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class LeaseDurations {
+ public static readonly ILeaseDuration Daily = new LeaseDuration( "Daily", 1, 1 );
+ public static readonly ILeaseDuration Weekly = new LeaseDuration( "Weekly", 2, 7 );
+ public static readonly ILeaseDuration Monthly = new LeaseDuration( "Monthly", 3, 30 );
+ public static readonly ILeaseDuration Yearly = new LeaseDuration( "Yearly", 4, 365 );
+ private static readonly ILeaseDuration NoDuration = new LeaseDuration( "No Duration", -1, 0 );
+ private static readonly ILeaseDuration UnknownDuration = new LeaseDuration( "Unknown", -1, 0 );
+
+ private class LeaseDuration : DomainObject, ILeaseDuration {
+ private readonly int _days;
+ private readonly string _name;
+
+ public LeaseDuration( string name, long id, int days ) : base( id ) {
+ _days = days;
+ _name = name;
+ }
+
+ public DateTime CalculateExpiryDateFrom( DateTime startDate ) {
+ return startDate.AddDays( _days ).Date.AddHours( 11 );
+ }
+
+ public string Name() {
+ return _name;
+ }
+
+ public bool IsSatisfiedBy( IDateRange range ) {
+ TimeSpan daysInRange = range.End( ).Subtract( range.Start( ) );
+ return _days <= daysInRange.Days;
+ }
+ }
+
+ public static ILeaseDuration FindFor( DateTime startDate, DateTime endDate ) {
+ foreach ( ILeaseDuration duration in AllDurations( ) ) {
+ if ( duration.IsSatisfiedBy( new DateRange( startDate, endDate ) ) ) {
+ return duration;
+ }
+ }
+ return NoDuration;
+ }
+
+ private static IEnumerable< ILeaseDuration > AllDurations() {
+ yield return Yearly;
+ yield return Monthly;
+ yield return Weekly;
+ yield return Daily;
+ }
+
+ public static ILeaseDuration FindBy( string duration ) {
+ foreach ( ILeaseDuration leaseDuration in AllDurations( ) ) {
+ if ( string.Compare( leaseDuration.Name( ), duration, true ) == 0 ) {
+ return leaseDuration;
+ }
+ }
+ return UnknownDuration;
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Location.cs b/slips/src/app/Marina/Domain/Location.cs new file mode 100644 index 0000000..eb68748 --- /dev/null +++ b/slips/src/app/Marina/Domain/Location.cs @@ -0,0 +1,15 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class Location : ILocation {
+ public Location( string name ) {
+ _name = name;
+ }
+
+ public string Name() {
+ return _name;
+ }
+
+ private readonly string _name;
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Range.cs b/slips/src/app/Marina/Domain/Range.cs new file mode 100644 index 0000000..4b76b25 --- /dev/null +++ b/slips/src/app/Marina/Domain/Range.cs @@ -0,0 +1,32 @@ +using System;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class Range< T > : IRange< T > where T : IComparable< T > {
+ private readonly T start;
+ private readonly T end;
+
+ public Range( T start, T end ) {
+ if ( start.CompareTo( end ) <= 0 ) {
+ this.start = start;
+ this.end = end;
+ }
+ else {
+ this.start = end;
+ this.end = start;
+ }
+ }
+
+ public T Start() {
+ return start;
+ }
+
+ public T End() {
+ return end;
+ }
+
+ public bool Contains( T value ) {
+ return value.CompareTo( start ) >= 0 && value.CompareTo( end ) <= 0;
+ }
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Repositories/ICustomerRepository.cs b/slips/src/app/Marina/Domain/Repositories/ICustomerRepository.cs new file mode 100644 index 0000000..439bb12 --- /dev/null +++ b/slips/src/app/Marina/Domain/Repositories/ICustomerRepository.cs @@ -0,0 +1,13 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain.Repositories {
+ public interface ICustomerRepository {
+ ICustomer FindBy( long customerId );
+
+ ICustomer FindBy( string username );
+
+ void Save( ICustomer customer );
+
+ ICustomer NewCustomer();
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Repositories/IDockRepository.cs b/slips/src/app/Marina/Domain/Repositories/IDockRepository.cs new file mode 100644 index 0000000..de9e51f --- /dev/null +++ b/slips/src/app/Marina/Domain/Repositories/IDockRepository.cs @@ -0,0 +1,7 @@ +using Marina.Domain.Interfaces;
+
+namespace Marina.Domain.Repositories {
+ public interface IDockRepository {
+ IDock FindBy( long dockId );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Repositories/ISlipsRepository.cs b/slips/src/app/Marina/Domain/Repositories/ISlipsRepository.cs new file mode 100644 index 0000000..8a23ca6 --- /dev/null +++ b/slips/src/app/Marina/Domain/Repositories/ISlipsRepository.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain.Repositories {
+ public interface ISlipsRepository {
+ IEnumerable< ISlip > AllAvailableSlips();
+
+ IEnumerable< ISlip > AllAvailableSlipsFor( IDock dock );
+
+ ISlip FindBy( long slipId );
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Slip.cs b/slips/src/app/Marina/Domain/Slip.cs new file mode 100644 index 0000000..6b8a9b7 --- /dev/null +++ b/slips/src/app/Marina/Domain/Slip.cs @@ -0,0 +1,46 @@ +using Marina.Domain.Exceptions;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class Slip : DomainObject, ISlip {
+ public Slip( long id, IDock dock, int width, int length, bool isLeased ) : base( id ) {
+ _dock = dock;
+ _width = width;
+ _length = length;
+ _isLeased = isLeased;
+ }
+
+ public IDock Dock() {
+ return _dock;
+ }
+
+ public ILocation Location() {
+ return _dock.Location( );
+ }
+
+ public int Width() {
+ return _width;
+ }
+
+ public int Length() {
+ return _length;
+ }
+
+ public ISlipLease LeaseTo( ICustomer customer, ILeaseDuration duration ) {
+ if ( !IsLeased( ) ) {
+ _isLeased = true;
+ return new SlipLease( this, duration );
+ }
+ throw new SlipIsAlreadyLeasedException( );
+ }
+
+ public bool IsLeased() {
+ return _isLeased;
+ }
+
+ private readonly IDock _dock;
+ private readonly int _width;
+ private readonly int _length;
+ private bool _isLeased;
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/SlipLease.cs b/slips/src/app/Marina/Domain/SlipLease.cs new file mode 100644 index 0000000..297bbf0 --- /dev/null +++ b/slips/src/app/Marina/Domain/SlipLease.cs @@ -0,0 +1,37 @@ +using System;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class SlipLease : ISlipLease {
+ public SlipLease( ISlip slip, ILeaseDuration duration )
+ : this( slip, duration, DateTime.Now.Date, duration.CalculateExpiryDateFrom( DateTime.Now.Date ) ) {}
+
+ public SlipLease( ISlip slip, ILeaseDuration duration, DateTime startDate, DateTime expiryDate ) {
+ _slip = slip;
+ _duration = duration;
+ _startDate = startDate;
+ _expiryDate = expiryDate;
+ }
+
+ public ILeaseDuration Duration() {
+ return _duration;
+ }
+
+ public DateTime StartDate() {
+ return _startDate;
+ }
+
+ public DateTime ExpiryDate() {
+ return _expiryDate;
+ }
+
+ public ISlip Slip() {
+ return _slip;
+ }
+
+ private readonly ILeaseDuration _duration;
+ private readonly DateTime _startDate;
+ private readonly DateTime _expiryDate;
+ private readonly ISlip _slip;
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/UnknownCustomer.cs b/slips/src/app/Marina/Domain/UnknownCustomer.cs new file mode 100644 index 0000000..f79f4cc --- /dev/null +++ b/slips/src/app/Marina/Domain/UnknownCustomer.cs @@ -0,0 +1,39 @@ +using System;
+using System.Collections.Generic;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class UnknownCustomer : ICustomer {
+ public void RegisterBoat( string registrationNumber, string manufacturer, DateTime yearOfModel, long length ) {}
+
+ public void RegisterBoat( IBoat unregisteredBoat ) {}
+
+ public IEnumerable< IBoat > RegisteredBoats() {
+ return new List< IBoat >( );
+ }
+
+ public void Lease( ISlip slip, ILeaseDuration duration ) {}
+
+ public IEnumerable< ISlipLease > Leases() {
+ return new List< ISlipLease >( );
+ }
+
+ public IRegistration Registration() {
+ return CustomerRegistration.BlankRegistration( );
+ }
+
+ public void RegisterAccount( string username, string password, string firstName, string lastName, string phoneNumber,
+ string city ) {}
+
+ public void UpdateRegistrationTo( IRegistration registration ) {}
+
+ public void UpdateRegistrationTo( string username, string password, string firstName, string lastName,
+ string phoneNumber, string city ) {}
+
+ public long ID() {
+ return -1;
+ }
+
+ public void ChangeIdTo( long id ) {}
+ }
+}
\ No newline at end of file diff --git a/slips/src/app/Marina/Domain/Utilities.cs b/slips/src/app/Marina/Domain/Utilities.cs new file mode 100644 index 0000000..d318a86 --- /dev/null +++ b/slips/src/app/Marina/Domain/Utilities.cs @@ -0,0 +1,91 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using Marina.Domain.Interfaces;
+
+namespace Marina.Domain {
+ public class Utilities {
+ public static readonly IUtility Water = new Utility( "Water" );
+ public static readonly IUtility Electrical = new Utility( "Electrical" );
+ private static readonly IUtility None = new Utility( "None" );
+
+ public static IUtility For( params IUtility[] utilities ) {
+ if ( null != utilities && 0 < utilities.Length ) {
+ return new UtilityComposite( utilities );
+ }
+ return None;
+ }
+
+ private class Utility : IUtility, IEquatable< Utility > {
+ private readonly string _name;
+
+ public Utility( string name ) {
+ _name = name;
+ }
+
+ public bool IsEnabled( IUtility utility ) {
+ return Equals( utility );
+ }
+
+ public bool Equals( Utility utility ) {
+ if ( utility == null ) {
+ return false;
+ }
+ return Equals( _name, utility._name );
+ }
+
+ public override bool Equals( object obj ) {
+ if ( ReferenceEquals( this, obj ) ) {
+ return true;
+ }
+ return Equals( obj as Utility );
+ }
+
+ public override int GetHashCode() {
+ return _name.GetHashCode( );
+ }
+
+ public override string ToString() {
+ return _name;
+ }
+ }
+
+ private class UtilityComposite : IUtility {
+ private readonly IEnumerable< IUtility > _utilities;
+
+ public UtilityComposite( params IUtility[] utilities ) {
+ _utilities = new List< IUtility >( utilities );
+ }
+
+ public bool IsEnabled( IUtility utility ) {
+ return Equals( utility );
+ }
+
+ public override bool Equals( object obj ) {
+ if ( ReferenceEquals( this, obj ) ) {
+ return true;
+ }
+ foreach ( IUtility utility in _utilities ) {
+ if ( utility != null ) {
+ if ( utility.Equals( obj ) ) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public override int GetHashCode() {
+ return 0;
+ }
+
+ public override string ToString() {
+ StringBuilder builder = new StringBuilder( );
+ foreach ( IUtility utility in _utilities ) {
+ builder.Append( utility.ToString( ) );
+ }
+ return builder.ToString( );
+ }
+ }
+ }
+}
\ No newline at end of file |
