Skip to content

Commit

Permalink
Fixing most unit test failures.
Browse files Browse the repository at this point in the history
Extension methods can't be used for Mock setups, so since I made GetGeneratedOutputAsync() with no parameter an extension method, I had to switch unit tests to use GeGeneratedOutputAsync(It.Any<bool>())
  • Loading branch information
alexgav committed Aug 29, 2024
1 parent 137d9ad commit 7715a4c
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(
codeDocument.SetCSharpDocument(csharpDocumentWithDiagnostic);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(document =>
document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
document.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(codeDocument) &&
document.GetTextAsync() == Task.FromResult(codeDocument.Source.Text) &&
document.Project.GetTagHelpersAsync(It.IsAny<CancellationToken>()) == new ValueTask<ImmutableArray<TagHelperDescriptor>>(tagHelpers), MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(
codeDocument.SetCSharpDocument(csharpDocumentWithDiagnostic);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(document =>
document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
document.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(codeDocument) &&
document.GetTextAsync() == Task.FromResult(codeDocument.Source.Text) &&
document.Project.GetTagHelpersAsync(It.IsAny<CancellationToken>()) == new ValueTask<ImmutableArray<TagHelperDescriptor>>(tagHelpers), MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(
var codeDocument = projectEngine.ProcessDesignTime(sourceDocument, FileKinds.Component, importSources: default, tagHelpers);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(document =>
document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
document.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(codeDocument) &&
document.GetTextAsync() == Task.FromResult(codeDocument.Source.Text) &&
document.Project.GetTagHelpersAsync(It.IsAny<CancellationToken>()) == new ValueTask<ImmutableArray<TagHelperDescriptor>>(tagHelpers), MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP
codeDocument.SetCSharpDocument(csharpDocumentWithDiagnostic);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(document =>
document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
document.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(codeDocument) &&
document.GetTextAsync() == Task.FromResult(codeDocument.Source.Text) &&
document.Project.GetTagHelpersAsync(It.IsAny<CancellationToken>()) == new ValueTask<ImmutableArray<TagHelperDescriptor>>(tagHelpers), MockBehavior.Strict);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private static RazorCodeActionContext CreateRazorCodeActionContext(VSCodeActionP
codeDocument.SetSyntaxTree(syntaxTree);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(document =>
document.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
document.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(codeDocument) &&
document.GetTextAsync() == Task.FromResult(codeDocument.Source.Text), MockBehavior.Strict);

var sourceText = SourceText.From(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public async Task Handle_NoTypeNameIdentifier_ReturnsNull()
var builder = TagHelperDescriptorBuilder.Create("MyTagHelper", "MyAssembly");
var tagHelperDescriptor = builder.Build();

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(componentCodeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(componentCodeDocument), MockBehavior.Strict);

var uri = new Uri("file://path/test.razor");
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);
Expand Down Expand Up @@ -262,7 +262,7 @@ public async Task Handle_MultipleUris_ReturnsNull()
var documentMappingService = Mock.Of<IDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.Html, MockBehavior.Strict);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(false) == Task.FromResult(codeDocument), MockBehavior.Strict);

var uri = new Uri("file://path/test.razor");
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);
Expand Down Expand Up @@ -313,7 +313,7 @@ public async Task Handle_NotComponent_ReturnsNull()
var documentMappingService = Mock.Of<IDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.Html, MockBehavior.Strict);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(false) == Task.FromResult(codeDocument), MockBehavior.Strict);

var droppedUri = new Uri("file:///c:/path/MyTagHelper.cshtml");
var uri = new Uri("file://path/test.razor");
Expand Down Expand Up @@ -422,7 +422,7 @@ public async Task Handle_CSharp_ReturnsNull()
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.CSharp &&
s.TryMapToGeneratedDocumentRange(csharpDocument, It.IsAny<LinePositionSpan>(), out projectedRange) == true, MockBehavior.Strict);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(false) == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);

var response = (WorkspaceEdit?)null;
Expand Down Expand Up @@ -466,7 +466,7 @@ public async Task Handle_DocumentNotFound_ReturnsNull()
var documentMappingService = Mock.Of<IDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.Html, MockBehavior.Strict);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(false) == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);

var response = (WorkspaceEdit?)null;
Expand Down Expand Up @@ -511,7 +511,7 @@ public async Task Handle_UnsupportedCodeDocument_ReturnsNull()
var documentMappingService = Mock.Of<IDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.Html, MockBehavior.Strict);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(false) == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);

var response = new WorkspaceEdit();
Expand Down Expand Up @@ -555,7 +555,7 @@ public async Task Handle_NoUris_ReturnsNull()
var documentMappingService = Mock.Of<IDocumentMappingService>(
s => s.GetLanguageKind(codeDocument, It.IsAny<int>(), It.IsAny<bool>()) == RazorLanguageKind.Html, MockBehavior.Strict);

var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync() == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentSnapshot = Mock.Of<IDocumentSnapshot>(s => s.GetGeneratedOutputAsync(false) == Task.FromResult(codeDocument), MockBehavior.Strict);
var documentContextFactory = CreateDocumentContextFactory(uri, codeDocument);

var response = (WorkspaceEdit?)null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static (RazorCodeDocument, IDocumentSnapshot) CreateCodeDocumentAndSnaps

var documentSnapshot = new Mock<IDocumentSnapshot>(MockBehavior.Strict);
documentSnapshot
.Setup(d => d.GetGeneratedOutputAsync())
.Setup(d => d.GetGeneratedOutputAsync(It.IsAny<bool>()))
.ReturnsAsync(codeDocument);
documentSnapshot
.Setup(d => d.TargetPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,6 @@ @using Microsoft.AspNetCore.Components.Web
internal static IDocumentSnapshot CreateDocumentSnapshot(string path, ImmutableArray<TagHelperDescriptor> tagHelpers, string? fileKind, ImmutableArray<RazorSourceDocument> importsDocuments, ImmutableArray<IDocumentSnapshot> imports, RazorProjectEngine projectEngine, RazorCodeDocument codeDocument, bool inGlobalNamespace = false)
{
var documentSnapshot = new Mock<IDocumentSnapshot>(MockBehavior.Strict);
documentSnapshot
.Setup(d => d.GetGeneratedOutputAsync())
.ReturnsAsync(codeDocument);
documentSnapshot
.Setup(d => d.GetGeneratedOutputAsync(It.IsAny<bool>()))
.ReturnsAsync(codeDocument);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ public void Increment(){
var sourceText = SourceText.From(txt);

var snapshot = Mock.Of<IDocumentSnapshot>(d =>
d.GetGeneratedOutputAsync() == Task.FromResult(codeDocument) &&
d.GetGeneratedOutputAsync(It.IsAny<bool>()) == Task.FromResult(codeDocument) &&
d.FilePath == path &&
d.FileKind == FileKinds.Component &&
d.GetTextAsync() == Task.FromResult(sourceText) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ private static DocumentContext CreateDocumentContext(
.SetupGet(x => x.Project)
.Returns(projectSnapshot.Object);
documentSnapshotMock
.Setup(x => x.GetGeneratedOutputAsync())
.Setup(x => x.GetGeneratedOutputAsync(It.IsAny<bool>()))
.ReturnsAsync(document);
documentSnapshotMock
.Setup(x => x.GetTextAsync())
Expand Down

0 comments on commit 7715a4c

Please sign in to comment.