-
Notifications
You must be signed in to change notification settings - Fork 4
/
1_Interfaces.cs
executable file
·90 lines (79 loc) · 1.99 KB
/
1_Interfaces.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
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MoqKoans.KoansHelpers;
namespace MoqKoans
{
/// <summary>
/// The tests in this class will make you familiar with creating Mock objects with Moq.
/// </summary>
[TestClass]
public class Moq1_Interfaces : Koan
{
// This is an interface that we will be mocking.
public interface IVolume
{
void Louder();
void Quieter();
string Current();
}
// This is a simple implementation of IVolume.
private class Volume : IVolume
{
private int volume = 50;
public void Louder() { volume++; }
public void Quieter() { volume--; }
public string Current() { return volume.ToString(); }
}
[TestMethod]
public void VariablesStartAsNull()
{
IVolume volume = null;
Assert.AreEqual(___, volume == null);
}
[TestMethod]
public void AnInstanceOfVolumeIsAlsoAnIVolume()
{
var volume = new Volume();
Assert.AreEqual(___, volume is IVolume);
}
[TestMethod]
public void AMockOfIVolumeIsNotAnIVolume()
{
var volume = new Moq.Mock<IVolume>();
Assert.AreEqual(___, volume is IVolume);
Assert.IsTrue(volume is ___);
}
[TestMethod]
public void TheObjectPropertyOfAMockReturnsAnInstanceThatImplementsTheMockedInterface()
{
var volume = new Moq.Mock<IVolume>();
Assert.AreEqual(___, volume.Object is IVolume);
}
// IVolume was a public interface.
// This one is private instead.
private interface IPrivateInterface
{
string SomeMethod();
}
[TestMethod]
public void CanNotMockAPrivateInterface()
{
var throwsException = false;
try
{
var mock = new Moq.Mock<IPrivateInterface>().Object;
}
catch (Exception)
{
throwsException = true;
}
Assert.AreEqual(___, throwsException);
}
[TestMethod]
public void CreateANewMockOfIVolumeToMakeThisTestPass()
{
var mock = new ___();
Assert.IsInstanceOfType(mock, typeof(Moq.Mock<IVolume>));
}
}
}