|
| 1 | +using Microsoft.AspNetCore.Builder; |
| 2 | +using Microsoft.AspNetCore.Hosting; |
| 3 | +using Microsoft.Extensions.Logging; |
| 4 | +using NpgsqlRest.Mcp; |
| 5 | + |
| 6 | +namespace NpgsqlRestTests.Setup; |
| 7 | + |
| 8 | +[CollectionDefinition("McpFeatureWarnFixture")] |
| 9 | +public class McpFeatureWarnFixtureCollection : ICollectionFixture<McpFeatureWarnTestFixture> { } |
| 10 | + |
| 11 | +/// <summary> |
| 12 | +/// Fixture for the MCP non-applicable-feature warning. The isolated <c>mcp_warn</c> schema holds a |
| 13 | +/// routine that is annotated <c>@mcp</c> but is also a <c>login</c> endpoint — a feature that does not |
| 14 | +/// translate to an MCP tool call. The plugin should log a warning at endpoint-creation time. Logs are |
| 15 | +/// captured so the test can assert the warning fired. |
| 16 | +/// </summary> |
| 17 | +public class McpFeatureWarnTestFixture : IDisposable |
| 18 | +{ |
| 19 | + private readonly WebApplication _app; |
| 20 | + private readonly LogCollector _logCollector = new(); |
| 21 | + |
| 22 | + public IReadOnlyList<LogEntry> StartupLogs { get; } |
| 23 | + |
| 24 | + public McpFeatureWarnTestFixture() |
| 25 | + { |
| 26 | + Database.Create(); |
| 27 | + var connectionString = Database.CreateAdditional("mcp_feature_warn_test"); |
| 28 | + |
| 29 | + var builder = WebApplication.CreateBuilder(); |
| 30 | + builder.WebHost.UseUrls("http://127.0.0.1:0"); |
| 31 | + builder.Logging.ClearProviders(); |
| 32 | + builder.Logging.SetMinimumLevel(LogLevel.Trace); |
| 33 | + builder.Logging.AddProvider(new CollectingLoggerProvider(_logCollector)); |
| 34 | + _app = builder.Build(); |
| 35 | + |
| 36 | + _app.UseNpgsqlRest(new NpgsqlRestOptions(connectionString) |
| 37 | + { |
| 38 | + IncludeSchemas = ["mcp_warn"], |
| 39 | + CommentsMode = CommentsMode.OnlyAnnotated, |
| 40 | + EndpointCreateHandlers = [new Mcp(new McpOptions { Enabled = true })] |
| 41 | + }); |
| 42 | + |
| 43 | + _app.StartAsync().GetAwaiter().GetResult(); |
| 44 | + StartupLogs = _logCollector.Snapshot(); |
| 45 | + } |
| 46 | + |
| 47 | +#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize |
| 48 | + public void Dispose() |
| 49 | +#pragma warning restore CA1816 // Dispose methods should call SuppressFinalize |
| 50 | + { |
| 51 | + _app.StopAsync().GetAwaiter().GetResult(); |
| 52 | + _app.DisposeAsync().GetAwaiter().GetResult(); |
| 53 | + } |
| 54 | +} |
0 commit comments