|
| 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.IO; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using EmptyFiles; |
| 7 | +using Microsoft.Extensions.AI.Templates.IntegrationTests; |
| 8 | +using Microsoft.Extensions.AI.Templates.Tests; |
| 9 | +using Microsoft.Extensions.Logging; |
| 10 | +using Microsoft.TemplateEngine.Authoring.TemplateVerifier; |
| 11 | +using Microsoft.TemplateEngine.TestHelper; |
| 12 | +using Xunit; |
| 13 | +using Xunit.Abstractions; |
| 14 | + |
| 15 | +namespace Microsoft.Extensions.AI.Templates.InegrationTests; |
| 16 | + |
| 17 | +public class AichatwebTemplatesTests : TestBase |
| 18 | +{ |
| 19 | + private readonly ILogger _log; |
| 20 | + |
| 21 | + public AichatwebTemplatesTests(ITestOutputHelper log) |
| 22 | + { |
| 23 | +#pragma warning disable CA2000 // Dispose objects before losing scope |
| 24 | + _log = new XunitLoggerProvider(log).CreateLogger("TestRun"); |
| 25 | +#pragma warning restore CA2000 // Dispose objects before losing scope |
| 26 | + } |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public async Task BasicTest() |
| 30 | + { |
| 31 | + string workingDir = TestUtils.CreateTemporaryFolder(); |
| 32 | + string templateShortName = "aichatweb"; |
| 33 | + |
| 34 | + // Get the template location |
| 35 | + string templateLocation = Path.Combine(TemplateFeedLocation, "Microsoft.Extensions.AI.Templates", "src", "ChatWithCustomData"); |
| 36 | + |
| 37 | + // Treat *.in files as text, see https://github.com/VerifyTests/EmptyFiles#istext |
| 38 | + FileExtensions.AddTextExtension(".in"); |
| 39 | + |
| 40 | + TemplateVerifierOptions options = new TemplateVerifierOptions(templateName: templateShortName) |
| 41 | + { |
| 42 | + TemplatePath = templateLocation, |
| 43 | + SnapshotsDirectory = "Snapshots", |
| 44 | + OutputDirectory = workingDir, |
| 45 | + DoNotPrependCallerMethodNameToScenarioName = true, |
| 46 | + ScenarioName = "Basic", |
| 47 | + } |
| 48 | + .WithCustomScrubbers( |
| 49 | + ScrubbersDefinition.Empty.AddScrubber((path, content) => |
| 50 | + { |
| 51 | + string filePath = path.UnixifyDirSeparators(); |
| 52 | + if (filePath.EndsWith("aichatweb/ChatWithCustomData.Web/ChatWithCustomData.Web.csproj") || |
| 53 | + filePath.EndsWith("aichatweb/aichatweb.csproj") || |
| 54 | + filePath.EndsWith("aichatweb/aichatweb.csproj.in")) |
| 55 | + { |
| 56 | + content.ScrubByRegex("<UserSecretsId>(.*)<\\/UserSecretsId>", "<UserSecretsId>secret</UserSecretsId>"); |
| 57 | + } |
| 58 | + |
| 59 | + if (filePath.EndsWith("aichatweb/Properties/launchSettings.json")) |
| 60 | + { |
| 61 | + content.ScrubByRegex("(http(s?):\\/\\/localhost)\\:(\\d*)", "$1:9999"); |
| 62 | + } |
| 63 | + })); |
| 64 | + |
| 65 | + VerificationEngine engine = new VerificationEngine(_log); |
| 66 | + await engine.Execute(options); |
| 67 | + |
| 68 | +#pragma warning disable CA1031 // Do not catch general exception types |
| 69 | + try |
| 70 | + { |
| 71 | + Directory.Delete(workingDir, recursive: true); |
| 72 | + } |
| 73 | + catch |
| 74 | + { |
| 75 | + /* don't care */ |
| 76 | + } |
| 77 | +#pragma warning restore CA1031 // Do not catch general exception types |
| 78 | + } |
| 79 | +} |
0 commit comments