dotnet-installer/test/dotnet-test.UnitTests/DotnetTestMessageScenario.cs
Livar Cunha 7630337074 Adding unit tests for the state machine of dotnet test. Starting the implementation of a state machine in dotnet test. Right now we only handle the TestSession:Terminate message.
Adding a message handler for the version check message. Also introduced an IDotnetTest that handles state and handlers (the state machine).

Adding the test discover start message handler and introducing a test runner.

Added the handler for the GetTestRunnerProcessInfo message. Also, modified dotnet test to have separate setter for the special message handlers for terminate and unknown messages and added a separate method to add new reporting channels to DotnetTest, so that it can handle the new listener for the test runner.

Added the test runner test discovery handlers.

Added handlers to deal with the test execution itself.

Updated dotnet-test program to use the message handlers during design time.

Added a test for the whole discover tests message flow.

Added a test for the run tests full message exchange.
2016-02-23 11:20:04 -08:00

76 lines
No EOL
3.1 KiB
C#

using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test;
using Microsoft.Extensions.Testing.Abstractions;
using Moq;
using Newtonsoft.Json.Linq;
namespace Microsoft.Dotnet.Tools.Test.Tests
{
public class DotnetTestMessageScenario
{
private TestMessagesCollection _messages;
private const string AssemblyUnderTest = "assembly.dll";
private const string TestRunner = "testRunner";
private const int Port = 1;
public DotnetTest DotnetTestUnderTest { get; private set; }
public Mock<ITestRunner> TestRunnerMock { get; private set; }
public Mock<IReportingChannel> AdapterChannelMock { get; private set; }
public Mock<IReportingChannel> TestRunnerChannelMock { get; private set; }
public DotnetTestMessageScenario()
{
_messages = new TestMessagesCollection();
DotnetTestUnderTest = new DotnetTest(_messages, AssemblyUnderTest);
TestRunnerChannelMock = new Mock<IReportingChannel>();
TestRunnerMock = new Mock<ITestRunner>();
AdapterChannelMock = new Mock<IReportingChannel>();
}
public void Run()
{
var reportingChannelFactoryMock = new Mock<IReportingChannelFactory>();
reportingChannelFactoryMock
.Setup(r => r.CreateChannelWithAnyAvailablePort())
.Returns(TestRunnerChannelMock.Object);
var commandFactoryMock = new Mock<ICommandFactory>();
var testRunnerFactoryMock = new Mock<ITestRunnerFactory>();
testRunnerFactoryMock
.Setup(t => t.CreateTestRunner(It.IsAny<DiscoverTestsArgumentsBuilder>()))
.Returns(TestRunnerMock.Object);
testRunnerFactoryMock
.Setup(t => t.CreateTestRunner(It.IsAny<RunTestsArgumentsBuilder>()))
.Returns(TestRunnerMock.Object);
var reportingChannelFactory = reportingChannelFactoryMock.Object;
var adapterChannel = AdapterChannelMock.Object;
var commandFactory = commandFactoryMock.Object;
var testRunnerFactory = testRunnerFactoryMock.Object;
using (DotnetTestUnderTest)
{
DotnetTestUnderTest
.AddNonSpecificMessageHandlers(_messages, adapterChannel)
.AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
.AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
.AddTestRunnnersMessageHandlers(adapterChannel);
DotnetTestUnderTest.StartListeningTo(adapterChannel);
AdapterChannelMock.Raise(r => r.MessageReceived += null, DotnetTestUnderTest, new Message
{
MessageType = TestMessageTypes.VersionCheck,
Payload = JToken.FromObject(new ProtocolVersionMessage { Version = 1 })
});
DotnetTestUnderTest.StartHandlingMessages();
}
AdapterChannelMock.Verify();
TestRunnerMock.Verify();
}
}
}