diff --git a/FineCodeCoverage/FineCodeCoverage.csproj b/FineCodeCoverage/FineCodeCoverage.csproj
index df4d01ad..ad9ac972 100644
--- a/FineCodeCoverage/FineCodeCoverage.csproj
+++ b/FineCodeCoverage/FineCodeCoverage.csproj
@@ -189,6 +189,9 @@
13.0.1
+
+ 3.13.1
+
1.0.0
diff --git a/FineCodeCoverageTests/AppOptionsProvider_Tests.cs b/FineCodeCoverageTests/AppOptionsProvider_Tests.cs
index dce37834..8dabaec3 100644
--- a/FineCodeCoverageTests/AppOptionsProvider_Tests.cs
+++ b/FineCodeCoverageTests/AppOptionsProvider_Tests.cs
@@ -349,7 +349,8 @@ internal void Should_Use_Deseralized_String_From_Store_For_AppOption_Property(Fu
{nameof(IAppOptions.ShowLineNewHighlighting),true },
{nameof(IAppOptions.ShowLineNotIncludedHighlighting),true },
{nameof(IAppOptions.UseEnterpriseFontsAndColors),true },
- {nameof(IAppOptions.EditorCoverageColouringMode), EditorCoverageColouringMode.UseRoslynWhenTextChanges }
+ {nameof(IAppOptions.EditorCoverageColouringMode), EditorCoverageColouringMode.UseRoslynWhenTextChanges },
+ {nameof(IAppOptions.BlazorCoverageLinesFromGeneratedSource), true }
};
var mockJsonConvertService = autoMocker.GetMock();
mockJsonConvertService.Setup(
diff --git a/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorCoverageContentType_Tests.cs b/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorCoverageContentType_Tests.cs
new file mode 100644
index 00000000..b525ef65
--- /dev/null
+++ b/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorCoverageContentType_Tests.cs
@@ -0,0 +1,75 @@
+using FineCodeCoverage.Editor.DynamicCoverage.ContentTypes.Blazor;
+using FineCodeCoverage.Options;
+using Moq;
+using NUnit.Framework;
+
+namespace FineCodeCoverageTests.Editor.DynamicCoverage
+{
+ internal class BlazorCoverageContentType_Tests
+ {
+ [TestCase("path.razor",false)]
+ [TestCase("path.cshtml", true)]
+ [TestCase("path.vbhtml", true)]
+ public void Should_Include_Razor_Component_Files(string filePath, bool expectedExclude)
+ {
+ Assert.That(new BlazorCoverageContentType(null, null).Exclude(filePath), Is.EqualTo(expectedExclude));
+ }
+
+ [Test]
+ public void Should_Line_Exclude_HtmlTags()
+ {
+ var lineExcluder = new BlazorCoverageContentType(null, null).LineExcluder;
+ Assert.True(lineExcluder.ExcludeIfNotCode("<"));
+ }
+
+ [Test]
+ public void Should_Line_Exclude_Directives()
+ {
+ var lineExcluder = new BlazorCoverageContentType(null, null).LineExcluder;
+ Assert.True(lineExcluder.ExcludeIfNotCode("@"));
+ }
+
+ [Test]
+ public void Should_Line_Exclude_Comments()
+ {
+ var lineExcluder = new BlazorCoverageContentType(null, null).LineExcluder;
+ Assert.True(lineExcluder.ExcludeIfNotCode("//"));
+ }
+
+ [Test]
+ public void Should_Line_Exclude_Compiler_Directives()
+ {
+ var lineExcluder = new BlazorCoverageContentType(null, null).LineExcluder;
+ Assert.True(lineExcluder.ExcludeIfNotCode("#"));
+ }
+
+ [Test]
+ public void Should_Not_UseFileCodeSpanRangeServiceForChanges()
+ {
+ Assert.False(new BlazorCoverageContentType(null, null).UseFileCodeSpanRangeServiceForChanges);
+ }
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Should_CoverageFromFileCodeSpanRangeService_From_AppOptions(bool blazorCoverageLinesFromGeneratedSource)
+ {
+ var mockAppOptionsProvider = new Mock();
+ mockAppOptionsProvider.Setup(a => a.Get()).Returns(new AppOptions { BlazorCoverageLinesFromGeneratedSource = blazorCoverageLinesFromGeneratedSource });
+ Assert.That(new BlazorCoverageContentType(null, mockAppOptionsProvider.Object).CoverageOnlyFromFileCodeSpanRangeService, Is.EqualTo(blazorCoverageLinesFromGeneratedSource));
+ }
+
+ [Test]
+ public void Should_Use_BlazorFileCodeSpanRangeService()
+ {
+ var blazorFileCodeSpanRangeService = new Mock().Object;
+ Assert.That(blazorFileCodeSpanRangeService, Is.SameAs(new BlazorCoverageContentType(blazorFileCodeSpanRangeService, null).FileCodeSpanRangeService));
+ }
+
+ [Test]
+ public void Should_Be_For_The_Razor_ContentType()
+ {
+ Assert.That("Razor", Is.EqualTo(new BlazorCoverageContentType(null, null).ContentTypeName));
+ }
+
+ }
+}
diff --git a/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorFileCodeSpanRangeService_Tests.cs b/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorFileCodeSpanRangeService_Tests.cs
new file mode 100644
index 00000000..725f6e09
--- /dev/null
+++ b/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorFileCodeSpanRangeService_Tests.cs
@@ -0,0 +1,118 @@
+using System.Collections.Generic;
+using System.Linq;
+using AutoMoq;
+using FineCodeCoverage.Core.Utilities.VsThreading;
+using FineCodeCoverage.Editor.DynamicCoverage;
+using FineCodeCoverage.Editor.DynamicCoverage.ContentTypes.Blazor;
+using FineCodeCoverage.Editor.DynamicCoverage.Utilities;
+using FineCodeCoverage.Editor.Roslyn;
+using FineCodeCoverageTests.TestHelpers;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.Text;
+using Microsoft.VisualStudio.Text;
+using Moq;
+using NUnit.Framework;
+
+namespace FineCodeCoverageTests.Editor.DynamicCoverage
+{
+ internal class BlazorFileCodeSpanRangeService_Tests
+ {
+ [Test]
+ public void Should_Return_Null_If_Cannot_Find_Syntax_Root_Of_Generated_Document()
+ {
+ var mockTextSnapshot = new Mock();
+ var mockTextBuffer = new Mock();
+ mockTextSnapshot.SetupGet(textSnapshot => textSnapshot.TextBuffer).Returns(mockTextBuffer.Object);
+
+ var autoMoqer = new AutoMoqer();
+ var razorGeneratedFilePathMatcher = autoMoqer.GetMock().Object;
+ autoMoqer.SetInstance(new TestThreadHelper());
+ autoMoqer.GetMock().Setup(t => t.GetFilePath(mockTextBuffer.Object)).Returns("path");
+
+ var mockRazorGeneratedDocumentRootFinder = autoMoqer.GetMock();
+ mockRazorGeneratedDocumentRootFinder.Setup(
+ razorGeneratedDocumentootFinder => razorGeneratedDocumentootFinder.FindSyntaxRootAsync(mockTextBuffer.Object, "path", razorGeneratedFilePathMatcher)
+ ).ReturnsAsync((SyntaxNode)null);
+
+ var fileCodeSpanRanges = autoMoqer.Create().GetFileCodeSpanRanges(mockTextSnapshot.Object);
+
+ Assert.IsNull(fileCodeSpanRanges);
+ mockRazorGeneratedDocumentRootFinder.VerifyAll();
+ }
+
+ [Test]
+ public void Should_Return_Null_If_Generated_Document_Has_No_Code_Nodes()
+ {
+ var mockTextSnapshot = new Mock();
+ var mockTextBuffer = new Mock();
+ mockTextSnapshot.SetupGet(textSnapshot => textSnapshot.TextBuffer).Returns(mockTextBuffer.Object);
+
+ var autoMoqer = new AutoMoqer();
+ var mockCSharpCodeCoverageNodeVisitor = autoMoqer.GetMock();
+ mockCSharpCodeCoverageNodeVisitor.Setup(cSharpCodeCoverageNodeVisitor => cSharpCodeCoverageNodeVisitor.GetNodes(It.IsAny()))
+ .Returns(new List());
+ var razorGeneratedFilePathMatcher = autoMoqer.GetMock().Object;
+ autoMoqer.SetInstance(new TestThreadHelper());
+ autoMoqer.GetMock().Setup(t => t.GetFilePath(mockTextBuffer.Object)).Returns("path");
+
+ var rootNode = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);
+ var mockRazorGeneratedDocumentRootFinder = autoMoqer.GetMock();
+ mockRazorGeneratedDocumentRootFinder.Setup(
+ razorGeneratedDocumentootFinder => razorGeneratedDocumentootFinder.FindSyntaxRootAsync(mockTextBuffer.Object, "path", razorGeneratedFilePathMatcher)
+ ).ReturnsAsync(rootNode);
+
+ var fileCodeSpanRanges = autoMoqer.Create().GetFileCodeSpanRanges(mockTextSnapshot.Object);
+
+ Assert.IsNull(fileCodeSpanRanges);
+
+ mockCSharpCodeCoverageNodeVisitor.VerifyAll();
+ }
+
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Should_Use_The_Generated_Coverage_Syntax_Nodes_Mapped_To_Razor_File_For_The_CodeSpanRange(
+ bool firstMapsBack
+ )
+ {
+ var mockTextSnapshot = new Mock();
+ var mockTextBuffer = new Mock();
+ mockTextSnapshot.SetupGet(textSnapshot => textSnapshot.TextBuffer).Returns(mockTextBuffer.Object);
+
+ var autoMoqer = new AutoMoqer();
+ var razorGeneratedFilePathMatcher = autoMoqer.GetMock().Object;
+ autoMoqer.SetInstance(new TestThreadHelper());
+ autoMoqer.GetMock().Setup(t => t.GetFilePath(mockTextBuffer.Object)).Returns("path");
+
+ var mockRazorGeneratedDocumentRootFinder = autoMoqer.GetMock();
+ SyntaxNode rootSyntaxNode = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);
+ SyntaxNode codeCoverageNode1 = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);
+ SyntaxNode codeCoverageNode2 = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration);
+ mockRazorGeneratedDocumentRootFinder.Setup(
+ razorGeneratedDocumentootFinder => razorGeneratedDocumentootFinder.FindSyntaxRootAsync(mockTextBuffer.Object, "path", razorGeneratedFilePathMatcher)
+ ).ReturnsAsync(rootSyntaxNode);
+
+ var mockCSharpCodeCoverageNodeVisitor = autoMoqer.GetMock();
+ mockCSharpCodeCoverageNodeVisitor.Setup(cSharpCodeCoverageNodeVisitor => cSharpCodeCoverageNodeVisitor.GetNodes(rootSyntaxNode))
+ .Returns(new List { codeCoverageNode1, codeCoverageNode2 });
+ var mockSyntaxNodeLocationMapper = autoMoqer.GetMock();
+
+ var linePositionSpan1 = new LinePositionSpan(new LinePosition(1, 1), new LinePosition(2, 1));
+ var fileLinePositionSpan1 = new FileLinePositionSpan(firstMapsBack ? "path" : "",linePositionSpan1);
+ var linePositionSpan2 = new LinePositionSpan(new LinePosition(3, 1), new LinePosition(4, 1));
+ var fileLinePositionSpan2 = new FileLinePositionSpan(firstMapsBack ? "" : "path", linePositionSpan2);
+ var expectedCodeSpanRange = firstMapsBack ? new CodeSpanRange(1, 2) : new CodeSpanRange(3, 4);
+
+ mockSyntaxNodeLocationMapper.Setup(syntaxNodeLocationMapper => syntaxNodeLocationMapper.Map(codeCoverageNode1))
+ .Returns(fileLinePositionSpan1);
+ mockSyntaxNodeLocationMapper.Setup(syntaxNodeLocationMapper => syntaxNodeLocationMapper.Map(codeCoverageNode2))
+ .Returns(fileLinePositionSpan2);
+
+
+ var fileCodeSpanRanges = autoMoqer.Create().GetFileCodeSpanRanges(mockTextSnapshot.Object);
+ var fileCodeSpanRange = fileCodeSpanRanges.Single();
+
+ Assert.That(expectedCodeSpanRange, Is.EqualTo(fileCodeSpanRange));
+ }
+ }
+}
diff --git a/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorGeneratedFilePathMatcher_Tests.cs b/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorGeneratedFilePathMatcher_Tests.cs
new file mode 100644
index 00000000..cdc52a9e
--- /dev/null
+++ b/FineCodeCoverageTests/Editor/DynamicCoverage/BlazorGeneratedFilePathMatcher_Tests.cs
@@ -0,0 +1,21 @@
+using FineCodeCoverage.Editor.DynamicCoverage.ContentTypes.Blazor;
+using NUnit.Framework;
+
+namespace FineCodeCoverageTests.Editor.DynamicCoverage
+{
+ internal class BlazorGeneratedFilePathMatcher_Tests
+ {
+ [TestCase("razorpath","razorpath.",true)]
+ [TestCase("razorpath", "razorpathx.", false)]
+ public void Should_Be_Generated_If_File_Path_Starts_With_Razor_Path_And_Dot(
+ string razorFilePath,
+ string generatedFilePath,
+ bool expectedIsGenerated
+ )
+ {
+ var isGenerated = new BlazorGeneratedFilePathMatcher().IsBlazorGeneratedFilePath(razorFilePath, generatedFilePath);
+
+ Assert.That(expectedIsGenerated, Is.EqualTo(isGenerated));
+ }
+ }
+}
diff --git a/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs b/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs
index 1175fdf0..51498c58 100644
--- a/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs
+++ b/FineCodeCoverageTests/Editor/DynamicCoverage/BufferLineCoverage_Tests.cs
@@ -1,9 +1,9 @@
using AutoMoq;
using FineCodeCoverage.Core.Utilities;
using FineCodeCoverage.Editor.DynamicCoverage;
-using FineCodeCoverage.Editor.Tagging.Base;
using FineCodeCoverage.Engine;
using FineCodeCoverage.Engine.Model;
+using FineCodeCoverage.Impl;
using FineCodeCoverage.Options;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
@@ -12,6 +12,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Threading;
namespace FineCodeCoverageTests.Editor.DynamicCoverage
{
@@ -27,8 +28,8 @@ internal class BufferLineCoverage_Tests
private Mock mockTextBuffer;
private Mock mockTextView;
private ITextSnapshot textSnapshot;
- private ITextInfo textInfo;
- private Mock mockAppOptions;
+ private Mock mockTextInfo;
+ private readonly string filePath = "filepath";
private ILine CreateLine()
{
@@ -37,249 +38,470 @@ private ILine CreateLine()
mockLine.SetupGet(line => line.CoverageType).Returns(CoverageType.Partial);
return mockLine.Object;
}
+
+ private IAppOptions CreateAppOptions(bool off)
+ {
+ var mockAppOptions = new Mock();
+ mockAppOptions.SetupGet(appOptions => appOptions.EditorCoverageColouringMode)
+ .Returns(off ? EditorCoverageColouringMode.Off : EditorCoverageColouringMode.UseRoslynWhenTextChanges);
+ return mockAppOptions.Object;
+ }
+
private void SetupEditorCoverageColouringMode(AutoMoqer autoMoqer,bool off = false)
{
- mockAppOptions = new Mock();
- mockAppOptions.SetupGet(appOptions => appOptions.EditorCoverageColouringMode).Returns(off ? EditorCoverageColouringMode.Off : EditorCoverageColouringMode.UseRoslynWhenTextChanges);
- autoMoqer.Setup(appOptionsProvider => appOptionsProvider.Get()).Returns(mockAppOptions.Object);
+ autoMoqer.Setup(appOptionsProvider => appOptionsProvider.Get())
+ .Returns(CreateAppOptions(off));
}
- private void SimpleTextInfoSetUp(bool editorCoverageOff = false,string contentTypeName = "CSharp")
+
+ private void MockTextInfo(Mock mockTextInfo)
{
- autoMoqer = new AutoMoqer();
- SetupEditorCoverageColouringMode(autoMoqer, editorCoverageOff);
+ this.mockTextInfo = mockTextInfo;
mockTextView = new Mock();
mockTextBuffer = new Mock();
- mockTextBuffer.Setup(textBuffer => textBuffer.ContentType.TypeName).Returns(contentTypeName);
mockTextSnapshot = new Mock();
textSnapshot = mockTextSnapshot.Object;
mockTextBuffer.Setup(textBuffer => textBuffer.CurrentSnapshot).Returns(textSnapshot);
- var mockTextInfo = new Mock();
mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer).Returns(mockTextBuffer.Object);
mockTextInfo.SetupGet(textInfo => textInfo.TextView).Returns(mockTextView.Object);
- mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns("filepath");
- textInfo = mockTextInfo.Object;
- autoMoqer.SetInstance(textInfo);
+ mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns(filePath);
}
- [TestCase("CSharp", Language.CSharp)]
- [TestCase("Basic", Language.VB)]
- [TestCase("C/C++", Language.CPP)]
- public void Should_Create_Tracked_Lines_From_Existing_Coverage_Based_Upon_The_Content_Type_Language(string contentTypeName, Language expectedLanguage)
+ private void SimpleSetUp(bool editorCoverageOff)
{
- SimpleTextInfoSetUp(false,contentTypeName);
+ autoMoqer = new AutoMoqer();
+ SetupEditorCoverageColouringMode(autoMoqer, editorCoverageOff);
+ MockTextInfo(autoMoqer.GetMock());
+ }
- var lines = new List { CreateLine()};
- var mockFileLineCoverage = autoMoqer.GetMock();
- mockFileLineCoverage.Setup(fileLineCoverage => fileLineCoverage.GetLines("filepath")).Returns(lines);
+ private void AddLastFileLineCoverage(Mock mockFileLineCoverage)
+ {
+ autoMoqer.GetMock()
+ .SetupGet(lastCoverage => lastCoverage.FileLineCoverage)
+ .Returns(mockFileLineCoverage.Object);
+ }
+ private BufferLineCoverage SetupNoInitialTrackedLines()
+ {
+ SimpleSetUp(false);
var bufferLineCoverage = autoMoqer.Create();
-
- autoMoqer.Verify(trackedLinesFactory => trackedLinesFactory.Create(lines, textSnapshot, expectedLanguage));
+ Assert.Null(bufferLineCoverage.TrackedLines);
+ return bufferLineCoverage;
}
[Test]
- public void Should_Not_Create_TrackedLines_If_EditorCoverageColouringMode_Is_Off()
+ public void Should_Add_Itself_As_A_Listener()
{
- SimpleTextInfoSetUp(true);
+ SimpleSetUp(true);
var bufferLineCoverage = autoMoqer.Create();
- autoMoqer.Verify(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never());
+ autoMoqer.Verify(eventAggregator => eventAggregator.AddListener(bufferLineCoverage, null));
}
[Test]
- public void Should_Not_Create_TrackedLines_From_NewCoverageLinesMessage_If_EditorCoverageColouringMode_Is_Off()
+ public void Should_Stop_Listening_When_TextView_Closed()
{
- SimpleTextInfoSetUp(true);
+ SimpleSetUp(true);
var bufferLineCoverage = autoMoqer.Create();
+ mockTextView.Setup(textView => textView.TextSnapshot.GetText()).Returns("");
+ mockTextView.Raise(textView => textView.Closed += null, EventArgs.Empty);
+
+ autoMoqer.Verify(eventAggregator => eventAggregator.RemoveListener(bufferLineCoverage));
+ mockTextView.VerifyRemove(textView => textView.Closed -= It.IsAny(), Times.Once);
+ mockTextBuffer.VerifyRemove(textBuffer => textBuffer.Changed -= It.IsAny>(), Times.Once);
+ var mockAppOptionsProvider = autoMoqer.GetMock();
+ mockAppOptionsProvider.VerifyRemove(appOptionsProvider => appOptionsProvider.OptionsChanged -= It.IsAny>(), Times.Once);
+ }
+
+ [Test]
+ public void Should_Delegate_GetLines_To_Tracked_Lines()
+ {
+ SimpleSetUp(false);
+ var mockTrackedLines = new Mock();
+ var dynamicLines = new List { new Mock().Object };
+ mockTrackedLines.Setup(trackedLines => trackedLines.GetLines(0, 5)).Returns(dynamicLines);
- var newCoverageLinesMessage = new NewCoverageLinesMessage { CoverageLines = new Mock().Object };
- bufferLineCoverage.Handle(newCoverageLinesMessage);
+ var bufferLineCoverage = autoMoqer.Create();
+ bufferLineCoverage.TrackedLines = mockTrackedLines.Object;
- autoMoqer.Verify(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()), Times.Never());
+ Assert.That(bufferLineCoverage.GetLines(0, 5), Is.SameAs(dynamicLines));
}
[Test]
- public void Should_Not_Throw_If_No_Initial_Coverage()
+ public void Should_Return_Empty_Enumerable_If_No_Tracked_Lines()
{
- SimpleTextInfoSetUp();
-
- new BufferLineCoverage(null, textInfo, new Mock().Object, null, null,new Mock().Object);
+ SimpleSetUp(false);
+
+ var bufferLineCoverage = autoMoqer.Create();
+
+ Assert.IsEmpty(bufferLineCoverage.GetLines(0, 5).ToList());
}
+ #region creating from existing coverage when file opens
+
[Test]
- public void GetLines_Should_Delegate_To_TrackedLines()
+ public void Should_Create_TrackedLines_From_Serialized_Coverage_If_Present_And_Not_Out_Of_Date()
{
- SimpleTextInfoSetUp();
+ SimpleSetUp(false);
- var mockTrackedLines = new Mock();
- var lines = new List();
- mockTrackedLines.Setup(trackedLines => trackedLines.GetLines(2, 5)).Returns(lines);
+ DateTime lastWriteDate = new DateTime(2024, 5, 8);
+ DateTime textExecutionStartingDate = new DateTime(2024, 5, 10);
+ DateTime serializedDate = new DateTime(2024, 5, 8);
+
+ mockTextInfo.Setup(textInfo => textInfo.GetLastWriteTime()).Returns(lastWriteDate);
+ var mockLastCoverage = autoMoqer.GetMock();
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.TestExecutionStartingDate).Returns(textExecutionStartingDate);
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.FileLineCoverage).Returns(new Mock().Object);
+ autoMoqer.Setup(dynamicCoverageStore => dynamicCoverageStore.GetSerializedCoverage(filePath))
+ .Returns(new SerializedCoverageWhen { Serialized = "serialized", When = serializedDate });
+
+ var trackedLinesFromSerialized = new Mock().Object;
autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()))
- .Returns(mockTrackedLines.Object);
+ trackedLinesFactory => trackedLinesFactory.Create("serialized", textSnapshot, filePath)
+ ).Returns(trackedLinesFromSerialized);
var bufferLineCoverage = autoMoqer.Create();
- Assert.That(bufferLineCoverage.GetLines(2, 5), Is.SameAs(lines));
+ Assert.That(bufferLineCoverage.TrackedLines, Is.SameAs(trackedLinesFromSerialized));
}
[Test]
- public void Should_Listen_For_Coverage_Changed()
+ public void Should_Not_Create_TrackedLines_When_Existing_Coverage_When_LastWriteTime_After_LastTestExecutionStarting_When_No_Serialized_Coverage()
{
- SimpleTextInfoSetUp();
+ SimpleSetUp(false);
+ mockTextInfo.Setup(textInfo => textInfo.GetLastWriteTime()).Returns(new DateTime(2024, 5, 10));
+ var mockLastCoverage = autoMoqer.GetMock();
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.TestExecutionStartingDate).Returns(new DateTime(2024, 5, 9));
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.FileLineCoverage).Returns(new Mock().Object);
var bufferLineCoverage = autoMoqer.Create();
- autoMoqer.Verify(eventAggregator => eventAggregator.AddListener(bufferLineCoverage, null));
+ Assert.IsNull(bufferLineCoverage.TrackedLines);
+ }
+
+ private BufferLineCoverage SerializedCoverageisOutOfDate()
+ {
+ SimpleSetUp(false);
+
+ DateTime lastWriteDate = new DateTime(2024, 5, 9);
+ DateTime textExecutionStartingDate = new DateTime(2024, 5, 10);
+ DateTime serializedDate = new DateTime(2024, 5, 8);
+
+ mockTextInfo.Setup(textInfo => textInfo.GetLastWriteTime()).Returns(lastWriteDate);
+ var mockLastCoverage = autoMoqer.GetMock();
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.TestExecutionStartingDate).Returns(textExecutionStartingDate);
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.FileLineCoverage).Returns(new Mock().Object);
+
+ autoMoqer.Setup(dynamicCoverageStore => dynamicCoverageStore.GetSerializedCoverage(filePath))
+ .Returns(new SerializedCoverageWhen { Serialized = "serialized", When = serializedDate });
+
+ return autoMoqer.Create();
}
[Test]
- public void Should_Have_Empty_Lines_When_Coverage_Cleared()
+ public void Should_Not_Create_TrackedLines_When_Existing_Coverage_When_Serialized_Coverage_Is_Out_Of_Date()
{
- SimpleTextInfoSetUp();
+ var bufferLineCoverage = SerializedCoverageisOutOfDate();
+
+ Assert.IsNull(bufferLineCoverage.TrackedLines);
+ }
+
+ [Test]
+ public void Should_Log_When_Not_Creating_TrackedLines_As_Out_Of_Date()
+ {
+ SerializedCoverageisOutOfDate();
+
+ autoMoqer.Verify(logger => logger.Log($"Not creating editor marks for {filePath} as coverage is out of date"));
+ }
+ [Test]
+ public void Should_Create_TrackedLines_When_No_Serialized_Coverage_And_Not_Out_Of_Date()
+ {
+ SimpleSetUp(false);
+
+ DateTime lastWriteDate = new DateTime(2024, 5, 9);
+ DateTime textExecutionStartingDate = new DateTime(2024, 5, 10);
+
+ mockTextInfo.Setup(textInfo => textInfo.GetLastWriteTime()).Returns(lastWriteDate);
+ var mockLastCoverage = autoMoqer.GetMock();
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.TestExecutionStartingDate).Returns(textExecutionStartingDate);
+ var mockFileLineCoverage = new Mock();
+ mockLastCoverage.SetupGet(lastCoverage => lastCoverage.FileLineCoverage).Returns(mockFileLineCoverage.Object);
+ var lines = new List { new Mock().Object };
+ mockFileLineCoverage.Setup(fileLineCoverage => fileLineCoverage.GetLines(filePath)).Returns(lines);
+ var trackedLinesFromSerialized = new Mock().Object;
autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()))
- .Returns(new Mock().Object);
+ trackedLinesFactory => trackedLinesFactory.Create(lines, textSnapshot, filePath)
+ ).Returns(trackedLinesFromSerialized);
+
+ var bufferLineCoverage = autoMoqer.Create();
+
+ Assert.AreSame(bufferLineCoverage.TrackedLines, trackedLinesFromSerialized);
+ }
+
+ [Test]
+ public void Should_Log_If_Exception_Creating_TrackedLines()
+ {
+ var exception = new Exception("exception");
+
+ SimpleSetUp(false);
+
+ var mockFileLineCoverage = new Mock();
+ mockFileLineCoverage.Setup(fileLineCoverage => fileLineCoverage.GetLines(filePath)).Throws(exception);
+ AddLastFileLineCoverage(mockFileLineCoverage);
+
+ var bufferLineCoverage = autoMoqer.Create();
+
+ autoMoqer.Verify(logger => logger.Log($"Error creating tracked lines for {filePath}", exception));
+
+ }
+
+ [Test]
+ public void Should_Not_Create_TrackedLines_If_EditorCoverageColouringMode_Is_Off()
+ {
+ SimpleSetUp(true);
+
+ var lines = new List { CreateLine() };
+ var mockFileLineCoverage = new Mock();
+ mockFileLineCoverage.Setup(fileLineCoverage => fileLineCoverage.GetLines(filePath)).Returns(lines);
+ AddLastFileLineCoverage(mockFileLineCoverage);
+
+ var trackedLines = new Mock().Object;
+ var mockTrackedLinesFactory = autoMoqer.GetMock();
+ mockTrackedLinesFactory.Setup(trackedLinesFactory => trackedLinesFactory.Create(lines, textSnapshot, filePath))
+ .Returns(trackedLines);
+
+ var bufferLineCoverage = autoMoqer.Create();
+ Assert.IsNull(bufferLineCoverage.TrackedLines);
+ }
+
+ [Test]
+ public void Should_Have_Null_TrackedLines_If_No_Initial_Coverage()
+ {
+
+ MockTextInfo(new Mock());
+ var bufferLineCoverage = new BufferLineCoverage(
+ null,
+ mockTextInfo.Object,
+ new Mock().Object,
+ null,
+ null,
+ new Mock().Object,
+ null
+ );
+
+ Assert.IsNull(bufferLineCoverage.TrackedLines);
+ }
+
+
+
+ #endregion
+
+ #region NewCoverageLinesMessge
+
+ [Test]
+ public void Should_Have_Null_TrackedLines_After_Sending_CoverageChangedMessage_When_Coverage_Cleared()
+ {
+ SimpleSetUp(false);
var bufferLineCoverage = autoMoqer.Create();
+ bufferLineCoverage.TrackedLines = new Mock().Object;
+
+ var mockEventAggregator = autoMoqer.GetMock();
+ mockEventAggregator.Setup(eventAggregator => eventAggregator.SendMessage(
+ new CoverageChangedMessage(bufferLineCoverage,filePath,null),
+ null
+ )).Callback(() => Assert.IsNull(bufferLineCoverage.TrackedLines));
bufferLineCoverage.Handle(new NewCoverageLinesMessage());
- var lines = bufferLineCoverage.GetLines(2, 5);
- Assert.That(lines, Is.Empty);
+ mockEventAggregator.VerifyAll();
+ }
+
+ [Test]
+ public void Should_Not_Send_CoverageChangedMessage_For_Coverage_Clearing_If_Not_Tracking()
+ {
+ SimpleSetUp(false);
+ var bufferLineCoverage = autoMoqer.Create();
+ bufferLineCoverage.TrackedLines = null;
+
+ bufferLineCoverage.Handle(new NewCoverageLinesMessage());
+
+ autoMoqer.Verify(eventAggregator => eventAggregator.SendMessage(
+ It.IsAny(),
+ null
+ ),Times.Never());
+
}
[TestCase(true)]
[TestCase(false)]
- public void Should_Create_New_TextLines_When_Coverage_Changed_And_Not_Off_In_AppOptions(bool off)
- {
- var autoMoqer = new AutoMoqer();
- SetupEditorCoverageColouringMode(autoMoqer, off);
- var mockTextBuffer = new Mock();
- mockTextBuffer.Setup(textBuffer => textBuffer.ContentType.TypeName).Returns("CSharp");
- var mockCurrentSnapshot = new Mock();
- mockCurrentSnapshot.SetupGet(snapshot => snapshot.LineCount).Returns(10);
- mockTextBuffer.SetupSequence(textBuffer => textBuffer.CurrentSnapshot)
- .Returns(new Mock().Object)
- .Returns(mockCurrentSnapshot.Object);
- var mockTextDocument = new Mock();
- mockTextDocument.SetupGet(textDocument => textDocument.FilePath).Returns("filepath");
- var mockTextInfo = new Mock();
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer).Returns(mockTextBuffer.Object);
- mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns("filepath");
- mockTextInfo.SetupGet(textInfo => textInfo.TextView).Returns(new Mock().Object);
- autoMoqer.SetInstance(mockTextInfo.Object);
+ public void Should_Create_New_TextLines_From_New_Coverage_And_Not_Off_In_AppOptions(bool off)
+ {
+ // no initial tracked lines
+ SimpleSetUp(true);
+ var bufferLineCoverage = autoMoqer.Create();
- var lines = new List { CreateLine()};
- var mockNewFileLineCoverage = autoMoqer.GetMock();
- mockNewFileLineCoverage.Setup(fileLineCoverage => fileLineCoverage.GetLines("filepath")).Returns(lines);
+ if (!off)
+ {
+ var appOptionsOn = CreateAppOptions(false);
+ autoMoqer.GetMock()
+ .Raise(appOptionsProvider => appOptionsProvider.OptionsChanged += null, appOptionsOn);
+ }
- var mockTrackedLines = new Mock();
- var dynamicLines = new List();
- mockTrackedLines.Setup(trackedLines => trackedLines.GetLines(2, 5)).Returns(dynamicLines);
+ var newCoverageLines = new List { CreateLine() };
autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(lines, mockCurrentSnapshot.Object, Language.CSharp)
- ).Returns(mockTrackedLines.Object);
+ trackedLinesFactory => trackedLinesFactory.Create(newCoverageLines, textSnapshot, filePath)
+ ).Returns(new Mock().Object);
+ var mockFileLineCoverage = new Mock();
+ mockFileLineCoverage.Setup(fileLineCoverage => fileLineCoverage.GetLines(filePath)).Returns(newCoverageLines);
+ (bufferLineCoverage as IListener).Handle(
+ new NewCoverageLinesMessage { CoverageLines = mockFileLineCoverage.Object });
- var bufferLineCoverage = autoMoqer.Create();
-
- bufferLineCoverage.Handle(new NewCoverageLinesMessage { CoverageLines = mockNewFileLineCoverage.Object });
- var bufferLines = bufferLineCoverage.GetLines(2, 5);
+
if (off)
{
- Assert.That(bufferLines, Is.Empty);
+ Assert.That(bufferLineCoverage.TrackedLines, Is.Null);
}
else
{
- Assert.That(bufferLines, Is.SameAs(dynamicLines));
+ autoMoqer.Verify(eventAggregator => eventAggregator.SendMessage(
+ new CoverageChangedMessage(bufferLineCoverage,filePath, null), null), Times.Once());
+ Assert.That(bufferLineCoverage.TrackedLines, Is.Not.Null);
}
}
- [TestCase(true,true,true,true)]
- [TestCase(true, false, true, true)]
- [TestCase(false, true, true, true)]
- [TestCase(true, false, false, true)]
- [TestCase(false, false, false, false)]
- public void Should_Send_CoverageChangedMessage_When_Necessary(
- bool initialTrackedLines,
- bool nextTrackedLines,
- bool hasCoverageLines,
- bool expectedSends)
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Should_Not_Create_TrackedLines_From_NewCoverageLinesMessage_If_Text_Changed_Since_TestExecutionStartingMessage(
+ bool textChangedSinceTestExecutionStarting
+ )
{
- SimpleTextInfoSetUp();
- var trackedLines = new Mock().Object;
+ var bufferLineCoverage = SetupNoInitialTrackedLines();
+
var mockTrackedLinesFactory = autoMoqer.GetMock();
- mockTrackedLinesFactory.SetupSequence(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()))
- .Returns(initialTrackedLines ? trackedLines : null)
- .Returns(nextTrackedLines ? trackedLines : null);
- var bufferLineCoverage = autoMoqer.Create();
+ mockTrackedLinesFactory.Setup(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), textSnapshot, filePath))
+ .Returns(new Mock().Object);
- var newCoverageLinesMessage = new NewCoverageLinesMessage();
- if(hasCoverageLines)
+
+ void RaiseChangedOnBackground()
+ {
+ mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, new TextContentChangedEventArgs(new Mock().Object, new Mock().Object, new EditOptions(), null));
+ }
+ void RaiseTestExecutionStartingMessage()
{
- newCoverageLinesMessage.CoverageLines = new Mock().Object;
+ (bufferLineCoverage as IListener).Handle(new TestExecutionStartingMessage());
}
- bufferLineCoverage.Handle(newCoverageLinesMessage);
+
- autoMoqer.Verify(
- eventAggregator => eventAggregator.SendMessage(
- It.Is(message => message.AppliesTo == "filepath" && message.BufferLineCoverage == bufferLineCoverage)
- , null
- ), expectedSends ? Times.Once() : Times.Never());
+ if (textChangedSinceTestExecutionStarting)
+ {
+ RaiseTestExecutionStartingMessage();
+ Thread.Sleep(1);
+ RaiseChangedOnBackground();
+ } else
+ {
+ RaiseChangedOnBackground();
+ Thread.Sleep(1);
+ RaiseTestExecutionStartingMessage();
+ }
+
+ bufferLineCoverage.Handle(new NewCoverageLinesMessage { CoverageLines = new Mock().Object });
+
+
+ Assert.That(bufferLineCoverage.TrackedLines, textChangedSinceTestExecutionStarting ? Is.Null : Is.Not.Null);
+
+ var expectCoverageChangedMessage = textChangedSinceTestExecutionStarting ? false : true;
+ autoMoqer.Verify(eventAggregator => eventAggregator.SendMessage(
+ It.IsAny(), null),
+ Times.Exactly(expectCoverageChangedMessage ? 1 : 0));
}
- [TestCase(true)]
- [TestCase(false)]
- public void Should_Update_TrackedLines_When_Text_Buffer_ChangedOnBackground(bool linesInRange)
+ [Test]
+ public void Should_Log_When_Text_Changed_Since_TestExecutionStartingMessage()
{
- SimpleTextInfoSetUp();
+ var bufferLineCoverage = SetupNoInitialTrackedLines();
- var mockAfterSnapshot = new Mock();
- mockAfterSnapshot.SetupGet(textSnapshot => textSnapshot.LineCount).Returns(linesInRange ? 100 : 11);
+ (bufferLineCoverage as IListener).Handle(new TestExecutionStartingMessage());
+ Thread.Sleep(1);
+ mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, new TextContentChangedEventArgs(new Mock().Object, new Mock().Object, new EditOptions(), null));
- var newSpan = new Span(1, 2);
- var mockTrackedLines = new Mock();
- var changedLineNumbers = new List { 11, 12 };
- mockTrackedLines.Setup(trackedLines => trackedLines.GetChangedLineNumbers(mockAfterSnapshot.Object, new List { newSpan }))
- .Returns(changedLineNumbers);
- autoMoqer.Setup(trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()))
- .Returns(mockTrackedLines.Object);
+ bufferLineCoverage.Handle(new NewCoverageLinesMessage { CoverageLines = new Mock().Object });
+
+ autoMoqer.Verify(ILogger => ILogger.Log($"Not creating editor marks for {filePath} as it was changed after test execution started"));
+ }
+ #endregion
+
+
+ #region updating when text changes on background
+ [TestCase(10, new int[] { -1, 9, 10 }, new int[] { 9 })]
+ [TestCase(10, new int[] { 9, 10 }, new int[] {})]
+ public void Should_Update_TrackedLines_When_Text_Buffer_ChangedOnBackground_And_Send_CoverageChangedMessage_If_Any_Changed_Within_Snapshot(
+ int afterLineCount,
+ int[] changedLineNumbers,
+ int[] expectedMessageChangedLineNumbers
+ )
+ {
+ SimpleSetUp(false);
+ var mockAfterSnapshot = new Mock();
+ mockAfterSnapshot.SetupGet(afterSnapshot => afterSnapshot.LineCount).Returns(afterLineCount);
var bufferLineCoverage = autoMoqer.Create();
+ var mockTrackedLines = new Mock();
+ var newSpan = new Span(0, 1);
+ mockTrackedLines.Setup(
+ trackedLines => trackedLines.GetChangedLineNumbers(mockAfterSnapshot.Object, new List { newSpan})
+ ).Returns(changedLineNumbers);
+ bufferLineCoverage.TrackedLines = mockTrackedLines.Object;
+
mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, CreateTextContentChangedEventArgs(mockAfterSnapshot.Object, newSpan));
autoMoqer.Verify(
- eventAggregator => eventAggregator.SendMessage(
- It.Is(message => message.AppliesTo == "filepath" && message.BufferLineCoverage == bufferLineCoverage && message.ChangedLineNumbers.SequenceEqual(changedLineNumbers))
- , null
- ), Times.Exactly(linesInRange ? 1 : 0));
+ eventAggregator => eventAggregator.SendMessage(
+ It.Is(message =>
+ message.AppliesTo == filePath &&
+ message.BufferLineCoverage == bufferLineCoverage &&
+ message.ChangedLineNumbers.SequenceEqual(expectedMessageChangedLineNumbers))
+ , null
+ ), expectedMessageChangedLineNumbers.Length > 0 ? Times.Once() : Times.Never());
}
[Test]
- public void Should_Not_Throw_When_Text_Buffer_Changed_And_No_Coverage()
+ public void Should_Log_When_Exception_Updating_TrackedLines_When_Text_Buffer_ChangedOnBackground()
{
- SimpleTextInfoSetUp();
+ SimpleSetUp(false);
+
+ var bufferLineCoverage = autoMoqer.Create();
- autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny()))
- .Returns(new Mock().Object);
+ var exception = new Exception("message");
+ var mockTrackedLines = new Mock();
+ mockTrackedLines.Setup(
+ trackedLines => trackedLines.GetChangedLineNumbers(It.IsAny(), It.IsAny>())
+ ).Throws(exception);
+ bufferLineCoverage.TrackedLines = mockTrackedLines.Object;
- var bufferLineCoverage = autoMoqer.Create();
+ mockTextBuffer.Raise(textBuffer => textBuffer.ChangedOnBackground += null, CreateTextContentChangedEventArgs(new Mock().Object, new Span(0,1)));
- // clear coverage
- bufferLineCoverage.Handle(new NewCoverageLinesMessage());
+ autoMoqer.Verify(logger => logger.Log($"Error updating tracked lines for {filePath}", exception));
+ }
+
+ [Test]
+ public void Should_Not_Throw_When_Text_Buffer_Changed_And_No_Coverage()
+ {
+ SimpleSetUp(true);
+
+ var bufferLineCoverage = autoMoqer.Create();
+ bufferLineCoverage.TrackedLines = null;
mockTextBuffer.Raise(textBuffer => textBuffer.Changed += null, CreateTextContentChangedEventArgs(new Mock().Object, new Span(0, 0)));
}
-
+ #endregion
private TextContentChangedEventArgs CreateTextContentChangedEventArgs(ITextSnapshot afterSnapshot, params Span[] newSpans)
{
var normalizedTextChangeCollection = new NormalizedTextChangeCollection();
@@ -295,154 +517,76 @@ private TextContentChangedEventArgs CreateTextContentChangedEventArgs(ITextSnaps
return new TextContentChangedEventArgs(mockBeforeSnapshot.Object, afterSnapshot, EditOptions.None, null);
}
- [Test]
- public void Should_Stop_Listening_When_TextView_Closed()
+ #region saving serialized coverage
+ [TestCase(true)]
+ [TestCase(false)]
+ public void Should_SaveSerializedCoverage_When_TextView_Closed_And_Tracking_And_File_System_Reflecting_TrackedLines(
+ bool fileSystemReflectsTrackedLines
+ )
{
- SimpleTextInfoSetUp();
-
+ SimpleSetUp(false);
var bufferLineCoverage = autoMoqer.Create();
+ bufferLineCoverage.TrackedLines = new Mock().Object;
- mockTextView.Raise(textView => textView.Closed += null, EventArgs.Empty);
-
- autoMoqer.Verify(eventAggregator => eventAggregator.RemoveListener(bufferLineCoverage));
- mockTextView.VerifyRemove(textView => textView.Closed -= It.IsAny(), Times.Once);
- mockTextBuffer.VerifyRemove(textBuffer => textBuffer.Changed -= It.IsAny>(), Times.Once);
- var mockAppOptionsProvider = autoMoqer.GetMock();
- mockAppOptionsProvider.VerifyRemove(appOptionsProvider => appOptionsProvider.OptionsChanged -= It.IsAny>(), Times.Once);
- }
-
- [Test]
- public void Should_SaveSerializedCoverage_When_TextView_Closed_And_There_Has_Been_Coverage()
- {
- var autoMoqer = new AutoMoqer();
- SetupEditorCoverageColouringMode(autoMoqer);
- var mockTextInfo = autoMoqer.GetMock();
- mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns("filepath");
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer.ContentType.TypeName).Returns("contenttypename");
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer.CurrentSnapshot).Returns(new Mock().Object);
- var mockTextView = new Mock();
- mockTextInfo.SetupGet(textInfo => textInfo.TextView).Returns(mockTextView.Object);
- autoMoqer.Setup>(
- fileLineCoverage => fileLineCoverage.GetLines(It.IsAny(), It.IsAny(), It.IsAny())
- ).Returns(new List { });
- var trackedLines = new Mock().Object;
- autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny())
- ).Returns(trackedLines);
+ var snapshotText = "snapshot text";
autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Serialize(trackedLines)
+ trackedLinesFactory => trackedLinesFactory.Serialize(bufferLineCoverage.TrackedLines, snapshotText)
).Returns("serialized");
- autoMoqer.Create();
-
+ mockTextInfo.Setup(textInfo => textInfo.GetFileText())
+ .Returns(fileSystemReflectsTrackedLines ? snapshotText : "changes not saved");
+
+ var mockTextViewCurrentSnapshot = new Mock();
+ mockTextViewCurrentSnapshot.Setup(snapshot => snapshot.GetText()).Returns(snapshotText);
+ mockTextView.Setup(textView => textView.TextSnapshot).Returns(mockTextViewCurrentSnapshot.Object);
+
mockTextView.Raise(textView => textView.Closed += null, EventArgs.Empty);
- autoMoqer.Verify(dynamicCoverageStore => dynamicCoverageStore.SaveSerializedCoverage("filepath", "serialized"));
+ autoMoqer.Verify(
+ dynamicCoverageStore => dynamicCoverageStore.SaveSerializedCoverage(filePath, "serialized"),
+ fileSystemReflectsTrackedLines ? Times.Once() : Times.Never());
+
}
[Test]
public void Should_Remove_Serialized_Coverage_When_TextView_Closed_And_No_TrackedLines()
{
- var autoMoqer = new AutoMoqer();
- SetupEditorCoverageColouringMode(autoMoqer);
- var mockTextInfo = autoMoqer.GetMock();
- mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns("filepath");
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer.ContentType.TypeName).Returns("contenttypename");
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer.CurrentSnapshot).Returns(new Mock().Object);
- var mockTextView = new Mock();
- mockTextInfo.SetupGet(textInfo => textInfo.TextView).Returns(mockTextView.Object);
- autoMoqer.Setup>(
- fileLineCoverage => fileLineCoverage.GetLines(It.IsAny(), It.IsAny(), It.IsAny())
- ).Returns(new List { });
- var trackedLines = new Mock().Object;
- autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny())
- ).Returns(trackedLines);
- autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Serialize(trackedLines)
- ).Returns("serialized");
-
+ SimpleSetUp(false);
var bufferLineCoverage = autoMoqer.Create();
- // clear coverage
- bufferLineCoverage.Handle(new NewCoverageLinesMessage());
+ bufferLineCoverage.TrackedLines = null;
mockTextView.Raise(textView => textView.Closed += null, EventArgs.Empty);
- autoMoqer.Verify(dynamicCoverageStore => dynamicCoverageStore.RemoveSerializedCoverage("filepath"));
+ autoMoqer.Verify(dynamicCoverageStore => dynamicCoverageStore.RemoveSerializedCoverage(filePath));
}
+ #endregion
- [TestCase(true, "CSharp", Language.CSharp)]
- [TestCase(true, "Basic", Language.VB)]
- [TestCase(true, "C/C++", Language.CPP)]
- [TestCase(false,"",Language.CPP)]
- public void Should_Create_From_Serialized_Coverage_If_Present(bool hasSerialized,string contentTypeLanguage, Language expectedLanguage)
- {
- var autoMoqer = new AutoMoqer();
- SetupEditorCoverageColouringMode(autoMoqer);
- var mockTextInfo = autoMoqer.GetMock();
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer.ContentType.TypeName).Returns(contentTypeLanguage);
- mockTextInfo.SetupGet(textInfo => textInfo.TextView).Returns(new Mock().Object);
- var currentTextSnaphot = new Mock().Object;
- mockTextInfo.SetupGet(textInfo => textInfo.TextBuffer.CurrentSnapshot).Returns(currentTextSnaphot);
- mockTextInfo.SetupGet(textInfo => textInfo.FilePath).Returns("filepath");
- autoMoqer.Setup(dynamicCoverageStore => dynamicCoverageStore.GetSerializedCoverage("filepath"))
- .Returns(hasSerialized ? "serialized" : null);
-
- var mockTrackedLinesNoSerialized = new Mock();
- autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny())
- ).Returns(mockTrackedLinesNoSerialized.Object);
-
- var mockTrackedLinesFromSerialized = new Mock();
- autoMoqer.Setup(
- trackedLinesFactory => trackedLinesFactory.Create("serialized", currentTextSnaphot, expectedLanguage)
- ).Returns(mockTrackedLinesFromSerialized.Object);
-
-
- var bufferLineCoverage = autoMoqer.Create();
-
- bufferLineCoverage.GetLines(2, 5);
-
- var expectedMockTrackedLines = hasSerialized ? mockTrackedLinesFromSerialized : mockTrackedLinesNoSerialized;
- expectedMockTrackedLines.Verify(trackedLines => trackedLines.GetLines(2, 5), Times.Once);
- }
+ #region app options turn off editor coverage
[Test]
public void Should_Remove_TrackedLines_When_AppOptions_Changed_And_EditorCoverageColouringMode_Is_Off()
{
- SimpleTextInfoSetUp();
- var mockTrackedLines = new Mock();
- mockTrackedLines.Setup(trackedLines => trackedLines.GetLines(It.IsAny(), It.IsAny()))
- .Returns(new List { new Mock().Object });
- autoMoqer.Setup(
- trackedCoverageLinesFactory => trackedCoverageLinesFactory.Create(It.IsAny>(), It.IsAny(), It.IsAny