Skip to content

Commit 8555444

Browse files
committed
fix test
1 parent 21a64d7 commit 8555444

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/StaticWebAssetsSdk/Targets/Microsoft.NET.Sdk.StaticWebAssets.ScopedCss.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ Integration with static web assets:
244244
<_AddLinkHeaderToAppBundle Include="Append" Condition="'@(_ResolvedScopedCssBundleEndpoints)' != ''">
245245
<UpdateTarget>Header</UpdateTarget>
246246
<Name>Link</Name>
247-
<Value>@(_ResolvedScopedCssBundleEndpoints->'&lt;$([System.Uri]::EscapeDataString(%(Identity)))&gt;; rel="preload"; as="style"', ', ')</Value>
247+
<Value>@(_ResolvedScopedCssBundleEndpoints->'&lt;%(Identity)&gt;; rel="preload"; as="style"', ', ')</Value>
248248
</_AddLinkHeaderToAppBundle>
249249
</ItemGroup>
250250

test/Microsoft.NET.Sdk.StaticWebAssets.Tests/ScopedCssIntegrationTests.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable disable
55

6+
using System.Text.Json;
67
using System.Text.RegularExpressions;
78
using Microsoft.AspNetCore.StaticWebAssets.Tasks;
89

@@ -625,12 +626,12 @@ public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName()
625626
ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
626627

627628
// Rename the ClassLibrary project to have non-ASCII characters
628-
var originalLibPath = Path.Combine(ProjectDirectory.Path, "ClassLibrary");
629+
var originalLibPath = Path.Combine(ProjectDirectory.Path, "AnotherClassLib");
629630
var newLibPath = Path.Combine(ProjectDirectory.Path, "项目");
630631
Directory.Move(originalLibPath, newLibPath);
631632

632633
// Update the project file to set the assembly name and package ID
633-
var libProjectFile = Path.Combine(newLibPath, "ClassLibrary.csproj");
634+
var libProjectFile = Path.Combine(newLibPath, "AnotherClassLib.csproj");
634635
var newLibProjectFile = Path.Combine(newLibPath, "项目.csproj");
635636
File.Move(libProjectFile, newLibProjectFile);
636637

@@ -649,11 +650,11 @@ public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName()
649650
// Update the main project to reference the renamed library
650651
var mainProjectFile = Path.Combine(ProjectDirectory.Path, "AppWithPackageAndP2PReference", "AppWithPackageAndP2PReference.csproj");
651652
var mainProjectContent = File.ReadAllText(mainProjectFile);
652-
mainProjectContent = mainProjectContent.Replace(@"..\ClassLibrary\ClassLibrary.csproj", @"..\项目\项目.csproj");
653+
mainProjectContent = mainProjectContent.Replace(@"..\AnotherClassLib\AnotherClassLib.csproj", @"..\项目\项目.csproj");
653654
File.WriteAllText(mainProjectFile, mainProjectContent);
654655

655656
// Ensure library has scoped CSS
656-
var libCssFile = Path.Combine(newLibPath, "Components", "Component1.razor.css");
657+
var libCssFile = Path.Combine(newLibPath, "Views", "Shared", "Index.cshtml.css");
657658
if (!File.Exists(libCssFile))
658659
{
659660
Directory.CreateDirectory(Path.GetDirectoryName(libCssFile));
@@ -675,9 +676,14 @@ public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName()
675676
new FileInfo(endpointsFile).Should().Exist();
676677

677678
var endpointsContent = File.ReadAllText(endpointsFile);
679+
var json = JsonSerializer.Deserialize<StaticWebAssetEndpointsManifest>(endpointsContent, new JsonSerializerOptions(JsonSerializerDefaults.Web));
678680

679-
// Verify that the Link header contains URL-encoded characters (%E9%A1%B9%E7%9B%AE is "项目" encoded)
680-
endpointsContent.Should().Contain("%E9%A1%B9%E7%9B%AE");
681+
var styles = json.Endpoints.Where(e => e.Route.EndsWith("styles.css"));
682+
683+
foreach (var styleEndpoint in styles)
684+
{
685+
styleEndpoint.ResponseHeaders.Should().Contain(h => h.Name.Equals("Link", StringComparison.OrdinalIgnoreCase) && h.Value.Contains("%E9%A1%B9%E7%9B%AE"));
686+
}
681687
}
682688
}
683689
}

0 commit comments

Comments
 (0)