diff --git a/FineCodeCoverageTests/TestContainerDiscovery_Tests.cs b/FineCodeCoverageTests/TestContainerDiscovery_Tests.cs index 80cb96e..57bc602 100644 --- a/FineCodeCoverageTests/TestContainerDiscovery_Tests.cs +++ b/FineCodeCoverageTests/TestContainerDiscovery_Tests.cs @@ -10,9 +10,11 @@ using FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage; using FineCodeCoverage.Impl; using FineCodeCoverage.Options; +using Microsoft.Build.Evaluation; using Microsoft.VisualStudio.TestWindow.Extensibility; using Moq; using NUnit.Framework; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace Test { @@ -260,10 +262,12 @@ public void Should_Collect_Ms_Code_Coverage_When_TestExecutionFinished_And_Ms_Co mockTestOperationFactory.Setup(testOperationFactory => testOperationFactory.Create(operation)).Returns(testOperation); RaiseTestExecutionFinished(operation); +#pragma warning disable VSTHRD110 // Observe result of async calls mocker.Verify( msCodeCoverageRunSettingsService => msCodeCoverageRunSettingsService.CollectAsync(operation,testOperation) ); +#pragma warning restore VSTHRD110 // Observe result of async calls } [Test] @@ -401,5 +405,29 @@ public void Should_Send_TestExecutionStartingMessage_When_TestExecutionStarting( RaiseTestExecutionStarting(operation); mocker.Verify(eventAggregator => eventAggregator.SendMessage(It.IsAny(),null)); } + + [Test] + public void Should_MsCodeCoverageRunSettingsService_TestExecutionNotFinishedAsync_When_IsCollecting_TestExecutionFinishedAsync_And_CollectAsync_Not_Called() + { + var mockMsCodeCoverageRunSettingsService = mocker.GetMock(); + mockMsCodeCoverageRunSettingsService.Setup( + msCodeCoverageRunSettingsService => + msCodeCoverageRunSettingsService.IsCollectingAsync(It.IsAny()) + ).ReturnsAsync(MsCodeCoverageCollectionStatus.Collecting); + + SetUpOptions(mockOptions => + { + mockOptions.Setup(options => options.Enabled).Returns(true); + mockOptions.Setup(options => options.RunWhenTestsFail).Returns(false); + }); + var mockTestOperation = new Mock(); + mockTestOperation.SetupGet(testOperation => testOperation.FailedTests).Returns(1); + mocker.GetMock().Setup(f => f.Create(It.IsAny())).Returns(mockTestOperation.Object); + RaiseTestExecutionStarting(); + RaiseTestExecutionFinished(); + + mockMsCodeCoverageRunSettingsService.Verify(msCodeCoverageRunSettingsService => msCodeCoverageRunSettingsService.TestExecutionNotFinishedAsync(mockTestOperation.Object)); + + } } } \ No newline at end of file diff --git a/SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs b/SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs index 91f6535..cee62a9 100644 --- a/SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs +++ b/SharedProject/Impl/TestContainerDiscovery/TestContainerDiscoverer.cs @@ -141,6 +141,13 @@ private async Task TestExecutionFinishedAsync(IOperation operation) { await TestExecutionFinishedCollectionAsync(operation, testOperation); } + else + { + if (msCodeCoverageCollectionStatus == MsCodeCoverageCollectionStatus.Collecting) + { + await msCodeCoverageRunSettingsService.TestExecutionNotFinishedAsync(testOperation); + } + } } private (bool should, ITestOperation testOperation) ShouldConditionallyCollectWhenTestExecutionFinished(IOperation operation)