Skip to content

Commit

Permalink
Merge pull request #443 from tonyhallett/fix-runsettings-projectfile-…
Browse files Browse the repository at this point in the history
…cleanup

Fix runsettings projectfile cleanup
  • Loading branch information
tonyhallett authored Jul 25, 2024
2 parents aab53e4 + fab9b74 commit 860a295
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions FineCodeCoverageTests/TestContainerDiscovery_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<IMsCodeCoverageRunSettingsService>(
msCodeCoverageRunSettingsService =>
msCodeCoverageRunSettingsService.CollectAsync(operation,testOperation)
);
#pragma warning restore VSTHRD110 // Observe result of async calls
}

[Test]
Expand Down Expand Up @@ -401,5 +405,29 @@ public void Should_Send_TestExecutionStartingMessage_When_TestExecutionStarting(
RaiseTestExecutionStarting(operation);
mocker.Verify<IEventAggregator>(eventAggregator => eventAggregator.SendMessage(It.IsAny<TestExecutionStartingMessage>(),null));
}

[Test]
public void Should_MsCodeCoverageRunSettingsService_TestExecutionNotFinishedAsync_When_IsCollecting_TestExecutionFinishedAsync_And_CollectAsync_Not_Called()
{
var mockMsCodeCoverageRunSettingsService = mocker.GetMock<IMsCodeCoverageRunSettingsService>();
mockMsCodeCoverageRunSettingsService.Setup(
msCodeCoverageRunSettingsService =>
msCodeCoverageRunSettingsService.IsCollectingAsync(It.IsAny<ITestOperation>())
).ReturnsAsync(MsCodeCoverageCollectionStatus.Collecting);

SetUpOptions(mockOptions =>
{
mockOptions.Setup(options => options.Enabled).Returns(true);
mockOptions.Setup(options => options.RunWhenTestsFail).Returns(false);
});
var mockTestOperation = new Mock<ITestOperation>();
mockTestOperation.SetupGet(testOperation => testOperation.FailedTests).Returns(1);
mocker.GetMock<ITestOperationFactory>().Setup(f => f.Create(It.IsAny<IOperation>())).Returns(mockTestOperation.Object);
RaiseTestExecutionStarting();
RaiseTestExecutionFinished();

mockMsCodeCoverageRunSettingsService.Verify(msCodeCoverageRunSettingsService => msCodeCoverageRunSettingsService.TestExecutionNotFinishedAsync(mockTestOperation.Object));

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 860a295

Please sign in to comment.