summaryrefslogtreecommitdiff
path: root/slips/src/test/Marina.Test/Unit/Domain/CustomerTest.cs
blob: 604b049c38cf22f0f4a22848d375b6173ace3c8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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( ) );
		}
	}
}