Skip to content

Commit 2369059

Browse files
Remove RazorLogger from VisualStudioLSPEditorFeatureDetectorTest
1 parent 6226245 commit 2369059

File tree

5 files changed

+57
-62
lines changed

5 files changed

+57
-62
lines changed

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/ActivityLogLoggerProvider.Logger.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Logging;
1010

1111
internal sealed partial class ActivityLogLoggerProvider
1212
{
13-
private sealed class Logger(ActivityLog activityLog, string categoryName) : ILogger
13+
private sealed class Logger(RazorActivityLog activityLog, string categoryName) : ILogger
1414
{
15-
private readonly ActivityLog _activityLog = activityLog;
15+
private readonly RazorActivityLog _activityLog = activityLog;
1616
private readonly string _categoryName = categoryName;
1717

1818
public bool IsEnabled(LogLevel logLevel)

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/ActivityLogLoggerProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor.Logging;
1212
/// </summary>
1313
[Export(typeof(ILoggerProvider))]
1414
[method: ImportingConstructor]
15-
internal sealed partial class ActivityLogLoggerProvider(ActivityLog activityLog) : ILoggerProvider
15+
internal sealed partial class ActivityLogLoggerProvider(RazorActivityLog activityLog) : ILoggerProvider
1616
{
17-
private readonly ActivityLog _activityLog = activityLog;
17+
private readonly RazorActivityLog _activityLog = activityLog;
1818

1919
public ILogger CreateLogger(string categoryName)
2020
=> new Logger(_activityLog, categoryName);

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/ActivityLog.cs renamed to src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/Logging/RazorActivityLog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
namespace Microsoft.VisualStudio.Razor.Logging;
1616

17-
[Export(typeof(ActivityLog))]
18-
internal sealed class ActivityLog : IDisposable
17+
[Export(typeof(RazorActivityLog))]
18+
internal sealed class RazorActivityLog : IDisposable
1919
{
2020
private enum EntryType { Error, Warning, Info }
2121

@@ -26,7 +26,7 @@ private enum EntryType { Error, Warning, Info }
2626
private readonly AsyncBatchingWorkQueue<(EntryType, string)> _loggingQueue;
2727
private IVsActivityLog? _vsActivityLog;
2828

29-
public ActivityLog(
29+
public RazorActivityLog(
3030
[Import(typeof(SAsyncServiceProvider))] IAsyncServiceProvider serviceProvider,
3131
JoinableTaskContext joinableTaskContext)
3232
{

src/Razor/src/Microsoft.VisualStudio.LanguageServices.Razor/VisualStudioLSPEditorFeatureDetector.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
using System;
55
using System.ComponentModel.Composition;
6-
using Microsoft.CodeAnalysis.Razor;
76
using Microsoft.CodeAnalysis.Razor.Workspaces;
87
using Microsoft.Internal.VisualStudio.Shell.Interop;
8+
using Microsoft.VisualStudio.Razor.Logging;
99
using Microsoft.VisualStudio.Settings;
1010
using Microsoft.VisualStudio.Shell;
1111
using Microsoft.VisualStudio.Shell.Interop;
@@ -27,10 +27,10 @@ internal class VisualStudioLSPEditorFeatureDetector : LSPEditorFeatureDetector
2727
private readonly Lazy<IVsUIShellOpenDocument> _vsUIShellOpenDocument;
2828
private readonly Lazy<bool> _useLegacyEditor;
2929

30-
private readonly RazorLogger _logger;
30+
private readonly RazorActivityLog _activityLog;
3131

3232
[ImportingConstructor]
33-
public VisualStudioLSPEditorFeatureDetector(AggregateProjectCapabilityResolver projectCapabilityResolver, RazorLogger logger)
33+
public VisualStudioLSPEditorFeatureDetector(AggregateProjectCapabilityResolver projectCapabilityResolver, RazorActivityLog activityLog)
3434
{
3535
_projectCapabilityResolver = projectCapabilityResolver;
3636
_vsUIShellOpenDocument = new Lazy<IVsUIShellOpenDocument>(() =>
@@ -57,7 +57,7 @@ public VisualStudioLSPEditorFeatureDetector(AggregateProjectCapabilityResolver p
5757
return useLegacyEditor;
5858
});
5959

60-
_logger = logger;
60+
_activityLog = activityLog;
6161
}
6262

6363
[Obsolete("Test constructor")]
@@ -69,24 +69,24 @@ internal VisualStudioLSPEditorFeatureDetector()
6969

7070
public override bool IsLSPEditorAvailable(string? documentMoniker, object? hierarchy)
7171
{
72-
_logger.LogVerbose("Checking if LSP Editor is available");
72+
_activityLog.LogInfo("Checking if LSP Editor is available");
7373
if (documentMoniker is null)
7474
{
75-
_logger.LogWarning($"LSP Editor not available because {nameof(documentMoniker)} is null");
75+
_activityLog.LogWarning($"LSP Editor not available because {nameof(documentMoniker)} is null");
7676
return false;
7777
}
7878

7979
if (!IsLSPEditorAvailable())
8080
{
81-
_logger.LogVerbose("Using Legacy editor because the option was set to true");
81+
_activityLog.LogInfo("Using Legacy editor because the option was set to true");
8282
return false;
8383
}
8484

8585
var ivsHierarchy = hierarchy as IVsHierarchy;
8686
if (!ProjectSupportsLSPEditor(documentMoniker, ivsHierarchy))
8787
{
8888
// Current project hierarchy doesn't support the LSP Razor editor
89-
_logger.LogVerbose("Using Legacy editor because the current project does not support LSP Editor");
89+
_activityLog.LogInfo("Using Legacy editor because the current project does not support LSP Editor");
9090
return false;
9191
}
9292

@@ -114,11 +114,11 @@ private protected virtual bool ProjectSupportsLSPEditor(string documentMoniker,
114114
{
115115
if (!ErrorHandler.Succeeded(hr))
116116
{
117-
_logger.LogWarning($"Project does not support LSP Editor beccause {nameof(_vsUIShellOpenDocument.Value.IsDocumentInAProject)} failed with exit code {hr}");
117+
_activityLog.LogWarning($"Project does not support LSP Editor beccause {nameof(_vsUIShellOpenDocument.Value.IsDocumentInAProject)} failed with exit code {hr}");
118118
}
119119
else if (hierarchy is null)
120120
{
121-
_logger.LogWarning($"Project does not support LSP Editor because {nameof(hierarchy)} is null");
121+
_activityLog.LogWarning($"Project does not support LSP Editor because {nameof(hierarchy)} is null");
122122
}
123123

124124
return false;
@@ -130,7 +130,7 @@ private protected virtual bool ProjectSupportsLSPEditor(string documentMoniker,
130130
// those types of scenarios for the new .NET Core Razor editor.
131131
if (_projectCapabilityResolver.HasCapability(documentMoniker, hierarchy, LegacyRazorEditorCapability))
132132
{
133-
_logger.LogVerbose($"Project does not support LSP Editor because '{documentMoniker}' has Capability {LegacyRazorEditorCapability}");
133+
_activityLog.LogInfo($"Project does not support LSP Editor because '{documentMoniker}' has Capability {LegacyRazorEditorCapability}");
134134
// CPS project that requires the legacy editor
135135
return false;
136136
}
@@ -141,7 +141,7 @@ private protected virtual bool ProjectSupportsLSPEditor(string documentMoniker,
141141
return true;
142142
}
143143

144-
_logger.LogVerbose($"Project {documentMoniker} does not support LSP Editor because it does not have the {DotNetCoreCSharpCapability} capability.");
144+
_activityLog.LogInfo($"Project {documentMoniker} does not support LSP Editor because it does not have the {DotNetCoreCSharpCapability} capability.");
145145
// Not a C# .NET Core project. This typically happens for legacy Razor scenarios
146146
return false;
147147
}
Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the MIT license. See License.txt in the project root for license information.
33

4-
#nullable disable
5-
64
using Microsoft.AspNetCore.Razor.Test.Common;
7-
using Microsoft.CodeAnalysis.Razor;
5+
using Microsoft.VisualStudio.Razor.Logging;
6+
using Microsoft.VisualStudio.Shell;
87
using Microsoft.VisualStudio.Shell.Interop;
98
using Moq;
109
using Xunit;
1110
using Xunit.Abstractions;
1211

1312
namespace Microsoft.VisualStudio.Razor;
1413

15-
public class VisualStudioLSPEditorFeatureDetectorTest : ToolingTestBase
14+
public class VisualStudioLSPEditorFeatureDetectorTest(ITestOutputHelper testOutput) : ToolingTestBase(testOutput)
1615
{
17-
public VisualStudioLSPEditorFeatureDetectorTest(ITestOutputHelper testOutput)
18-
: base(testOutput)
19-
{
20-
}
21-
22-
[Fact]
16+
[UIFact]
2317
public void IsLSPEditorAvailable_ProjectSupported_ReturnsTrue()
2418
{
2519
// Arrange
26-
var logger = GetRazorLogger();
27-
var featureDetector = new TestLSPEditorFeatureDetector(logger)
20+
using var activityLog = GetRazorActivityLog();
21+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog)
2822
{
2923
ProjectSupportsLSPEditorValue = true,
3024
};
@@ -36,12 +30,12 @@ public void IsLSPEditorAvailable_ProjectSupported_ReturnsTrue()
3630
Assert.True(result);
3731
}
3832

39-
[Fact]
33+
[UIFact]
4034
public void IsLSPEditorAvailable_LegacyEditorEnabled_ReturnsFalse()
4135
{
4236
// Arrange
43-
var logger = GetRazorLogger();
44-
var featureDetector = new TestLSPEditorFeatureDetector(logger)
37+
using var activityLog = GetRazorActivityLog();
38+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog)
4539
{
4640
UseLegacyEditor = true,
4741
ProjectSupportsLSPEditorValue = true,
@@ -54,12 +48,12 @@ public void IsLSPEditorAvailable_LegacyEditorEnabled_ReturnsFalse()
5448
Assert.False(result);
5549
}
5650

57-
[Fact]
51+
[UIFact]
5852
public void IsLSPEditorAvailable_IsVSRemoteClient_ReturnsTrue()
5953
{
6054
// Arrange
61-
var logger = GetRazorLogger();
62-
var featureDetector = new TestLSPEditorFeatureDetector(logger)
55+
using var activityLog = GetRazorActivityLog();
56+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog)
6357
{
6458
IsVSRemoteClientValue = true,
6559
ProjectSupportsLSPEditorValue = true,
@@ -72,12 +66,12 @@ public void IsLSPEditorAvailable_IsVSRemoteClient_ReturnsTrue()
7266
Assert.True(result);
7367
}
7468

75-
[Fact]
69+
[UIFact]
7670
public void IsLSPEditorAvailable_UnsupportedProject_ReturnsFalse()
7771
{
7872
// Arrange
79-
var logger = GetRazorLogger();
80-
var featureDetector = new TestLSPEditorFeatureDetector(logger)
73+
using var activityLog = GetRazorActivityLog();
74+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog)
8175
{
8276
ProjectSupportsLSPEditorValue = false,
8377
};
@@ -89,12 +83,12 @@ public void IsLSPEditorAvailable_UnsupportedProject_ReturnsFalse()
8983
Assert.False(result);
9084
}
9185

92-
[Fact]
86+
[UIFact]
9387
public void IsRemoteClient_VSRemoteClient_ReturnsTrue()
9488
{
9589
// Arrange
96-
var logger = GetRazorLogger();
97-
var featureDetector = new TestLSPEditorFeatureDetector(logger)
90+
using var activityLog = GetRazorActivityLog();
91+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog)
9892
{
9993
IsVSRemoteClientValue = true,
10094
};
@@ -106,12 +100,12 @@ public void IsRemoteClient_VSRemoteClient_ReturnsTrue()
106100
Assert.True(result);
107101
}
108102

109-
[Fact]
103+
[UIFact]
110104
public void IsRemoteClient_LiveShareGuest_ReturnsTrue()
111105
{
112106
// Arrange
113-
var logger = GetRazorLogger();
114-
var featureDetector = new TestLSPEditorFeatureDetector(logger)
107+
using var activityLog = GetRazorActivityLog();
108+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog)
115109
{
116110
IsLiveShareGuestValue = true,
117111
};
@@ -123,12 +117,12 @@ public void IsRemoteClient_LiveShareGuest_ReturnsTrue()
123117
Assert.True(result);
124118
}
125119

126-
[Fact]
120+
[UIFact]
127121
public void IsRemoteClient_UnknownEnvironment_ReturnsFalse()
128122
{
129123
// Arrange
130-
var logger = GetRazorLogger();
131-
var featureDetector = new TestLSPEditorFeatureDetector(logger);
124+
using var activityLog = GetRazorActivityLog();
125+
var featureDetector = new TestLSPEditorFeatureDetector(activityLog);
132126

133127
// Act
134128
var result = featureDetector.IsRemoteClient();
@@ -137,22 +131,24 @@ public void IsRemoteClient_UnknownEnvironment_ReturnsFalse()
137131
Assert.False(result);
138132
}
139133

140-
private static RazorLogger GetRazorLogger()
134+
private RazorActivityLog GetRazorActivityLog()
141135
{
142-
var mock = new Mock<RazorLogger>(MockBehavior.Strict);
143-
mock.Setup(l => l.LogVerbose(It.IsAny<string>()));
136+
var vsActivityLogMock = new StrictMock<IVsActivityLog>();
137+
vsActivityLogMock
138+
.Setup(x => x.LogEntry(It.IsAny<uint>(), "Razor", It.IsAny<string>()))
139+
.Returns(VSConstants.S_OK);
144140

145-
return mock.Object;
141+
var serviceProviderMock = new StrictMock<IAsyncServiceProvider>();
142+
serviceProviderMock
143+
.Setup(x => x.GetServiceAsync(typeof(SVsActivityLog)))
144+
.ReturnsAsync(vsActivityLogMock.Object);
145+
146+
return new RazorActivityLog(serviceProviderMock.Object, JoinableTaskContext);
146147
}
147148

148-
#pragma warning disable CS0618 // Type or member is obsolete (Test constructor)
149-
private class TestLSPEditorFeatureDetector : VisualStudioLSPEditorFeatureDetector
149+
private class TestLSPEditorFeatureDetector(RazorActivityLog activityLog)
150+
: VisualStudioLSPEditorFeatureDetector(projectCapabilityResolver: null!, activityLog)
150151
{
151-
public TestLSPEditorFeatureDetector(RazorLogger logger)
152-
: base(projectCapabilityResolver: null, logger)
153-
{
154-
}
155-
156152
public bool UseLegacyEditor { get; set; }
157153

158154
public bool IsLiveShareGuestValue { get; set; }
@@ -171,7 +167,6 @@ public TestLSPEditorFeatureDetector(RazorLogger logger)
171167

172168
private protected override bool IsVSRemoteClient() => IsVSRemoteClientValue;
173169

174-
private protected override bool ProjectSupportsLSPEditor(string documentMoniker, IVsHierarchy hierarchy) => ProjectSupportsLSPEditorValue;
170+
private protected override bool ProjectSupportsLSPEditor(string documentMoniker, IVsHierarchy? hierarchy) => ProjectSupportsLSPEditorValue;
175171
}
176-
#pragma warning restore CS0618 // Type or member is obsolete (Test constructor)
177172
}

0 commit comments

Comments
 (0)