/
CommandCenterTests.cs
93 lines (78 loc) · 3.52 KB
/
CommandCenterTests.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
using System.Collections.Generic;
using Moq;
using NUnit.Framework;
using Nasa.MarsRover.Command;
using Nasa.MarsRover.Command.Interpret;
using Nasa.MarsRover.LandingSurface;
using Nasa.MarsRover.Report;
using Nasa.MarsRover.Rovers;
namespace Nasa.MarsRover.Tests
{
public class CommandCenterTests
{
[TestFixture]
public class CommandCenter_Constructor
{
[Test]
public void Assigns_LandingSurface_to_CommandInvoker_for_use_in_commands()
{
var mockLandingSurface = new Mock<ILandingSurface>();
var mockCommandInvoker = new Mock<ICommandInvoker>();
var commandCenter = new CommandCenter(mockLandingSurface.Object, null, mockCommandInvoker.Object, null);
mockCommandInvoker.Verify(x => x.SetLandingSurface(mockLandingSurface.Object), Times.Once());
}
[Test]
public void Assigns_a_rover_list_to_CommandInvoker_for_use_in_commands()
{
var mockCommandInvoker = new Mock<ICommandInvoker>();
var commandCenter = new CommandCenter(null, null, mockCommandInvoker.Object, null);
mockCommandInvoker.Verify(x => x.SetRovers(It.IsAny<IList<IRover>>()), Times.Once());
}
}
[TestFixture]
public class CommandCenter_Execute
{
[Test]
public void Parses_command_string_and_invokes_all_commands()
{
var expectedInvocationList = new ICommand[]{};
var mockCommandParser = new Mock<ICommandParser>();
mockCommandParser.Setup(x => x.Parse(null)).Returns(expectedInvocationList);
var mockCommandInvoker = new Mock<ICommandInvoker>();
var commandCenter = new CommandCenter(null, mockCommandParser.Object, mockCommandInvoker.Object, null);
commandCenter.Execute(null);
mockCommandInvoker.Verify(x => x.Assign(expectedInvocationList), Times.Once());
mockCommandInvoker.Verify(x => x.InvokeAll(), Times.Once());
}
}
[TestFixture]
public class CommandCenter_GetLandingSurface
{
[Test]
public void Returns_injected_LandingSurface()
{
var expectedLandingSurface = new Mock<ILandingSurface>();
var mockCommandinvoker = new Mock<ICommandInvoker>();
var commandCenter = new CommandCenter(expectedLandingSurface.Object, null, mockCommandinvoker.Object, null);
var landingSurface = commandCenter.GetLandingSurface();
Assert.AreEqual(expectedLandingSurface.Object, landingSurface);
}
}
[TestFixture]
public class CommandCenter_GetCombinedRoverReport
{
[Test]
public void Invokes_ReportComposer_CompileReports()
{
const string expectedReport = "any";
var mockReportComposer = new Mock<IReportComposer>();
var mockCommandInvoker = new Mock<ICommandInvoker>();
mockReportComposer.Setup(x => x.CompileReports(It.IsAny<List<IRover>>()))
.Returns(expectedReport);
var commandCenter = new CommandCenter(null, null, mockCommandInvoker.Object, mockReportComposer.Object);
var report = commandCenter.GetCombinedRoverReport();
Assert.AreEqual(expectedReport, report);
}
}
}
}