-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #423 from tonyhallett/fix-blazor-editor-marks
Fix blazor editor marks
- Loading branch information
Showing
91 changed files
with
3,018 additions
and
1,268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
FineCodeCoverageTests/Editor/DynamicCoverage/BlazorCoverageContentType_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IAppOptionsProvider>(); | ||
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<IBlazorFileCodeSpanRangeService>().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)); | ||
} | ||
|
||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
FineCodeCoverageTests/Editor/DynamicCoverage/BlazorFileCodeSpanRangeService_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ITextSnapshot>(); | ||
var mockTextBuffer = new Mock<ITextBuffer>(); | ||
mockTextSnapshot.SetupGet(textSnapshot => textSnapshot.TextBuffer).Returns(mockTextBuffer.Object); | ||
|
||
var autoMoqer = new AutoMoqer(); | ||
var razorGeneratedFilePathMatcher = autoMoqer.GetMock<IBlazorGeneratedFilePathMatcher>().Object; | ||
autoMoqer.SetInstance<IThreadHelper>(new TestThreadHelper()); | ||
autoMoqer.GetMock<ITextInfoFactory>().Setup(t => t.GetFilePath(mockTextBuffer.Object)).Returns("path"); | ||
|
||
var mockRazorGeneratedDocumentRootFinder = autoMoqer.GetMock<IBlazorGeneratedDocumentRootFinder>(); | ||
mockRazorGeneratedDocumentRootFinder.Setup( | ||
razorGeneratedDocumentootFinder => razorGeneratedDocumentootFinder.FindSyntaxRootAsync(mockTextBuffer.Object, "path", razorGeneratedFilePathMatcher) | ||
).ReturnsAsync((SyntaxNode)null); | ||
|
||
var fileCodeSpanRanges = autoMoqer.Create<BlazorFileCodeSpanRangeService>().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<ITextSnapshot>(); | ||
var mockTextBuffer = new Mock<ITextBuffer>(); | ||
mockTextSnapshot.SetupGet(textSnapshot => textSnapshot.TextBuffer).Returns(mockTextBuffer.Object); | ||
|
||
var autoMoqer = new AutoMoqer(); | ||
var mockCSharpCodeCoverageNodeVisitor = autoMoqer.GetMock<ICSharpCodeCoverageNodeVisitor>(); | ||
mockCSharpCodeCoverageNodeVisitor.Setup(cSharpCodeCoverageNodeVisitor => cSharpCodeCoverageNodeVisitor.GetNodes(It.IsAny<SyntaxNode>())) | ||
.Returns(new List<SyntaxNode>()); | ||
var razorGeneratedFilePathMatcher = autoMoqer.GetMock<IBlazorGeneratedFilePathMatcher>().Object; | ||
autoMoqer.SetInstance<IThreadHelper>(new TestThreadHelper()); | ||
autoMoqer.GetMock<ITextInfoFactory>().Setup(t => t.GetFilePath(mockTextBuffer.Object)).Returns("path"); | ||
|
||
var rootNode = SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration); | ||
var mockRazorGeneratedDocumentRootFinder = autoMoqer.GetMock<IBlazorGeneratedDocumentRootFinder>(); | ||
mockRazorGeneratedDocumentRootFinder.Setup( | ||
razorGeneratedDocumentootFinder => razorGeneratedDocumentootFinder.FindSyntaxRootAsync(mockTextBuffer.Object, "path", razorGeneratedFilePathMatcher) | ||
).ReturnsAsync(rootNode); | ||
|
||
var fileCodeSpanRanges = autoMoqer.Create<BlazorFileCodeSpanRangeService>().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<ITextSnapshot>(); | ||
var mockTextBuffer = new Mock<ITextBuffer>(); | ||
mockTextSnapshot.SetupGet(textSnapshot => textSnapshot.TextBuffer).Returns(mockTextBuffer.Object); | ||
|
||
var autoMoqer = new AutoMoqer(); | ||
var razorGeneratedFilePathMatcher = autoMoqer.GetMock<IBlazorGeneratedFilePathMatcher>().Object; | ||
autoMoqer.SetInstance<IThreadHelper>(new TestThreadHelper()); | ||
autoMoqer.GetMock<ITextInfoFactory>().Setup(t => t.GetFilePath(mockTextBuffer.Object)).Returns("path"); | ||
|
||
var mockRazorGeneratedDocumentRootFinder = autoMoqer.GetMock<IBlazorGeneratedDocumentRootFinder>(); | ||
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<ICSharpCodeCoverageNodeVisitor>(); | ||
mockCSharpCodeCoverageNodeVisitor.Setup(cSharpCodeCoverageNodeVisitor => cSharpCodeCoverageNodeVisitor.GetNodes(rootSyntaxNode)) | ||
.Returns(new List<SyntaxNode> { codeCoverageNode1, codeCoverageNode2 }); | ||
var mockSyntaxNodeLocationMapper = autoMoqer.GetMock<ISyntaxNodeLocationMapper>(); | ||
|
||
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<BlazorFileCodeSpanRangeService>().GetFileCodeSpanRanges(mockTextSnapshot.Object); | ||
var fileCodeSpanRange = fileCodeSpanRanges.Single(); | ||
|
||
Assert.That(expectedCodeSpanRange, Is.EqualTo(fileCodeSpanRange)); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
FineCodeCoverageTests/Editor/DynamicCoverage/BlazorGeneratedFilePathMatcher_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.