From 571028e6409c9a92ae7788cc48e62c6fee92f3a0 Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 30 Jun 2020 16:13:08 +0200 Subject: [PATCH] RFC changes merged --- .../MultiTestRunFinalizationEventsHandler.cs | 2 +- .../MultiTestRunFinalizationManager.cs | 31 ++- ...ltiTestRunFinalizationCompleteEventArgs.cs | 2 +- ...ltiTestRunFinalizationProgressEventArgs.cs | 35 ++-- .../IMultiTestRunFinalizationEventsHandler.cs | 8 +- .../IDataCollectorAttachmentProcessor.cs | 38 ++++ .../IDataCollectorAttachments.cs | 12 +- .../CodeCoverageDataAttachmentsHandler.cs | 26 ++- .../Interfaces/IVsTestConsoleWrapperAsync.cs | 7 +- .../VsTestConsoleWrapper.cs | 2 +- .../CodeCoverageTests.cs | 44 ++-- .../MultiTestRunFinalizationEventHandler.cs | 2 +- ...tiTestRunFinalizationEventsHandlerTests.cs | 2 +- .../MultiTestRunFinalizationManagerTests.cs | 188 +++++++++--------- ...CodeCoverageDataAttachmentsHandlerTests.cs | 30 +-- .../VsTestConsoleRequestSenderTests.cs | 4 +- .../VsTestConsoleWrapperAsyncTests.cs | 1 + .../VsTestConsoleWrapperTests.cs | 1 + 18 files changed, 235 insertions(+), 200 deletions(-) create mode 100644 src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs diff --git a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs index b31d7463a9..f0359712de 100644 --- a/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.Client/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandler.cs @@ -55,7 +55,7 @@ public void HandleMultiTestRunFinalizationProgress(MultiTestRunFinalizationProgr } /// - public void HandleFinalisedAttachments(IEnumerable attachments) + public void HandleProcessedAttachmentsChunk(IEnumerable attachments) { throw new System.NotImplementedException(); } diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs index af23cbcaee..661090959f 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/MultiTestRunFinalization/MultiTestRunFinalizationManager.cs @@ -28,15 +28,15 @@ public class MultiTestRunFinalizationManager : IMultiTestRunFinalizationManager private static string FinalizationFailed = "Failed"; private readonly ITestPlatformEventSource testPlatformEventSource; - private readonly IDataCollectorAttachments[] dataCollectorAttachmentsHandlers; + private readonly IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors; /// /// Initializes a new instance of the class. /// - public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachments[] dataCollectorAttachmentsHandlers) + public MultiTestRunFinalizationManager(ITestPlatformEventSource testPlatformEventSource, params IDataCollectorAttachmentProcessor[] dataCollectorAttachmentsProcessors) { this.testPlatformEventSource = testPlatformEventSource ?? throw new ArgumentNullException(nameof(testPlatformEventSource)); - this.dataCollectorAttachmentsHandlers = dataCollectorAttachmentsHandlers ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsHandlers)); + this.dataCollectorAttachmentsProcessors = dataCollectorAttachmentsProcessors ?? throw new ArgumentNullException(nameof(dataCollectorAttachmentsProcessors)); } /// @@ -64,10 +64,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( var taskCompletionSource = new TaskCompletionSource>(); using (cancellationToken.Register(() => taskCompletionSource.TrySetCanceled())) { - Task> task = Task.Run(() => - { - return ProcessAttachments(new Collection(attachments.ToList()), eventHandler, cancellationToken); - }); + Task> task = Task.Run(async () => await ProcessAttachmentsAsync(new Collection(attachments.ToList()), eventHandler, cancellationToken)); var completedTask = await Task.WhenAny(task, taskCompletionSource.Task).ConfigureAwait(false); @@ -77,7 +74,7 @@ private async Task> InternalFinalizeMultiTestRunAsync( } else { - eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Informational, "Finalization was cancelled."); + eventHandler?.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled."); return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(true, null), attachments, stopwatch, eventHandler); } } @@ -94,26 +91,26 @@ private async Task> InternalFinalizeMultiTestRunAsync( { EqtTrace.Error("MultiTestRunFinalizationManager: Exception in FinalizeMultiTestRunAsync: " + e); - eventHandler?.HandleLogMessage(ObjectModel.Logging.TestMessageLevel.Error, e.Message); + eventHandler?.HandleLogMessage(TestMessageLevel.Error, e.Message); return FinalizeOperation(requestData, new MultiTestRunFinalizationCompleteEventArgs(false, e), attachments, stopwatch, eventHandler); } } - private Collection ProcessAttachments(Collection attachments, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken) + private async Task> ProcessAttachmentsAsync(Collection attachments, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken) { if (attachments == null || !attachments.Any()) return attachments; var logger = CreateMessageLogger(eventsHandler); - for (int i = 0; i < dataCollectorAttachmentsHandlers.Length; i++) + for (int i = 0; i < dataCollectorAttachmentsProcessors.Length; i++) { - IDataCollectorAttachments dataCollectorAttachmentsHandler = dataCollectorAttachmentsHandlers[i]; + var dataCollectorAttachmentsProcessor = dataCollectorAttachmentsProcessors[i]; int attachmentsHandlerIndex = i + 1; - Uri attachementUri = dataCollectorAttachmentsHandler.GetExtensionUri(); - if (attachementUri != null) + ICollection attachementProcessorUris = dataCollectorAttachmentsProcessor.GetExtensionUris()?.ToList(); + if (attachementProcessorUris != null && attachementProcessorUris.Any()) { - var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementUri.Equals(dataCollectionAttachment.Uri)).ToArray(); + var attachmentsToBeProcessed = attachments.Where(dataCollectionAttachment => attachementProcessorUris.Any(uri => uri.Equals(dataCollectionAttachment.Uri))).ToArray(); if (attachmentsToBeProcessed.Any()) { foreach (var attachment in attachmentsToBeProcessed) @@ -123,9 +120,9 @@ private Collection ProcessAttachments(Collection a IProgress progressReporter = new Progress((int progress) => eventsHandler?.HandleMultiTestRunFinalizationProgress( - new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, dataCollectorAttachmentsHandler.GetExtensionUri(), progress, dataCollectorAttachmentsHandlers.Length))); + new MultiTestRunFinalizationProgressEventArgs(attachmentsHandlerIndex, attachementProcessorUris, progress, dataCollectorAttachmentsProcessors.Length))); - ICollection processedAttachments = dataCollectorAttachmentsHandler.HandleDataCollectionAttachmentSets(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken); + ICollection processedAttachments = await dataCollectorAttachmentsProcessor.ProcessAttachmentSetsAsync(new Collection(attachmentsToBeProcessed), progressReporter, logger, cancellationToken).ConfigureAwait(false); foreach (var attachment in processedAttachments) { diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs index 4f73073caa..0ca669e6a1 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationCompleteEventArgs.cs @@ -34,7 +34,7 @@ public MultiTestRunFinalizationCompleteEventArgs(bool isCanceled, Exception erro public Exception Error { get; private set; } /// - /// Get or Sets the Metrics + /// Get or Sets the Metrics (used for telemetry) /// [DataMember] public IDictionary Metrics { get; set; } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs index 529be7baaf..9710add944 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Events/MultiTestRunFinalizationProgressEventArgs.cs @@ -4,6 +4,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { using System; + using System.Collections.Generic; using System.Runtime.Serialization; [DataContract] @@ -12,40 +13,40 @@ public class MultiTestRunFinalizationProgressEventArgs : EventArgs /// /// Default constructor. /// - /// Specifies current handler index. - /// Specifies current handler Uri. - /// Specifies current handler progress. - /// Specifies the overall number of handlers. - public MultiTestRunFinalizationProgressEventArgs(long currentHandlerIndex, Uri currentHandlerUri, long currentHandlerProgress, long handlersCount) + /// Specifies current attachment processor index. + /// Specifies current processor Uris. + /// Specifies current processor progress. + /// Specifies the overall number of processors. + public MultiTestRunFinalizationProgressEventArgs(long currentAttachmentProcessorIndex, ICollection currentAttachmentProcessorUris, long currentAttachmentProcessorProgress, long attachmentProcessorsCount) { - CurrentHandlerIndex = currentHandlerIndex; - CurrentHandlerUri = currentHandlerUri; - CurrentHandlerProgress = currentHandlerProgress; - HandlersCount = handlersCount; + CurrentAttachmentProcessorIndex = currentAttachmentProcessorIndex; + CurrentAttachmentProcessorUris = currentAttachmentProcessorUris; + CurrentAttachmentProcessorProgress = currentAttachmentProcessorProgress; + AttachmentProcessorsCount = attachmentProcessorsCount; } /// - /// Gets a current handler index. + /// Gets a current attachment processor index. /// [DataMember] - public long CurrentHandlerIndex { get; private set; } + public long CurrentAttachmentProcessorIndex { get; private set; } /// - /// Gets a current handler URI. + /// Gets a current attachment processor URI. /// [DataMember] - public Uri CurrentHandlerUri { get; private set; } + public ICollection CurrentAttachmentProcessorUris { get; private set; } /// - /// Gets a current handler progress. + /// Gets a current attachment processor progress. /// [DataMember] - public long CurrentHandlerProgress { get; private set; } + public long CurrentAttachmentProcessorProgress { get; private set; } /// - /// Gets the overall number of handlers. + /// Gets the overall number of attachment processors. /// [DataMember] - public long HandlersCount { get; private set; } + public long AttachmentProcessorsCount { get; private set; } } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs index 8c00b00c60..3983bd571e 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/Client/Interfaces/IMultiTestRunFinalizationEventsHandler.cs @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.Client { /// - /// Interface contract for handling multi test run finalization complete events + /// Interface contract for handling multi test run finalization events /// public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandler { @@ -18,10 +18,10 @@ public interface IMultiTestRunFinalizationEventsHandler : ITestMessageEventHandl void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompleteEventArgs finalizationCompleteEventArgs, IEnumerable lastChunk); /// - /// Dispatch FinalisedAttachments event to listeners. + /// Dispatch ProcessedAttachmentsChunk event to listeners. /// - /// Finalised attachment sets. - void HandleFinalisedAttachments(IEnumerable attachments); + /// Processed attachment sets. + void HandleProcessedAttachmentsChunk(IEnumerable attachments); /// /// Dispatch MultiTestRunFinalizationProgress event to listeners. diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs new file mode 100644 index 0000000000..7b996d950d --- /dev/null +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachmentProcessor.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection +{ + using System; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + + /// + /// Interface for data collectors add-ins that choose to reprocess generated attachments + /// + public interface IDataCollectorAttachmentProcessor + { + /// + /// Gets the attachments Uris, which are handled by attachment processor + /// + IEnumerable GetExtensionUris(); + + /// + /// Indicates whether attachment processor is supporting incremental processing of attachments + /// + bool SupportsIncrementalProcessing { get; } + + /// + /// Reprocess attachments generated by independent test executions + /// + /// Attachments to be processed + /// Progress reporter. Accepts integers from 0 to 100 + /// Message logger + /// Cancellation token + /// Attachments after reprocessing + Task> ProcessAttachmentSetsAsync(ICollection attachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken); + } +} diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs index cd9124743b..a342d74ea6 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/IDataCollectorAttachments.cs @@ -3,14 +3,13 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection { - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using System; using System.Collections.Generic; - using System.Threading; /// /// Interface for data collectors add-ins that choose to handle attachment(s) generated /// + [Obsolete("Interface is deprecated. Please use IDataCollectorAttachmentProcessor instead")] public interface IDataCollectorAttachments { /// @@ -19,15 +18,6 @@ public interface IDataCollectorAttachments /// Gets the attachment set after Test Run Session ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments); - /// - /// Gets the attachment set after Test Run Session - /// - /// Attachments to be processed - /// Progress reporter. Accepts integers from 0 to 100 - /// Cancellation token - /// Gets the attachment set after Test Run Session - ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken); - /// /// Gets the attachment Uri, which is handled by current Collector /// diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index d31fda0a56..2b911f6926 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -10,12 +10,13 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities using System.Linq; using System.Reflection; using System.Threading; + using System.Threading.Tasks; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; - public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachments + public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachmentProcessor { private const string CoverageUri = "datacollector://microsoft/CodeCoverage/2.0"; private const string CoverageFileExtension = ".coverage"; @@ -27,35 +28,32 @@ public class CodeCoverageDataAttachmentsHandler : IDataCollectorAttachments private static readonly Uri CodeCoverageDataCollectorUri = new Uri(CoverageUri); - public Uri GetExtensionUri() - { - return CodeCoverageDataCollectorUri; - } + public bool SupportsIncrementalProcessing => true; - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments) + public IEnumerable GetExtensionUris() { - return HandleDataCollectionAttachmentSets(dataCollectionAttachments, null, null, CancellationToken.None); - } + yield return CodeCoverageDataCollectorUri; + } - public ICollection HandleDataCollectionAttachmentSets(ICollection dataCollectionAttachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken) + public Task> ProcessAttachmentSetsAsync(ICollection attachments, IProgress progressReporter, IMessageLogger logger, CancellationToken cancellationToken) { - if (dataCollectionAttachments != null && dataCollectionAttachments.Any()) + if (attachments != null && attachments.Any()) { - var codeCoverageFiles = dataCollectionAttachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); + var codeCoverageFiles = attachments.Select(coverageAttachment => coverageAttachment.Attachments[0].Uri.LocalPath).ToArray(); var outputFile = MergeCodeCoverageFiles(codeCoverageFiles, progressReporter, cancellationToken); var attachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); if (!string.IsNullOrEmpty(outputFile)) { attachmentSet.Attachments.Add(new UriDataAttachment(new Uri(outputFile), CoverageFriendlyName)); - return new Collection { attachmentSet }; + return Task.FromResult((ICollection)new Collection { attachmentSet }); } // In case merging fails(esp in dotnet core we cannot merge), so return filtered list of Code Coverage Attachments - return dataCollectionAttachments; + return Task.FromResult(attachments); } - return new Collection(); + return Task.FromResult((ICollection)new Collection()); } private string MergeCodeCoverageFiles(IList files, IProgress progressReporter, CancellationToken cancellationToken) diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs index 56e322d711..d9f67417cf 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/Interfaces/IVsTestConsoleWrapperAsync.cs @@ -81,9 +81,10 @@ public interface IVsTestConsoleWrapperAsync /// Provides back all attachments to TestPlatform for additional processing (for example merging) /// /// Collection of attachments - /// Enables metrics collection - /// EventHandler to receive session complete event + /// Indicates that all test executions are done and all data is provided + /// Enables metrics collection (used for telemetry) + /// EventHandler to receive session complete event /// Cancellation token - Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler multiTestRunFinalizationCompleteEventsHandler, CancellationToken cancellationToken); + Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler eventsHandler, CancellationToken cancellationToken); } } diff --git a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs index 116a9d3240..e2750b80fe 100644 --- a/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs +++ b/src/Microsoft.TestPlatform.VsTestConsole.TranslationLayer/VsTestConsoleWrapper.cs @@ -407,7 +407,7 @@ public async Task RunTestsWithCustomTestHostAsync(IEnumerable testCase } /// - public async Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) + public async Task FinalizeMultiTestRunAsync(IEnumerable attachments, bool multiTestRunCompleted, bool collectMetrics, IMultiTestRunFinalizationEventsHandler testSessionEventsHandler, CancellationToken cancellationToken) { this.testPlatformEventSource.TranslationLayerMultiTestRunFinalizationStart(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs index 6d2047e105..cc3c7efe62 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/CodeCoverageTests.cs @@ -104,7 +104,7 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -118,12 +118,13 @@ public async Task TestRunWithCodeCoverageAndFinalization(RunnerInfo runnerInfo) for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorUris.Count); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) { - Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -152,7 +153,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run Assert.AreEqual(2, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, false, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, false, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -166,12 +167,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationNoMetrics(RunnerInfo run for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorUris.Count); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 2) { - Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(i == 0 ? 50 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -198,7 +200,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI Assert.AreEqual(3, this.runEventHandler.Attachments.Count); // act - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // Assert multiTestRunFinalizationEventHandler.EnsureSuccess(); @@ -212,13 +214,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationModuleDuplicated(RunnerI for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (multiTestRunFinalizationEventHandler.ProgressArgs.Count == 3) { - Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(i == 0 ? 33 : i == 1 ? 66 : 100, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -250,7 +252,7 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run CancellationTokenSource cts = new CancellationTokenSource(); - Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, multiTestRunFinalizationEventHandler, cts.Token); + Task finalization = this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(attachments, true, true, multiTestRunFinalizationEventHandler, cts.Token); while (true) { @@ -282,13 +284,13 @@ public async Task TestRunWithCodeCoverageAndFinalizationCancelled(RunnerInfo run for (int i = 0; i < multiTestRunFinalizationEventHandler.ProgressArgs.Count; i++) { VisualStudio.TestPlatform.ObjectModel.Client.MultiTestRunFinalizationProgressEventArgs progressArgs = multiTestRunFinalizationEventHandler.ProgressArgs[i]; - Assert.AreEqual(1, progressArgs.CurrentHandlerIndex); - Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentHandlerUri.AbsoluteUri); - Assert.AreEqual(1, progressArgs.HandlersCount); + Assert.AreEqual(1, progressArgs.CurrentAttachmentProcessorIndex); + Assert.AreEqual("datacollector://microsoft/CodeCoverage/2.0", progressArgs.CurrentAttachmentProcessorUris.First().AbsoluteUri); + Assert.AreEqual(1, progressArgs.AttachmentProcessorsCount); if (i == 0) { - Assert.AreEqual(0, progressArgs.CurrentHandlerProgress); + Assert.AreEqual(0, progressArgs.CurrentAttachmentProcessorProgress); } } @@ -316,7 +318,7 @@ public async Task EndSessionShouldEnsureVstestConsoleProcessDies(RunnerInfo runn Assert.AreEqual(6, this.runEventHandler.TestResults.Count); Assert.AreEqual(2, this.runEventHandler.Attachments.Count); - await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, multiTestRunFinalizationEventHandler, CancellationToken.None); + await this.vstestConsoleWrapper.FinalizeMultiTestRunAsync(runEventHandler.Attachments, true, true, multiTestRunFinalizationEventHandler, CancellationToken.None); // act this.vstestConsoleWrapper?.EndSession(); diff --git a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs index 0c867da64e..ed3fc68204 100644 --- a/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs +++ b/test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/EventHandler/MultiTestRunFinalizationEventHandler.cs @@ -96,7 +96,7 @@ public void HandleMultiTestRunFinalizationComplete(MultiTestRunFinalizationCompl CompleteArgs = finalizationCompleteEventArgs; } - public void HandleFinalisedAttachments(IEnumerable attachments) + public void HandleProcessedAttachmentsChunk(IEnumerable attachments) { throw new NotImplementedException(); } diff --git a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs index a15f47e09e..852554361c 100644 --- a/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Client.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationEventsHandlerTests.cs @@ -48,7 +48,7 @@ public void EventsHandlerHandleMultiTestRunFinalizationCompleteShouldSendFinaliz [TestMethod] public void EventsHandlerHandleMultiTestRunFinalizationProgressShouldSendFinalizationProgressMessage() { - var args = new MultiTestRunFinalizationProgressEventArgs(1, new System.Uri("http://www.bing.com/"), 90, 2); + var args = new MultiTestRunFinalizationProgressEventArgs(1, new[] { new System.Uri("http://www.bing.com/") }, 90, 2); handler.HandleMultiTestRunFinalizationProgress(args); diff --git a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs index 0b5c678a8a..a8f7aa866e 100644 --- a/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs +++ b/test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/MultiTestRunFinalization/MultiTestRunFinalizationManagerTests.cs @@ -28,8 +28,8 @@ public class MultiTestRunFinalizationManagerTests private readonly Mock mockRequestData; private readonly Mock mockMetricsCollection; private readonly Mock mockEventSource; - private readonly Mock mockAttachmentHandler1; - private readonly Mock mockAttachmentHandler2; + private readonly Mock mockAttachmentHandler1; + private readonly Mock mockAttachmentHandler2; private readonly Mock mockEventsHandler; private readonly MultiTestRunFinalizationManager manager; private readonly CancellationTokenSource cancellationTokenSource; @@ -41,12 +41,12 @@ public MultiTestRunFinalizationManagerTests() mockRequestData.Setup(r => r.MetricsCollection).Returns(mockMetricsCollection.Object); mockEventSource = new Mock(); - mockAttachmentHandler1 = new Mock(); - mockAttachmentHandler2 = new Mock(); + mockAttachmentHandler1 = new Mock(); + mockAttachmentHandler2 = new Mock(); mockEventsHandler = new Mock(); - mockAttachmentHandler1.Setup(h => h.GetExtensionUri()).Returns(new Uri(uri1)); - mockAttachmentHandler2.Setup(h => h.GetExtensionUri()).Returns(new Uri(uri2)); + mockAttachmentHandler1.Setup(h => h.GetExtensionUris()).Returns(new[] { new Uri(uri1) }); + mockAttachmentHandler2.Setup(h => h.GetExtensionUris()).Returns(new[] { new Uri(uri2) }); manager = new MultiTestRunFinalizationManager(mockEventSource.Object, mockAttachmentHandler1.Object, mockAttachmentHandler2.Object); @@ -69,10 +69,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(0)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(0)); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(0, 0); } @@ -88,10 +88,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnNoAttachments_IfNoAttach // assert Assert.AreEqual(0, result.Count); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(0, 0); } @@ -112,10 +112,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachmentT VerifyCompleteEvent(false, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -135,10 +135,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1NotProcessedAttachment_ // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -157,7 +157,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachments); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); @@ -166,10 +166,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachmentThro VerifyCompleteEvent(false, false, outputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -188,7 +188,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR new AttachmentSet(new Uri(uri1), "uri1_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachments); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachments); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -198,10 +198,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturn1ProcessedAttachment_IfR Assert.IsTrue(result.Contains(outputAttachments[0])); mockEventSource.Verify(s => s.MultiTestRunFinalizationStart(1)); mockEventSource.Verify(s => s.MultiTestRunFinalizationStop(1)); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1); } @@ -215,7 +215,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); @@ -224,10 +224,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug VerifyCompleteEvent(false, true, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "exception message"), Times.Once); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Failed"); } @@ -241,7 +241,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel new AttachmentSet(new Uri(uri1), "uri1_input") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Throws(new Exception("exception message")); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -249,10 +249,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfRel // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Failed"); } @@ -273,10 +273,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug // assert VerifyCompleteEvent(true, false, inputAttachments[0]); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -297,10 +297,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe // assert Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -328,8 +328,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler2); // act await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, mockEventsHandler.Object, cancellationTokenSource.Token); @@ -338,10 +338,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachmentsThro VerifyCompleteEvent(false, false, inputAttachments[4], outputAttachmentsForHandler1.First(), outputAttachmentsForHandler2.First()); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Never); mockEventsHandler.Verify(h => h.HandleLogMessage(It.IsAny(), It.IsAny()), Times.Never); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); VerifyMetrics(5, 3); } @@ -369,8 +369,8 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR new AttachmentSet(new Uri(uri2), "uri2_output") }; - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler1); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns(outputAttachmentsForHandler2); + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler1); + mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).ReturnsAsync(outputAttachmentsForHandler2); // act var result = await manager.FinalizeMultiTestRunAsync(mockRequestData.Object, inputAttachments, cancellationTokenSource.Token); @@ -380,10 +380,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProcessedAttachments_IfR Assert.IsTrue(result.Contains(inputAttachments[4])); Assert.IsTrue(result.Contains(outputAttachmentsForHandler1[0])); Assert.IsTrue(result.Contains(outputAttachmentsForHandler2[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[0]) && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 2 && c.Contains(inputAttachments[2]) && c.Contains(inputAttachments[3])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); VerifyMetrics(5, 3); } @@ -397,14 +397,14 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug new AttachmentSet(new Uri(uri1), "uri1_input") }; - List outputAttachments = new List + ICollection outputAttachments = new List { new AttachmentSet(new Uri(uri1), "uri1_output") }; var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { try { @@ -429,7 +429,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug innerTaskCompletionSource.TrySetResult(null); } - return outputAttachments; + return Task.FromResult(outputAttachments); }); // act @@ -445,10 +445,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachmentsThroug mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 3)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgs(a, 4)))); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "Finalization was cancelled.")); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -462,14 +462,14 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe new AttachmentSet(new Uri(uri1), "uri1_input") }; - List outputAttachments = new List + ICollection outputAttachments = new List { new AttachmentSet(new Uri(uri1), "uri1_output") }; var innerTaskCompletionSource = new TaskCompletionSource(); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress p, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress p, IMessageLogger logger, CancellationToken cancellation) => { try { @@ -493,7 +493,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe innerTaskCompletionSource.TrySetResult(null); } - return outputAttachments; + return Task.FromResult(outputAttachments); }); // act @@ -505,10 +505,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnInitialAttachments_IfOpe Assert.IsNotNull(result); Assert.AreEqual(1, result.Count); Assert.IsTrue(result.Contains(inputAttachments[0])); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri(), Times.Never); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris(), Times.Never); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), cancellationTokenSource.Token)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never); VerifyMetrics(1, 1, "Canceled"); } @@ -523,12 +523,12 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven new AttachmentSet(new Uri(uri2), "uri2_input") }; - List outputAttachments1 = new List + ICollection outputAttachments1 = new List { new AttachmentSet(new Uri(uri1), "uri1_output") }; - List outputAttachments2 = new List + ICollection outputAttachments2 = new List { new AttachmentSet(new Uri(uri2), "uri2_output") }; @@ -545,22 +545,22 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven } }); - mockAttachmentHandler1.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler1.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(25); progress.Report(50); progress.Report(75); logger.SendMessage(TestMessageLevel.Error, "error"); progress.Report(100); - return outputAttachments1; + return Task.FromResult(outputAttachments1); }); - mockAttachmentHandler2.Setup(h => h.HandleDataCollectionAttachmentSets(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => + mockAttachmentHandler2.Setup(h => h.ProcessAttachmentSetsAsync(It.IsAny>(), It.IsAny>(), It.IsAny(), It.IsAny())).Returns((ICollection i1, IProgress progress, IMessageLogger logger, CancellationToken cancellation) => { progress.Report(50); logger.SendMessage(TestMessageLevel.Informational, "info"); progress.Report(100); - return outputAttachments2; + return Task.FromResult(outputAttachments2); }); // act @@ -568,7 +568,7 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven // assert await innerTaskCompletionSource.Task; - VerifyCompleteEvent(false, false, outputAttachments1[0], outputAttachments2[0]); + VerifyCompleteEvent(false, false, outputAttachments1.First(), outputAttachments2.First()); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.IsAny()), Times.Exactly(6)); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 25, uri1)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 50, uri1)))); @@ -576,10 +576,10 @@ public async Task FinalizeMultiTestRunAsync_ShouldReturnProperlySendProgressEven mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 1, 100, uri1)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 50, uri2)))); mockEventsHandler.Verify(h => h.HandleMultiTestRunFinalizationProgress(It.Is(a => VerifyProgressArgsForTwoHandlers(a, 2, 100, uri2)))); - mockAttachmentHandler1.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler2.Verify(h => h.GetExtensionUri()); - mockAttachmentHandler1.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), CancellationToken.None)); - mockAttachmentHandler2.Verify(h => h.HandleDataCollectionAttachmentSets(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), CancellationToken.None)); + mockAttachmentHandler1.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler2.Verify(h => h.GetExtensionUris()); + mockAttachmentHandler1.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[0])), It.IsAny>(), It.IsAny(), CancellationToken.None)); + mockAttachmentHandler2.Verify(h => h.ProcessAttachmentSetsAsync(It.Is>(c => c.Count == 1 && c.Contains(inputAttachments[1])), It.IsAny>(), It.IsAny(), CancellationToken.None)); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Informational, "info")); mockEventsHandler.Verify(h => h.HandleLogMessage(TestMessageLevel.Error, "error")); @@ -607,15 +607,19 @@ private void VerifyCompleteEvent(bool isCanceled, bool containsError, params Att private bool VerifyProgressArgs(MultiTestRunFinalizationProgressEventArgs args, int progress) { - Assert.AreEqual(1, args.CurrentHandlerIndex); - Assert.AreEqual(2, args.HandlersCount); - Assert.AreEqual(uri1, args.CurrentHandlerUri.AbsoluteUri); - return progress == args.CurrentHandlerProgress; + Assert.AreEqual(1, args.CurrentAttachmentProcessorIndex); + Assert.AreEqual(2, args.AttachmentProcessorsCount); + Assert.AreEqual(1, args.CurrentAttachmentProcessorUris.Count); + Assert.AreEqual(uri1, args.CurrentAttachmentProcessorUris.First().AbsoluteUri); + return progress == args.CurrentAttachmentProcessorProgress; } private bool VerifyProgressArgsForTwoHandlers(MultiTestRunFinalizationProgressEventArgs args, long handlerIndex, long progress, string uri) { - return progress == args.CurrentHandlerProgress && args.CurrentHandlerIndex == handlerIndex && args.CurrentHandlerUri.AbsoluteUri == uri && args.HandlersCount == 2; + return progress == args.CurrentAttachmentProcessorProgress && + args.CurrentAttachmentProcessorIndex == handlerIndex && + args.CurrentAttachmentProcessorUris.First().AbsoluteUri == uri && + args.AttachmentProcessorsCount == 2; } } } diff --git a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs index 06a55ac0cb..ff89d295bd 100644 --- a/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs +++ b/test/Microsoft.TestPlatform.Utilities.UnitTests/CodeCoverageDataAttachmentsHandlerTests.cs @@ -1,14 +1,16 @@ namespace Microsoft.TestPlatform.Utilities.UnitTests { - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.Utilities; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading; + using System.Threading.Tasks; + + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.Utilities; + using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class CodeCoverageDataAttachmentsHandlerTests @@ -23,16 +25,16 @@ public CodeCoverageDataAttachmentsHandlerTests() } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachmentsOrAttachmentsAreNull() + public async Task HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachmentsOrAttachmentsAreNull() { Collection attachment = new Collection(); - ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, CancellationToken.None); + ICollection resultAttachmentSets = await + coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); - resultAttachmentSets = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(null, mockProgressReporter.Object, null, CancellationToken.None); + resultAttachmentSets = await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(null, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 0); @@ -41,14 +43,14 @@ public void HandleDataCollectionAttachmentSetsShouldReturnEmptySetWhenNoAttachme } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment() + public async Task HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment() { var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); Collection attachment = new Collection { attachmentSet }; - ICollection resultAttachmentSets = - coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, CancellationToken.None); + ICollection resultAttachmentSets = await + coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, CancellationToken.None); Assert.IsNotNull(resultAttachmentSets); Assert.IsTrue(resultAttachmentSets.Count == 1); @@ -57,7 +59,7 @@ public void HandleDataCollectionAttachmentSetsShouldReturnInputIfOnly1Attachment } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() + public async Task HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested() { var attachmentSet = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); @@ -70,7 +72,7 @@ public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested attachmentSet }; - Assert.ThrowsException(() => coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, cts.Token)); + await Assert.ThrowsExceptionAsync(async () => await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, cts.Token)); Assert.AreEqual(2, attachment.Count); @@ -78,7 +80,7 @@ public void HandleDataCollectionAttachmentSetsShouldThrowIfCancellationRequested } [TestMethod] - public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfFailedToLoadLibrary() + public async Task HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfFailedToLoadLibrary() { var attachmentSet1 = new AttachmentSet(new Uri("//badrui//"), string.Empty); attachmentSet1.Attachments.Add(new UriDataAttachment(new Uri("C:\\temp\\aa"), "coverage")); @@ -94,7 +96,7 @@ public void HandleDataCollectionAttachmentSetsShouldReturnExistingAttachmentsIfF attachmentSet2 }; - var result = coverageDataAttachmentsHandler.HandleDataCollectionAttachmentSets(attachment, mockProgressReporter.Object, null, cts.Token); + var result = await coverageDataAttachmentsHandler.ProcessAttachmentSetsAsync(attachment, mockProgressReporter.Object, null, cts.Token); Assert.AreEqual(2, result.Count); Assert.IsTrue(result.Contains(attachmentSet1)); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs index d23c9b84e4..b90aabfbc8 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleRequestSenderTests.cs @@ -2005,7 +2005,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage var progressPayload = new MultiTestRunFinalizationProgressPayload() { - FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, new System.Uri("http://www.bing.com/"), 50, 2) + FinalizationProgressEventArgs = new MultiTestRunFinalizationProgressEventArgs(1, new[] { new Uri("http://www.bing.com/") }, 50, 2) }; var finalizationProgress = new Message() @@ -2023,7 +2023,7 @@ public async Task FinalizeTestsShouldCompleteWithOneAttachmentAndProgressMessage mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationStart, It.IsAny())); mockCommunicationManager.Verify(c => c.SendMessage(MessageType.MultiTestRunFinalizationCancel), Times.Never); mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationComplete(It.IsAny(), It.Is>(a => a.Count == 1)), Times.Once, "Finalization Complete must be called"); - mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentHandlerIndex == 1 && a.CurrentHandlerUri == new System.Uri("http://www.bing.com/") && a.CurrentHandlerProgress == 50 && a.HandlersCount == 2)), Times.Once, "Finalization Progress must be called"); + mockHandler.Verify(mh => mh.HandleMultiTestRunFinalizationProgress(It.Is(a => a.CurrentAttachmentProcessorIndex == 1 && a.CurrentAttachmentProcessorUris.First() == new Uri("http://www.bing.com/") && a.CurrentAttachmentProcessorProgress == 50 && a.AttachmentProcessorsCount == 2)), Times.Once, "Finalization Progress must be called"); mockHandler.Verify(mh => mh.HandleLogMessage(TestMessageLevel.Informational, "Hello"), Times.Never); } diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs index 67b2010580..302302f9d5 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperAsyncTests.cs @@ -318,6 +318,7 @@ public async Task FinalizeMultiTestRunAsyncShouldSucceed() await this.consoleWrapper.FinalizeMultiTestRunAsync( attachments, true, + true, new Mock().Object, cancellationToken); diff --git a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs index b27f781ba1..5f3f099a76 100644 --- a/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs +++ b/test/TranslationLayer.UnitTests/VsTestConsoleWrapperTests.cs @@ -316,6 +316,7 @@ public async Task FinalizeMultiTestRunAsyncShouldSucceed() await this.consoleWrapper.FinalizeMultiTestRunAsync( attachments, true, + true, new Mock().Object, cancellationToken);