Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyhallett committed Jul 25, 2024
1 parent 62e260f commit fab9b74
Showing 1 changed file with 28 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));

}
}
}

0 comments on commit fab9b74

Please sign in to comment.