summaryrefslogtreecommitdiff
path: root/slips/src/test/Marina.Test/Unit/Domain
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/Unit/Domain
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/Unit/Domain')
-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
6 files changed, 351 insertions, 0 deletions
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