2016-02-13 02:22:35 +00:00
|
|
|
|
// 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;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test;
|
|
|
|
|
using Microsoft.Extensions.Testing.Abstractions;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.Dotnet.Tools.Test.Tests
|
|
|
|
|
{
|
2016-07-11 19:46:27 +00:00
|
|
|
|
public class GivenAnUnknownMessageHandler
|
2016-02-13 02:22:35 +00:00
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void It_throws_InvalidOperationException_and_sends_an_error_when_the_message_is_not_handled()
|
|
|
|
|
{
|
2016-07-11 19:46:27 +00:00
|
|
|
|
TestHostTracing.ClearListeners();
|
|
|
|
|
|
2016-02-13 02:22:35 +00:00
|
|
|
|
const string expectedError = "No handler for message 'Test Message' when at state 'InitialState'";
|
|
|
|
|
|
|
|
|
|
var dotnetTestMock = new Mock<IDotnetTest>();
|
|
|
|
|
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
|
|
|
|
|
|
|
|
|
var reportingChannel = new Mock<IReportingChannel>();
|
|
|
|
|
reportingChannel.Setup(r => r.SendError(expectedError)).Verifiable();
|
|
|
|
|
|
|
|
|
|
var unknownMessageHandler = new UnknownMessageHandler(reportingChannel.Object);
|
|
|
|
|
|
|
|
|
|
Action action = () => unknownMessageHandler.HandleMessage(
|
|
|
|
|
dotnetTestMock.Object,
|
|
|
|
|
new Message { MessageType = "Test Message" });
|
|
|
|
|
|
|
|
|
|
action.ShouldThrow<InvalidOperationException>().WithMessage(expectedError);
|
|
|
|
|
|
|
|
|
|
reportingChannel.Verify();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|