Skip to content

Commit a71ffcc

Browse files
committed
Test templates
1 parent 29c6180 commit a71ffcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+18114
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TestResult.xml
5050

5151
# VERIFY
5252
*.received.*
53+
**/*.received/
5354

5455
# Build Results of an ATL Project
5556
[Dd]ebugPS/

eng/packages/TestOnly.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<PackageVersion Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
1515
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="9.0.0" />
1616
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="$(MicrosoftMLTokenizersVersion)" />
17+
<PackageVersion Include="Microsoft.TemplateEngine.Authoring.TemplateVerifier" Version="9.0.201" />
18+
<PackageVersion Include="Microsoft.TemplateEngine.TestHelper" Version="9.0.200-rtm.25066.4" />
1719
<PackageVersion Include="Moq.AutoMock" Version="3.1.0" />
1820
<PackageVersion Include="Moq" Version="4.18.4" />
1921
<PackageVersion Include="OpenTelemetry.Exporter.InMemory" Version="1.9.0" />

scripts/Slngen.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ param (
6464
[Parameter(Mandatory = $false, HelpMessage="Enables use of folders.")]
6565
[switch]$Folders = $false,
6666
[Parameter(Mandatory = $false, HelpMessage="Path to exclude from search for project files. Must be repo root folder based.")]
67-
[string[]]$ExcludePaths = @('src\Tools\MutationTesting\samples\', 'src\Templates\templates'),
67+
[string[]]$ExcludePaths = @('src\Tools\MutationTesting\samples\', 'src\Templates\templates', 'test\**\Snapshots'),
6868
[Parameter(Mandatory = $false, HelpMessage="Don't launch Visual Studio.")]
6969
[switch]$NoLaunch = $false,
7070
[Parameter(Mandatory = $false, HelpMessage="Minimizes console output.")]
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>Unit tests for Microsoft.Extensions.AI.Templates.</Description>
5+
6+
<!--
7+
warning NU1504: Duplicate 'PackageReference' items found.
8+
Remove the duplicate items or use the Update functionality to ensure a consistent restore behavior.
9+
The duplicate 'PackageReference' items are: Verify.Xunit , Verify.Xunit ; FluentAssertions , FluentAssertions .
10+
-->
11+
<NoWarn>$(NoWarn);NU1504</NoWarn>
12+
</PropertyGroup>
13+
14+
<PropertyGroup>
15+
<NoWarn>$(NoWarn);CA1063;CA1861;CA2201;VSTHRD003;S104;S125;S2699</NoWarn>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="Microsoft.TemplateEngine.Authoring.TemplateVerifier" />
20+
<PackageReference Include="Microsoft.TemplateEngine.TestHelper" />
21+
<PackageReference Include="Verify.Xunit" VersionOverride="25.0.2" />
22+
<PackageReference Include="FluentAssertions" VersionOverride=" 6.12.0" />
23+
<PackageReference Include="xunit.extensibility.execution" VersionOverride="2.9.0" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Compile Remove="Snapshots\**\*.*" />
28+
<None Include="Snapshots\**\*.*" />
29+
</ItemGroup>
30+
31+
</Project>
32+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="utf-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<base href="/" />
8+
<link rel="stylesheet" href="@Assets["app.css"]" />
9+
<link rel="stylesheet" href="@Assets["aichatweb.styles.css"]" />
10+
<ImportMap />
11+
<HeadOutlet @rendermode="@renderMode" />
12+
</head>
13+
14+
<body>
15+
<Routes @rendermode="@renderMode" />
16+
<script src="@Assets["app.js"]" type="module"></script>
17+
<script src="@Assets["_framework/blazor.web.js"]"></script>
18+
</body>
19+
20+
</html>
21+
22+
@code {
23+
private readonly IComponentRenderMode renderMode = new InteractiveServerRenderMode(prerender: false);
24+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Used under CC0 license */
2+
3+
.lds-ellipsis {
4+
color: #666;
5+
animation: fade-in 1s;
6+
}
7+
8+
@keyframes fade-in {
9+
0% {
10+
opacity: 0;
11+
}
12+
13+
100% {
14+
opacity: 1;
15+
}
16+
}
17+
18+
.lds-ellipsis,
19+
.lds-ellipsis div {
20+
box-sizing: border-box;
21+
}
22+
23+
.lds-ellipsis {
24+
margin: auto;
25+
display: block;
26+
position: relative;
27+
width: 80px;
28+
height: 80px;
29+
}
30+
31+
.lds-ellipsis div {
32+
position: absolute;
33+
top: 33.33333px;
34+
width: 10px;
35+
height: 10px;
36+
border-radius: 50%;
37+
background: currentColor;
38+
animation-timing-function: cubic-bezier(0, 1, 1, 0);
39+
}
40+
41+
.lds-ellipsis div:nth-child(1) {
42+
left: 8px;
43+
animation: lds-ellipsis1 0.6s infinite;
44+
}
45+
46+
.lds-ellipsis div:nth-child(2) {
47+
left: 8px;
48+
animation: lds-ellipsis2 0.6s infinite;
49+
}
50+
51+
.lds-ellipsis div:nth-child(3) {
52+
left: 32px;
53+
animation: lds-ellipsis2 0.6s infinite;
54+
}
55+
56+
.lds-ellipsis div:nth-child(4) {
57+
left: 56px;
58+
animation: lds-ellipsis3 0.6s infinite;
59+
}
60+
61+
@keyframes lds-ellipsis1 {
62+
0% {
63+
transform: scale(0);
64+
}
65+
66+
100% {
67+
transform: scale(1);
68+
}
69+
}
70+
71+
@keyframes lds-ellipsis3 {
72+
0% {
73+
transform: scale(1);
74+
}
75+
76+
100% {
77+
transform: scale(0);
78+
}
79+
}
80+
81+
@keyframes lds-ellipsis2 {
82+
0% {
83+
transform: translate(0, 0);
84+
}
85+
86+
100% {
87+
transform: translate(24px, 0);
88+
}
89+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@inherits LayoutComponentBase
2+
3+
@Body
4+
5+
<div id="blazor-error-ui" data-nosnippet>
6+
An unhandled error has occurred.
7+
<a href="." class="reload">Reload</a>
8+
<span class="dismiss">🗙</span>
9+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#blazor-error-ui {
2+
color-scheme: light only;
3+
background: lightyellow;
4+
bottom: 0;
5+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
6+
box-sizing: border-box;
7+
display: none;
8+
left: 0;
9+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
10+
position: fixed;
11+
width: 100%;
12+
z-index: 1000;
13+
}
14+
15+
#blazor-error-ui .dismiss {
16+
cursor: pointer;
17+
position: absolute;
18+
right: 0.75rem;
19+
top: 0.5rem;
20+
}

0 commit comments

Comments
 (0)