summaryrefslogtreecommitdiff
path: root/slips/src/test/Marina.Test/Unit/Presentation/ViewRegisteredBoatsPresenterTest.cs
blob: 144315328b7b3e8442999140e0a8c49012ee51b7 (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
using System.Collections.Generic;
using Marina.Presentation;
using Marina.Presentation.DTO;
using Marina.Presentation.Presenters;
using Marina.Presentation.Views;
using Marina.Task;
using Marina.Web;
using MbUnit.Framework;
using Rhino.Mocks;

namespace Marina.Test.Unit.Presentation {
	[TestFixture]
	public class ViewRegisteredBoatsPresenterTest {
		private MockRepository _mockery;
		private IRegistrationTasks _mockTask;
		private IHttpRequest _mockRequest;
		private IRegisteredBoatsView _mockView;

		[SetUp]
		public void Setup() {
			_mockery = new MockRepository( );
			_mockTask = _mockery.DynamicMock< IRegistrationTasks >( );
			_mockRequest = _mockery.DynamicMock< IHttpRequest >( );
			_mockView = _mockery.DynamicMock< IRegisteredBoatsView >( );
		}

		public IViewRegisteredBoatsPresenter CreateSUT() {
			return new ViewRegisteredBoatsPresenter( _mockView, _mockTask, _mockRequest );
		}

		[Test]
		public void Should_leverage_task_to_retrieve_all_registered_boats_for_customer() {
			long customerId = 23;
			IList< BoatRegistrationDTO > boats = new List< BoatRegistrationDTO >( );

			using ( _mockery.Record( ) ) {
				SetupResult.For( _mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
				Expect.Call( _mockTask.AllBoatsFor( customerId ) ).Return( boats );
			}

			using ( _mockery.Playback( ) ) {
				CreateSUT( ).Initialize( );
			}
		}

		[Test]
		public void Should_display_registered_boats_on_view() {
			IList< BoatRegistrationDTO > boats = new List< BoatRegistrationDTO >( );
			using ( _mockery.Record( ) ) {
				SetupResult.For( _mockTask.AllBoatsFor( 0 ) )
					.IgnoreArguments( )
					.Return( boats );

				_mockView.Display( boats );
			}

			using ( _mockery.Playback( ) ) {
				CreateSUT( ).Initialize( );
			}
		}
	}
}