Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed CC for in-process console scenarios #4084

Merged
merged 5 commits into from
Oct 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests
  • Loading branch information
Codrin Poienaru committed Oct 24, 2022
commit 72de6e83c0e96f037120385f3ed52f8f3b5997a8
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.TestPlatform.VsTestConsole.TranslationLayer;
using Microsoft.TestPlatform.VsTestConsole.TranslationLayer.Interfaces;
Expand Down Expand Up @@ -38,6 +40,17 @@ public class InProcessVsTestConsoleWrapperTests

private readonly IList<string> _testSources = new List<String>() { "test1", "test2" };
private readonly IList<TestCase> _testCases = new List<TestCase>() { new TestCase(), new TestCase() };
private readonly IList<AttachmentSet> _attachmentSets = new List<AttachmentSet>()
{
new AttachmentSet(new Uri("datacollector://AttachmentSetDataCollector1"), "AttachmentSet1"),
new AttachmentSet(new Uri("datacollector://AttachmentSetDataCollector2"), "AttachmentSet2"),
};
private readonly IList<InvokedDataCollector> _invokedDataCollectors = new List<InvokedDataCollector>()
{
new InvokedDataCollector(new Uri("datacollector://InvokedDataCollector1"), "InvokedDataCollector1", "DummyAssemblyName1", "DummyFilePath1", true),
new InvokedDataCollector(new Uri("datacollector://InvokedDataCollector2"), "InvokedDataCollector2", "DummyAssemblyName2", "DummyFilePath2", false),
};

private readonly string _runSettings = "dummy runsettings";

public InProcessVsTestConsoleWrapperTests()
Expand Down Expand Up @@ -849,4 +862,83 @@ public void InProcessWrapperStartTestSessionSucceedsWhenNoExceptionIsThrown()
mockTestSessionEventsHandler.Verify(eh => eh.HandleStartTestSessionComplete(startTestSessionCompleteArgs), Times.Once);
mockTestSessionEventsHandler.Verify(eh => eh.HandleStopTestSessionComplete(stopTestSessionCompleteArgs), Times.Once);
}

[TestMethod]
public async Task InProcessWrapperProcessTestRunAttachmentsAsyncWithSevenParamsIsSuccessfullyInvoked()
{
var attachmentsEventHandler = new Mock<ITestRunAttachmentsProcessingEventsHandler>();

TestRunAttachmentsProcessingPayload? payload = null;
_mockTestRequestManager
.Setup(trm => trm.ProcessTestRunAttachments(
It.IsAny<TestRunAttachmentsProcessingPayload>(),
It.IsAny<ITestRunAttachmentsProcessingEventsHandler>(),
It.IsAny<ProtocolConfig>()))
.Callback((
TestRunAttachmentsProcessingPayload p,
ITestRunAttachmentsProcessingEventsHandler _,
ProtocolConfig _) => payload = p);

await _consoleWrapper.ProcessTestRunAttachmentsAsync(
_attachmentSets,
_invokedDataCollectors,
_runSettings,
true,
false,
attachmentsEventHandler.Object,
CancellationToken.None);

Assert.IsNotNull(payload);
Assert.IsTrue(_attachmentSets.SequenceEqual(payload.Attachments!));
Assert.IsTrue(_invokedDataCollectors.SequenceEqual(payload.InvokedDataCollectors!));
Assert.AreEqual(_runSettings, payload.RunSettings);
Assert.IsFalse(payload.CollectMetrics);

_mockEventSource.Verify(es => es.TranslationLayerTestRunAttachmentsProcessingStart(), Times.Once);
_mockEventSource.Verify(es => es.TranslationLayerTestRunAttachmentsProcessingStop(), Times.Once);
_mockTestRequestManager.Verify(trm => trm.ResetOptions(), Times.Never);
_mockTestRequestManager.Verify(trm => trm.ProcessTestRunAttachments(
It.IsAny<TestRunAttachmentsProcessingPayload>(),
It.IsAny<ITestRunAttachmentsProcessingEventsHandler>(),
It.IsAny<ProtocolConfig>()), Times.Once);
}

[TestMethod]
public async Task InProcessWrapperProcessTestRunAttachmentsAsyncWithSixParamsIsSuccessfullyInvoked()
{
var attachmentsEventHandler = new Mock<ITestRunAttachmentsProcessingEventsHandler>();

TestRunAttachmentsProcessingPayload? payload = null;
_mockTestRequestManager
.Setup(trm => trm.ProcessTestRunAttachments(
It.IsAny<TestRunAttachmentsProcessingPayload>(),
It.IsAny<ITestRunAttachmentsProcessingEventsHandler>(),
It.IsAny<ProtocolConfig>()))
.Callback((
TestRunAttachmentsProcessingPayload p,
ITestRunAttachmentsProcessingEventsHandler _,
ProtocolConfig _) => payload = p);

await _consoleWrapper.ProcessTestRunAttachmentsAsync(
_attachmentSets,
_runSettings,
true,
false,
attachmentsEventHandler.Object,
CancellationToken.None);

Assert.IsNotNull(payload);
Assert.IsTrue(_attachmentSets.SequenceEqual(payload.Attachments!));
Assert.IsNull(payload.InvokedDataCollectors);
Assert.AreEqual(_runSettings, payload.RunSettings);
Assert.IsFalse(payload.CollectMetrics);

_mockEventSource.Verify(es => es.TranslationLayerTestRunAttachmentsProcessingStart(), Times.Once);
_mockEventSource.Verify(es => es.TranslationLayerTestRunAttachmentsProcessingStop(), Times.Once);
_mockTestRequestManager.Verify(trm => trm.ResetOptions(), Times.Never);
_mockTestRequestManager.Verify(trm => trm.ProcessTestRunAttachments(
It.IsAny<TestRunAttachmentsProcessingPayload>(),
It.IsAny<ITestRunAttachmentsProcessingEventsHandler>(),
It.IsAny<ProtocolConfig>()), Times.Once);
}
}