public DotnetTestMessageScenario() { _messages = new TestMessagesCollection(); DotnetTestUnderTest = new DotnetTest(_messages, AssemblyUnderTest); TestRunnerChannelMock = new Mock <IReportingChannel>(); TestRunnerMock = new Mock <ITestRunner>(); AdapterChannelMock = new Mock <IReportingChannel>(); }
public void It_throws_an_InvalidOperationException_if_StartListeningTo_is_called_without_setting_a_UnknownMessageHandler() { var dotnetTest = new DotnetTest(new TestMessagesCollection(), AssemblyUnderTest) { TestSessionTerminateMessageHandler = new Mock <IDotnetTestMessageHandler>().Object }; Action action = () => dotnetTest.StartListeningTo(new Mock <IReportingChannel>().Object); action.ShouldThrow <InvalidOperationException>(); }
public void It_disposes_all_reporting_channels_that_it_was_listening_to_when_it_gets_disposed() { var firstReportingChannelMock = new Mock <IReportingChannel>(); var secondReportingChannelMock = new Mock <IReportingChannel>(); using (var dotnetTest = new DotnetTest(new TestMessagesCollection(), AssemblyUnderTest)) { dotnetTest.TestSessionTerminateMessageHandler = new Mock <IDotnetTestMessageHandler>().Object; dotnetTest.UnknownMessageHandler = new Mock <IDotnetTestMessageHandler>().Object; dotnetTest.StartListeningTo(firstReportingChannelMock.Object); dotnetTest.StartListeningTo(secondReportingChannelMock.Object); } firstReportingChannelMock.Verify(r => r.Dispose(), Times.Once); secondReportingChannelMock.Verify(r => r.Dispose(), Times.Once); }
public GivenADotnetTestApp() { _noOpMessageHandlerMock = new Mock <IDotnetTestMessageHandler>(); _noOpMessageHandlerMock .Setup(mh => mh.HandleMessage(It.IsAny <DotnetTest>(), It.IsAny <Message>())) .Returns(DotnetTestState.NoOp) .Verifiable(); _realMessageHandlerMock = new Mock <IDotnetTestMessageHandler>(); _realMessageHandlerMock .Setup(mh => mh.HandleMessage(It.IsAny <DotnetTest>(), It.Is <Message>(m => m.MessageType == "Test message"))) .Returns(DotnetTestState.VersionCheckCompleted).Callback(() => _reportingChannelMock.Raise(r => r.MessageReceived += null, _dotnetTest, new Message { MessageType = TestMessageTypes.TestSessionTerminate })); _reportingChannelMock = new Mock <IReportingChannel>(); _unknownMessageHandlerMock = new Mock <IDotnetTestMessageHandler>(); _unknownMessageHandlerMock .Setup(mh => mh.HandleMessage(It.IsAny <DotnetTest>(), It.IsAny <Message>())) .Throws <InvalidOperationException>(); var testMessagesCollection = new TestMessagesCollection(); _dotnetTest = new DotnetTest(testMessagesCollection, AssemblyUnderTest) { TestSessionTerminateMessageHandler = new TestSessionTerminateMessageHandler(testMessagesCollection), UnknownMessageHandler = _unknownMessageHandlerMock.Object }; _dotnetTest.StartListeningTo(_reportingChannelMock.Object); _reportingChannelMock.Raise(r => r.MessageReceived += null, _dotnetTest, new Message { MessageType = "Test message" }); }