Skip to content

Commit 3511216

Browse files
authored
Fix exception in tests (#12038)
Going through our tests trying to find the source of the flakiness. This isn't it, but it does throw an exception during language server shut down (method not mocked) so its not exactly helping.
2 parents b19444c + fc7aac5 commit 3511216

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Immutable;
5+
using System.Threading.Tasks;
6+
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
7+
8+
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
9+
10+
internal sealed class TestRazorProjectInfoDriver : IRazorProjectInfoDriver
11+
{
12+
public static readonly TestRazorProjectInfoDriver Instance = new();
13+
14+
public void AddListener(IRazorProjectInfoListener listener)
15+
{
16+
}
17+
18+
public ImmutableArray<RazorProjectInfo> GetLatestProjectInfo()
19+
{
20+
return [];
21+
}
22+
23+
public Task WaitForInitializationAsync()
24+
{
25+
return Task.CompletedTask;
26+
}
27+
}

src/Razor/test/Microsoft.AspNetCore.Razor.LanguageServer.Test/TestRazorProjectService.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
using System.Threading.Tasks;
66
using Microsoft.AspNetCore.Razor.Language;
77
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
8-
using Microsoft.AspNetCore.Razor.Test.Common;
98
using Microsoft.CodeAnalysis.Razor.Logging;
109
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
1110
using Microsoft.CodeAnalysis.Razor.Serialization;
1211
using Microsoft.CodeAnalysis.Razor.Utilities;
13-
using Moq;
1412

1513
namespace Microsoft.AspNetCore.Razor.LanguageServer.ProjectSystem;
1614

@@ -20,24 +18,12 @@ internal class TestRazorProjectService(
2018
ILoggerFactory loggerFactory)
2119
: RazorProjectService(
2220
projectManager,
23-
CreateProjectInfoDriver(),
21+
TestRazorProjectInfoDriver.Instance,
2422
remoteTextLoaderFactory,
2523
loggerFactory)
2624
{
2725
private readonly ProjectSnapshotManager _projectManager = projectManager;
2826

29-
private static IRazorProjectInfoDriver CreateProjectInfoDriver()
30-
{
31-
var mock = new StrictMock<IRazorProjectInfoDriver>();
32-
33-
mock.Setup(x => x.GetLatestProjectInfo())
34-
.Returns([]);
35-
36-
mock.Setup(x => x.AddListener(It.IsAny<IRazorProjectInfoListener>()));
37-
38-
return mock.Object;
39-
}
40-
4127
public async Task AddDocumentToPotentialProjectsAsync(string filePath, CancellationToken cancellationToken)
4228
{
4329
foreach (var projectSnapshot in _projectManager.FindPotentialProjects(filePath))

0 commit comments

Comments
 (0)