-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...form.CrossPlatEngine.UnitTests/DataCollection/ParallelDataCollectionEventsHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// 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.TestPlatform.CrossPlatEngine.UnitTests.DataCollection | ||
{ | ||
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.Parallel; | ||
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client; | ||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Engine; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
[TestClass] | ||
public class ParallelDataCollectionEventsHandlerTests | ||
{ | ||
private const string uri1 = "datacollector://microsoft/some1/1.0"; | ||
private const string uri2 = "datacollector://microsoft/some2/2.0"; | ||
private const string uri3 = "datacollector://microsoft/some3/2.0"; | ||
|
||
private readonly Mock<IRequestData> mockRequestData; | ||
private readonly Mock<IProxyExecutionManager> mockProxyExecutionManager; | ||
private readonly Mock<ITestRunEventsHandler> mockTestRunEventsHandler; | ||
private readonly Mock<IParallelProxyExecutionManager> mockParallelProxyExecutionManager; | ||
private readonly Mock<IMultiTestRunFinalizationManager> mockMultiTestRunFinalizationManager; | ||
private readonly CancellationTokenSource cancellationTokenSource; | ||
private readonly ParallelDataCollectionEventsHandler parallelDataCollectionEventsHandler; | ||
|
||
public ParallelDataCollectionEventsHandlerTests() | ||
{ | ||
mockRequestData = new Mock<IRequestData>(); | ||
mockProxyExecutionManager = new Mock<IProxyExecutionManager>(); | ||
mockTestRunEventsHandler = new Mock<ITestRunEventsHandler>(); | ||
mockParallelProxyExecutionManager = new Mock<IParallelProxyExecutionManager>(); | ||
mockMultiTestRunFinalizationManager = new Mock<IMultiTestRunFinalizationManager>(); | ||
cancellationTokenSource = new CancellationTokenSource(); | ||
parallelDataCollectionEventsHandler = new ParallelDataCollectionEventsHandler(mockRequestData.Object, mockProxyExecutionManager.Object, mockTestRunEventsHandler.Object, | ||
mockParallelProxyExecutionManager.Object, new ParallelRunDataAggregator(), mockMultiTestRunFinalizationManager.Object, cancellationTokenSource.Token); | ||
|
||
mockParallelProxyExecutionManager.Setup(m => m.HandlePartialRunComplete(It.IsAny<IProxyExecutionManager>(), It.IsAny<TestRunCompleteEventArgs>(), It.IsAny<TestRunChangedEventArgs>(), It.IsAny<ICollection<AttachmentSet>>(), It.IsAny<ICollection<string>>())).Returns(true); | ||
} | ||
|
||
[TestMethod] | ||
public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndUseResults() | ||
{ | ||
// arrange | ||
List<AttachmentSet> inputAttachments = new List<AttachmentSet> | ||
{ | ||
new AttachmentSet(new Uri(uri1), "uri1_input1"), | ||
new AttachmentSet(new Uri(uri2), "uri2_input1"), | ||
new AttachmentSet(new Uri(uri3), "uri3_input1") | ||
}; | ||
|
||
Collection<AttachmentSet> outputAttachments = new Collection<AttachmentSet> | ||
{ | ||
new AttachmentSet(new Uri(uri1), "uri1_input1") | ||
}; | ||
|
||
mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(It.IsAny<ICollection<AttachmentSet>>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult(outputAttachments)); | ||
|
||
// act | ||
parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); | ||
|
||
// assert | ||
mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny<TestRunCompleteEventArgs>(), It.IsAny<TestRunChangedEventArgs>(), It.Is<ICollection<AttachmentSet>>(c => c.Count == 1 && c.Contains(outputAttachments[0])), It.IsAny<ICollection<string>>())); | ||
mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(It.Is<ICollection<AttachmentSet>>(a => a.Count == 3), cancellationTokenSource.Token)); | ||
} | ||
|
||
[TestMethod] | ||
public void HandleTestRunComplete_ShouldCallFinalizerWithAttachmentsAndNotUserResults_IfFinalizerReturnsNull() | ||
{ | ||
// arrange | ||
List<AttachmentSet> inputAttachments = new List<AttachmentSet> | ||
{ | ||
new AttachmentSet(new Uri(uri1), "uri1_input1"), | ||
new AttachmentSet(new Uri(uri2), "uri2_input1"), | ||
new AttachmentSet(new Uri(uri3), "uri3_input1") | ||
}; | ||
|
||
mockMultiTestRunFinalizationManager.Setup(f => f.FinalizeMultiTestRunAsync(It.IsAny<ICollection<AttachmentSet>>(), It.IsAny<CancellationToken>())).Returns(Task.FromResult((Collection<AttachmentSet>)null)); | ||
|
||
// act | ||
parallelDataCollectionEventsHandler.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, TimeSpan.FromSeconds(1)), null, inputAttachments, null); | ||
|
||
// assert | ||
mockTestRunEventsHandler.Verify(h => h.HandleTestRunComplete(It.IsAny<TestRunCompleteEventArgs>(), It.IsAny<TestRunChangedEventArgs>(), It.Is<ICollection<AttachmentSet>>(c => c.Count == 3), It.IsAny<ICollection<string>>())); | ||
mockMultiTestRunFinalizationManager.Verify(f => f.FinalizeMultiTestRunAsync(It.Is<ICollection<AttachmentSet>>(a => a.Count == 3), cancellationTokenSource.Token)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters