summaryrefslogtreecommitdiff
path: root/slips/src/test/Marina.Test/Unit/Presentation/CurrentLeasesPresenterTest.cs
blob: a9f2cb124d5bdb35dc0f1ffe5dff30e649562b41 (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
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 CurrentLeasesPresenterTest {
		private MockRepository _mockery;
		private ILeaseTasks task;
		private IHttpRequest mockRequest;
		private ICurrentLeasesView mockView;

		[SetUp]
		public void Setup() {
			_mockery = new MockRepository( );
			task = _mockery.DynamicMock< ILeaseTasks >( );
			mockRequest = _mockery.DynamicMock< IHttpRequest >( );
			mockView = _mockery.DynamicMock< ICurrentLeasesView >( );
		}

		public ICurrentLeasesPresenter CreateSUT() {
			return new CurrentLeasesPresenter( mockView, mockRequest, task );
		}

		[Test]
		public void Should_leverage_task_to_retrieve_all_leases_for_customer_id() {
			long customerId = 32;
			IList< DisplayLeaseDTO > dtos = new List< DisplayLeaseDTO >( );

			using ( _mockery.Record( ) ) {
				SetupResult.For( mockRequest.ParsePayloadFor( PayloadKeys.CustomerId ) ).Return( customerId );
				Expect.Call( task.FindAllLeasesFor( customerId ) ).Return( dtos );
			}

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

		[Test]
		public void Should_display_the_found_leases_on_the_view() {
			IList< DisplayLeaseDTO > dtos = new List< DisplayLeaseDTO >( );
			using ( _mockery.Record( ) ) {
				SetupResult
					.For( task.FindAllLeasesFor( 0 ) )
					.IgnoreArguments( )
					.Return( dtos );

				mockView.Display( dtos );
			}

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