-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarTest.cs
108 lines (89 loc) · 2.68 KB
/
CarTest.cs
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
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Expedia;
using Rhino.Mocks;
namespace ExpediaTest
{
[TestFixture()]
public class CarTest
{
private Car targetCar;
private MockRepository mocks;
[SetUp()]
public void SetUp()
{
targetCar = new Car(5);
mocks = new MockRepository();
}
[Test()]
public void TestThatCarInitializes()
{
Assert.IsNotNull(targetCar);
}
[Test()]
public void TestThatCarHasCorrectBasePriceForFiveDays()
{
Assert.AreEqual(50, targetCar.getBasePrice() );
}
[Test()]
public void TestThatCarHasCorrectBasePriceForTenDays()
{
var target = new Car(10);
Assert.AreEqual(80, target.getBasePrice());
}
[Test()]
public void TestThatCarHasCorrectBasePriceForSevenDays()
{
var target = new Car(7);
Assert.AreEqual(10*7*.8, target.getBasePrice());
}
[Test()]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void TestThatCarThrowsOnBadLength()
{
new Car(-5);
}
[Test()]
public void TestThatCarDoesGetLocationFromTheDatabase()
{
IDatabase mockDatabase = mocks.Stub<IDatabase>();
String carLocation = "On a whale";
String anotherCarLocation = "On a raptor ranch";
using (mocks.Record())
{
// The mock will return "On a whale" when the call is made with 24
mockDatabase.getCarLocation(24);
LastCall.Return(carLocation);
// The mock will return "Raptor Wrangler" when the call is made with 1025
mockDatabase.getCarLocation(1025);
LastCall.Return(anotherCarLocation);
}
var target = new Car(10);
target.Database = mockDatabase;
String result;
result = target.getCarLocation(1025);
Assert.AreEqual(result, anotherCarLocation);
result = target.getCarLocation(24);
Assert.AreEqual(result, carLocation);
}
[Test()]
public void TestThatCarDoesGetMilageFromDatabase()
{
IDatabase mockDatabase = mocks.Stub<IDatabase>();
int Miles = 442;
mockDatabase.Miles = Miles;
var target = new Car(10) {Database = mockDatabase};
int Mileage = target.Mileage;
Assert.AreEqual(Mileage, Miles);
}
[Test()]
public void TestThatBasePriceIsCorrectUsingObjectMother()
{
var targetBMW = ObjectMother.BMW();
var targetSaab = ObjectMother.Saab();
Assert.AreEqual(10*7*.8, targetSaab.getBasePrice());
Assert.AreEqual(80, targetBMW.getBasePrice());
}
}
}