-
Notifications
You must be signed in to change notification settings - Fork 4
/
8_VerifyProperties.cs
executable file
·62 lines (52 loc) · 1.29 KB
/
8_VerifyProperties.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MoqKoans.KoansHelpers;
namespace MoqKoans
{
[TestClass]
public class Moq8_VerifyProperties : Koan
{
// This is an Interface with some properties.
public interface IPerson
{
string Name { get; set; }
int Age { get; set; }
}
[TestMethod]
public void VerifySetCanBeUsedToEnsureAPropertyIsSetToASpecificValue()
{
var mock = new Mock<IPerson>();
mock.SetupAllProperties();
mock.Object.Name = "John";
mock.VerifySet(x => x.Name = "___");
}
[TestMethod]
public void VerifyGetCanBeUsedToEnsureAPropertyValueIsRead()
{
var mock = new Mock<IPerson>();
mock.SetupProperty(x => x.Age, 24);
var exceptionWasThrown = false;
try
{
mock.VerifyGet(x => x.Age, "The user's age was never checked.");
}
catch (Exception ex)
{
exceptionWasThrown = true;
}
Assert.AreEqual(___, exceptionWasThrown);
}
public static object BuyBeer(IPerson buyer)
{
return buyer.Age >= 21 ? new object() : null;
}
[TestMethod]
public void WriteATestToEnsureTheBuyBeerMethodChecksThePersonsAge()
{
var mock = new ___();
BuyBeer(mock.Object);
mock.___(); // verify the user's age was checked.
}
}
}