using System.Net; using System.Net.Http.Json; using System.Text.Json; using Microsoft.AspNetCore.Mvc.Testing; using Microsoft.Extensions.Configuration; namespace MeetingAssistant.Tests; public sealed class MeetingWorkflowDiagnosticEndpointTests { [Fact] public async Task ReloadEndpointReloadsAutomationRulesPathFromConfigurationFile() { var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(root); var configPath = Path.Combine(root, "workflow-config.json"); var firstRulesPath = Path.Combine(root, "first-rules.yaml"); var secondRulesPath = Path.Combine(root, "second-rules.yaml"); await File.WriteAllTextAsync(configPath, CreateConfigJson(firstRulesPath)); await using var factory = new WebApplicationFactory() .WithWebHostBuilder(builder => { builder.ConfigureAppConfiguration((_, configuration) => { configuration.AddJsonFile(configPath, optional: false, reloadOnChange: false); configuration.AddInMemoryCollection(new Dictionary { ["MeetingAssistant:FunAsr:Backend:Enabled"] = "false" }); }); }); using var client = factory.CreateClient(); using var firstResponse = await client.PostAsync("/diagnostics/workflow/reload", null); var firstBody = await firstResponse.Content.ReadFromJsonAsync(); await File.WriteAllTextAsync(configPath, CreateConfigJson(secondRulesPath)); using var secondResponse = await client.PostAsync("/diagnostics/workflow/reload", null); var secondBody = await secondResponse.Content.ReadFromJsonAsync(); Assert.Equal(HttpStatusCode.OK, firstResponse.StatusCode); Assert.Equal(firstRulesPath, firstBody?.RulesPath); Assert.Equal(HttpStatusCode.OK, secondResponse.StatusCode); Assert.Equal(secondRulesPath, secondBody?.RulesPath); } private static string CreateConfigJson(string rulesPath) { return JsonSerializer.Serialize(new { MeetingAssistant = new { Automation = new { RulesPath = rulesPath } } }); } private sealed record WorkflowReloadResponse(string? RulesPath); }