blob: 81e170b5a9eb7f20d49b71893ea517fdb52f5cf3 (
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
|
using System.Collections.Generic;
using Marina.DataAccess;
using Marina.DataAccess.DataMappers;
using Marina.Domain.Interfaces;
using Marina.Infrastructure;
using MbUnit.Framework;
using Rhino.Mocks;
namespace Marina.Test.Unit.DataAccess.Mappers {
[TestFixture]
public class CustomerDataMapperTest {
private MockRepository _mockery;
private IDatabaseGateway _mockGateway;
private IBoatDataMapper _boatMapper;
private ILeaseDataMapper _leaseDataMapper;
private IRegistrationDataMapper _registrationMapper;
[SetUp]
public void Setup() {
_mockery = new MockRepository( );
_mockGateway = _mockery.DynamicMock< IDatabaseGateway >( );
_boatMapper = _mockery.DynamicMock< IBoatDataMapper >( );
_leaseDataMapper = _mockery.DynamicMock< ILeaseDataMapper >( );
_registrationMapper = _mockery.DynamicMock< IRegistrationDataMapper >( );
}
public ICustomerDataMapper CreateSUT() {
return new CustomerDataMapper( _mockGateway, _boatMapper, _leaseDataMapper, _registrationMapper );
}
[Test]
public void Should_leverage_mapper_to_load_customers_boats() {
long customerId = 32;
IList< IBoat > boats = new List< IBoat >( );
IBoat boat = _mockery.DynamicMock< IBoat >( );
boats.Add( boat );
using ( _mockery.Record( ) ) {
Expect.Call( _boatMapper.AllBoatsFor( customerId ) ).Return( boats );
}
using ( _mockery.Playback( ) ) {
ICustomer customer = CreateSUT( ).FindBy( customerId );
Assert.AreEqual( 1, ListFactory.From( customer.RegisteredBoats( ) ).Count );
Assert.IsTrue( ListFactory.From( customer.RegisteredBoats( ) ).Contains( boat ) );
}
}
[Test]
public void Should_leverage_mapper_to_load_customer_leases() {
long customerId = 32;
IList< ISlipLease > leases = new List< ISlipLease >( );
ISlipLease lease = _mockery.DynamicMock< ISlipLease >( );
leases.Add( lease );
using ( _mockery.Record( ) ) {
Expect
.Call( _leaseDataMapper.AllLeasesFor( customerId ) )
.Return( leases );
}
using ( _mockery.Playback( ) ) {
ICustomer customer = CreateSUT( ).FindBy( customerId );
Assert.AreEqual( 1, ListFactory.From( customer.Leases( ) ).Count );
Assert.IsTrue( ListFactory.From( customer.Leases( ) ).Contains( lease ) );
}
}
[Test]
public void Should_leverage_mapper_to_load_customer_registration() {
long customerId = 59;
IRegistration registration = _mockery.DynamicMock< IRegistration >( );
using ( _mockery.Record( ) ) {
Expect.Call( _registrationMapper.For( customerId ) ).Return( registration );
}
using ( _mockery.Playback( ) ) {
ICustomer customer = CreateSUT( ).FindBy( customerId );
Assert.AreEqual( registration, customer.Registration( ) );
}
}
}
}
|