diff --git a/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs b/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs index f9b0bfe05..39a32a450 100644 --- a/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs +++ b/DevProxy.Integration.Tests/GenerationPluginsIntegrationTests.cs @@ -11,6 +11,7 @@ using DevProxy.Abstractions.Proxy.Http; using DevProxy.Abstractions.Utils; using DevProxy.Plugins.Generation; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Xunit; @@ -217,9 +218,10 @@ public async Task OpenApiSpecGenerator_WritesSpec() [Fact] public async Task TypeSpecGenerator_WritesSpec() { + var logger = new MessageCapturingLogger(); var plugin = new TypeSpecGeneratorPlugin( TestDefaults.HttpClient, - NullLogger.Instance, + logger, Watch, new DisabledLanguageModelClient(), new TestProxyConfiguration(), @@ -233,10 +235,30 @@ public async Task TypeSpecGenerator_WritesSpec() ((Dictionary)args.GlobalData[ProxyUtils.ReportsKey])[plugin.Name]); Assert.NotEmpty(report); Assert.NotEmpty(dir.GetFiles("*.tsp")); + Assert.Contains(logger.Messages, m => m.StartsWith("Writing TypeSpec file to ", StringComparison.Ordinal)); + Assert.Contains(logger.Messages, m => m.StartsWith("Created TypeSpec file ", StringComparison.Ordinal)); + Assert.DoesNotContain(logger.Messages, m => m.Contains("OpenAPI", StringComparison.Ordinal)); } finally { dir.Delete(recursive: true); } } + + private sealed class MessageCapturingLogger : ILogger + { + public List Messages { get; } = []; + + public IDisposable? BeginScope(TState state) where TState : notnull => null; + + public bool IsEnabled(LogLevel logLevel) => true; + + public void Log( + LogLevel logLevel, + EventId eventId, + TState state, + Exception? exception, + Func formatter) => + Messages.Add(formatter(state, exception)); + } } diff --git a/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs b/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs index a89cb747e..5731ac562 100644 --- a/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs +++ b/DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs @@ -115,12 +115,12 @@ request.Method is null || cancellationToken.ThrowIfCancellationRequested(); var fileName = $"{typeSpecFile.Name}-{DateTime.Now:yyyyMMddHHmmss}.tsp"; - Logger.LogDebug("Writing OpenAPI spec to {FileName}...", fileName); + Logger.LogDebug("Writing TypeSpec file to {FileName}...", fileName); await File.WriteAllTextAsync(fileName, typeSpecFile.ToString(), cancellationToken); generatedTypeSpecFiles.Add(typeSpecFile.Service.Servers.First().Url, fileName); - Logger.LogInformation("Created OpenAPI spec file {FileName}", fileName); + Logger.LogInformation("Created TypeSpec file {FileName}", fileName); } StoreReport(new TypeSpecGeneratorPluginReport(