From 62e260fdada5afbf02970ef0d8d2511a573d5c46 Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Thu, 25 Jul 2024 13:37:44 +0100 Subject: [PATCH 1/2] clean up when ms code coverage does not collect --- .../Impl/TestContainerDiscovery/TestContainerDiscoverer.cs | 7 +++++++ 1 file changed, 7 insertions(+) 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) From fab9b745abf2a90d686e29b16f0828cd7df75cd8 Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Thu, 25 Jul 2024 13:56:00 +0100 Subject: [PATCH 2/2] add test --- .../TestContainerDiscovery_Tests.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) 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