-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarTest.cs
95 lines (79 loc) · 2.33 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
using System;
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 TestThatCarDoesGetMileageFromTheDatabase()
{
IDatabase mockDatabase = mocks.Stub<IDatabase>();
String ZeroMileage = "Zero mileage, you're going nowhere";
String NegativeMileage = "Neagive mileage, you're going backwards";
String PositiveMileage = "Positive Mileage, you're doing it right";
using (mocks.Record())
{
mockDatabase.getCarLocation(0);
LastCall.Return(ZeroMileage);
mockDatabase.getCarLocation(-45);
LastCall.Return(NegativeMileage);
mockDatabase.getCarLocation(80);
LastCall.Return(PositiveMileage);
}
var target = new Car(10);
target.Database = mockDatabase;
String result;
result = target.getCarLocation(0);
Assert.AreEqual(result, ZeroMileage);
result = target.getCarLocation(-45);
Assert.AreEqual(result, NegativeMileage);
result = target.getCarLocation(80);
Assert.AreEqual(result, PositiveMileage);
}
[Test()]
public void TestThatBMWHasCorrectPrice()
{
var target = ObjectMother.bmw();
Assert.AreEqual(80, target.getBasePrice());
}
}
}