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
|
using Marina.DataAccess;
using Marina.DataAccess.Builders;
using Marina.DataAccess.DataMappers;
using Marina.DataAccess.Schemas;
using Marina.Domain;
using Marina.Domain.Interfaces;
using Marina.Infrastructure.Container;
using Marina.Test.Utility;
using MbUnit.Framework;
namespace Marina.Test.Integration.DataAccess.Mappers {
[TestFixture]
public class RegistrationDataMapperTest {
public IRegistrationDataMapper CreateSUT() {
return new RegistrationDataMapper( );
}
[RunInRealContainer]
[Test]
public void Should_be_able_to_find_john() {
int customerId = 1000;
IRegistration registration = CreateSUT( ).For( customerId );
Assert.AreEqual( "John", registration.FirstName( ) );
Assert.AreEqual( "Doe", registration.LastName( ) );
Assert.AreEqual( "555-545-1212", registration.PhoneNumber( ) );
Assert.AreEqual( "Phoenix", registration.City( ) );
}
[RunInRealContainer]
[Test]
[RollBack]
public void Should_be_able_to_insert_new_registration_for_customer() {
IRegistrationDataMapper mapper = CreateSUT( );
long customerId = CreateCustomerRecord( );
IRegistration expectedRegistration =
new CustomerRegistration( "mokhan", "password", "mo", "khan", "4036813389", "calgary" );
mapper.Insert( expectedRegistration, customerId );
IRegistration actualRegistration = mapper.For( customerId );
Assert.AreEqual( expectedRegistration, actualRegistration );
}
[RunInRealContainer]
[Test]
[RollBack]
public void Should_be_able_to_update_record() {
IRegistrationDataMapper mapper = CreateSUT( );
long customerId = CreateCustomerRecord( );
IRegistration firstRegistration =
new CustomerRegistration( "mokhan", "password", "mo", "khan", "4036813389", "calgary" );
IRegistration expectedRegistration =
new CustomerRegistration( "khanmo", "wordpass", "om", "ankh", "1338940368", "garycal" );
mapper.Insert( firstRegistration, customerId );
mapper.Update( expectedRegistration, customerId );
IRegistration actualRegistration = mapper.For( customerId );
Assert.AreEqual( expectedRegistration, actualRegistration );
}
private long CreateCustomerRecord() {
IQuery query = DatabaseInsert.Into( CustomerTable.TableName )
.AddValue( CustomerTable.FirstName, string.Empty )
.AddValue( CustomerTable.LastName, string.Empty )
.AddValue( CustomerTable.Phone, string.Empty )
.AddValue( CustomerTable.City, string.Empty ).Build( );
return Resolve.DependencyFor< IDatabaseGateway >( ).ExecuteScalar( query );
}
}
}
|