dotnet-installer/test/dotnet-test.UnitTests/GivenThatWeWantToRunTests.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

86 lines
3.7 KiB
C#

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics;
using Microsoft.DotNet.Tools.Test;
using Microsoft.Extensions.Testing.Abstractions;
using Moq;
using Newtonsoft.Json.Linq;
using Xunit;
namespace Microsoft.Dotnet.Tools.Test.Tests
{
public class GivenThatWeWantToRunTests
{
[Fact]
public void Dotnet_test_handles_and_sends_all_the_right_messages()
{
var dotnetTestMessageScenario = new DotnetTestMessageScenario();
dotnetTestMessageScenario.TestRunnerMock
.Setup(t => t.GetProcessStartInfo())
.Returns(new ProcessStartInfo())
.Verifiable();
dotnetTestMessageScenario.AdapterChannelMock
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.VersionCheck)))
.Callback(() => dotnetTestMessageScenario.AdapterChannelMock.Raise(
r => r.MessageReceived += null,
dotnetTestMessageScenario.DotnetTestUnderTest,
new Message
{
MessageType = TestMessageTypes.TestExecutionGetTestRunnerProcessStartInfo
}))
.Verifiable();
dotnetTestMessageScenario.AdapterChannelMock
.Setup(a => a.Send(
It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionTestRunnerProcessStartInfo)))
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
t => t.MessageReceived += null,
dotnetTestMessageScenario.DotnetTestUnderTest,
new Message
{
MessageType = TestMessageTypes.TestRunnerTestStarted
}))
.Verifiable();
dotnetTestMessageScenario.AdapterChannelMock
.Setup(a => a.Send(
It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionStarted)))
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
t => t.MessageReceived += null,
dotnetTestMessageScenario.DotnetTestUnderTest,
new Message
{
MessageType = TestMessageTypes.TestRunnerTestResult
}))
.Verifiable();
dotnetTestMessageScenario.AdapterChannelMock
.Setup(a => a.Send(
It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionTestResult)))
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
t => t.MessageReceived += null,
dotnetTestMessageScenario.DotnetTestUnderTest,
new Message
{
MessageType = TestMessageTypes.TestRunnerTestCompleted
}))
.Verifiable();
dotnetTestMessageScenario.AdapterChannelMock
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionCompleted)))
.Callback(() => dotnetTestMessageScenario.AdapterChannelMock.Raise(
r => r.MessageReceived += null,
dotnetTestMessageScenario.DotnetTestUnderTest,
new Message
{
MessageType = TestMessageTypes.TestSessionTerminate
}))
.Verifiable();
dotnetTestMessageScenario.Run();
}
}
}