Skip to content

Commit f44a784

Browse files
Copilotjaviercn
andcommitted
Address feedback: revert unnecessary changes and fix test to use proper project structure
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
1 parent dec378b commit f44a784

22 files changed

+119
-99
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,12 @@ Integration with static web assets:
233233

234234
<ItemGroup>
235235
<_ScopedCssAppBundleStaticWebAssetCandidate Include="$(_ScopedCssOutputPath)">
236-
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' == 'true'">$([System.Uri]::EscapeDataString($(PackageId)))#[.{fingerprint}]?.styles.css</RelativePath>
237-
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' != 'true'">$([System.Uri]::EscapeDataString($(PackageId))).styles.css</RelativePath>
236+
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' == 'true'">$(PackageId)#[.{fingerprint}]?.styles.css</RelativePath>
237+
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' != 'true'">$(PackageId).styles.css</RelativePath>
238238
</_ScopedCssAppBundleStaticWebAssetCandidate>
239239
<_ScopedCssProjectBundleStaticWebAssetCandidate Include="$(_ScopedCssProjectOutputPath)">
240-
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' == 'true'">$([System.Uri]::EscapeDataString($(PackageId)))#[.{fingerprint}]!.bundle.scp.css</RelativePath>
241-
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' != 'true'">$([System.Uri]::EscapeDataString($(PackageId))).bundle.scp.css</RelativePath>
240+
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' == 'true'">$(PackageId)#[.{fingerprint}]!.bundle.scp.css</RelativePath>
241+
<RelativePath Condition="'$(StaticWebAssetFingerprintingEnabled)' != 'true'">$(PackageId).bundle.scp.css</RelativePath>
242242
</_ScopedCssProjectBundleStaticWebAssetCandidate>
243243
<!-- Adds a Link: <bundle1>; rel="preload", <bundle2>; rel="preload", <bundle3>; rel="preload" -->
244244
<_AddLinkHeaderToAppBundle Include="Append" Condition="'@(_ResolvedScopedCssBundleEndpoints)' != ''">

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Moq;
1414

1515
namespace Microsoft.NET.Sdk.StaticWebAssets.Tests;
16-
1716
public class ComputeStaticWebAssetsTargetPathsTest
1817
{
1918
[Fact]

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ public void Build_GeneratesManifestWhenItFindsALibrary()
3131
{
3232
var testAsset = "RazorComponentApp";
3333
var projectDirectory = CreateAspNetSdkTestAsset(testAsset)
34-
.WithProjectChanges(p =>
35-
{
36-
var fingerprintContent = p.Descendants()
37-
.SingleOrDefault(e => e.Name.LocalName == "StaticWebAssetsFingerprintContent");
38-
fingerprintContent.Value = "true";
39-
});
34+
.WithProjectChanges(p => {
35+
var fingerprintContent = p.Descendants()
36+
.SingleOrDefault(e => e.Name.LocalName == "StaticWebAssetsFingerprintContent");
37+
fingerprintContent.Value = "true";
38+
});
4039

4140
Directory.CreateDirectory(Path.Combine(projectDirectory.TestRoot, "wwwroot"));
4241
File.WriteAllText(Path.Combine(projectDirectory.TestRoot, "wwwroot", "ComponentApp.lib.module.js"), "console.log('Hello world!');");
@@ -90,8 +89,7 @@ public void Publish_PublishesJsModuleBundleBundleToTheRightLocation()
9089
{
9190
var testAsset = "RazorComponentApp";
9291
ProjectDirectory = CreateAspNetSdkTestAsset(testAsset)
93-
.WithProjectChanges(p =>
94-
{
92+
.WithProjectChanges(p => {
9593
var fingerprintContent = p.Descendants()
9694
.SingleOrDefault(e => e.Name.LocalName == "StaticWebAssetsFingerprintContent");
9795
fingerprintContent.Value = "true";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Microsoft.AspNetCore.StaticWebAssets.Tasks;
55

6-
[assembly: CollectionBehavior(DisableTestParallelization = true)]
6+
[assembly:CollectionBehavior(DisableTestParallelization = true)]
77

88
namespace Microsoft.NET.Sdk.StaticWebAssets.Tests
99
{

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

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,46 @@ public void RegeneratingScopedCss_ForProjectWithReferences()
621621
[Fact]
622622
public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName()
623623
{
624-
var testAsset = "RazorComponentApp";
625-
var projectDirectory = CreateAspNetSdkTestAsset(testAsset);
624+
var testAsset = "RazorAppWithPackageAndP2PReference";
625+
ProjectDirectory = CreateAspNetSdkTestAsset(testAsset);
626626

627-
// Create a CSS file to trigger scoped CSS processing
628-
var cssFile = Path.Combine(projectDirectory.Path, "Components", "Pages", "Index.razor.css");
629-
Directory.CreateDirectory(Path.GetDirectoryName(cssFile));
630-
File.WriteAllText(cssFile, ".test { color: red; }");
627+
// Rename the ClassLibrary project to have non-ASCII characters
628+
var originalLibPath = Path.Combine(ProjectDirectory.Path, "ClassLibrary");
629+
var newLibPath = Path.Combine(ProjectDirectory.Path, "项目");
630+
Directory.Move(originalLibPath, newLibPath);
631+
632+
// Update the project file to set the assembly name and package ID
633+
var libProjectFile = Path.Combine(newLibPath, "ClassLibrary.csproj");
634+
var newLibProjectFile = Path.Combine(newLibPath, "项目.csproj");
635+
File.Move(libProjectFile, newLibProjectFile);
636+
637+
// Add assembly name property to ensure consistent naming
638+
var libProjectContent = File.ReadAllText(newLibProjectFile);
639+
libProjectContent = libProjectContent.Replace("</PropertyGroup>",
640+
" <AssemblyName>项目</AssemblyName>\n <PackageId>项目</PackageId>\n </PropertyGroup>", 1);
641+
File.WriteAllText(newLibProjectFile, libProjectContent);
642+
643+
// Update the main project to reference the renamed library
644+
var mainProjectFile = Path.Combine(ProjectDirectory.Path, "AppWithPackageAndP2PReference", "AppWithPackageAndP2PReference.csproj");
645+
var mainProjectContent = File.ReadAllText(mainProjectFile);
646+
mainProjectContent = mainProjectContent.Replace(@"..\ClassLibrary\ClassLibrary.csproj", @"..\项目\项目.csproj");
647+
File.WriteAllText(mainProjectFile, mainProjectContent);
648+
649+
// Ensure library has scoped CSS
650+
var libCssFile = Path.Combine(newLibPath, "Components", "Component1.razor.css");
651+
if (!File.Exists(libCssFile))
652+
{
653+
Directory.CreateDirectory(Path.GetDirectoryName(libCssFile));
654+
File.WriteAllText(libCssFile, ".test { color: red; }");
655+
}
631656

632-
var build = CreateBuildCommand(projectDirectory);
633-
// Set PackageId to contain non-ASCII characters (Chinese characters meaning "project")
634-
ExecuteCommand(build, "/p:PackageId=项目").Should().Pass();
657+
EnsureLocalPackagesExists();
658+
659+
var restore = CreateRestoreCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
660+
ExecuteCommand(restore).Should().Pass();
661+
662+
var build = CreateBuildCommand(ProjectDirectory, "AppWithPackageAndP2PReference");
663+
ExecuteCommand(build).Should().Pass();
635664

636665
var intermediateOutputPath = build.GetIntermediateDirectory(DefaultTfm, "Debug").ToString();
637666

@@ -643,9 +672,6 @@ public void Build_GeneratesUrlEncodedLinkHeaderForNonAsciiProjectName()
643672

644673
// Verify that the Link header contains URL-encoded characters (%E9%A1%B9%E7%9B%AE is "项目" encoded)
645674
endpointsContent.Should().Contain("%E9%A1%B9%E7%9B%AE");
646-
647-
// Verify it doesn't contain the unencoded characters
648-
endpointsContent.Should().NotContain("项目");
649675
}
650676
}
651677
}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ private bool MatchUncompresedProjectBundlesNoFingerprint(StaticWebAssetEndpoint
8585
Success: true,
8686
Groups: [
8787
var _,
88-
{ Name: "project", Value: "ComponentApp", Success: true, },
89-
{ Name: "fingerprint", Value: "", Success: false },
90-
{ Name: "compress", Value: "", Success: false }
88+
{ Name: "project", Value: "ComponentApp", Success: true, },
89+
{ Name: "fingerprint", Value: "", Success: false },
90+
{ Name: "compress", Value: "", Success: false }
9191
]
9292
};
9393

@@ -96,9 +96,9 @@ private bool MatchCompressedProjectBundlesNoFingerprint(StaticWebAssetEndpoint e
9696
Success: true,
9797
Groups: [
9898
var _,
99-
{ Name: "project", Value: "ComponentApp", Success: true, },
100-
{ Name: "fingerprint", Value: "", Success: false },
101-
{ Name: "compress", Value: var compress, Success: true }
99+
{ Name: "project", Value: "ComponentApp", Success: true, },
100+
{ Name: "fingerprint", Value: "", Success: false },
101+
{ Name: "compress", Value: var compress, Success: true }
102102
]
103103
} && (compress == ".gz" || compress == ".br");
104104

@@ -107,9 +107,9 @@ private bool MatchUncompressedProjectBundlesWithFingerprint(StaticWebAssetEndpoi
107107
Success: true,
108108
Groups: [
109109
var m,
110-
{ Name: "project", Value: "ComponentApp", Success: true, },
111-
{ Name: "fingerprint", Value: var fingerprint, Success: true },
112-
{ Name: "compress", Value: "", Success: false }
110+
{ Name: "project", Value: "ComponentApp", Success: true, },
111+
{ Name: "fingerprint", Value: var fingerprint, Success: true },
112+
{ Name: "compress", Value: "", Success: false }
113113
]
114114
} && fingerprint == ep.EndpointProperties.Single(p => p.Name == "fingerprint").Value;
115115

@@ -118,9 +118,9 @@ private bool MatchCompressedProjectBundlesWithFingerprint(StaticWebAssetEndpoint
118118
Success: true,
119119
Groups: [
120120
var m,
121-
{ Name: "project", Value: "ComponentApp", Success: true, },
122-
{ Name: "fingerprint", Value: var fingerprint, Success: true },
123-
{ Name: "compress", Value: var compress, Success: true }
121+
{ Name: "project", Value: "ComponentApp", Success: true, },
122+
{ Name: "fingerprint", Value: var fingerprint, Success: true },
123+
{ Name: "compress", Value: var compress, Success: true }
124124
]
125125
} && !string.IsNullOrWhiteSpace(fingerprint)
126126
&& (compress == ".gz" || compress == ".br");
@@ -130,9 +130,9 @@ private bool MatchUncompressedAppBundleNoFingerprint(StaticWebAssetEndpoint ep)
130130
Success: true,
131131
Groups: [
132132
var _,
133-
{ Name: "project", Value: "ComponentApp", Success: true, },
134-
{ Name: "fingerprint", Value: "", Success: false },
135-
{ Name: "compress", Value: "", Success: false }
133+
{ Name: "project", Value: "ComponentApp", Success: true, },
134+
{ Name: "fingerprint", Value: "", Success: false },
135+
{ Name: "compress", Value: "", Success: false }
136136
]
137137
};
138138

@@ -141,9 +141,9 @@ private bool MatchCompressedAppBundleNoFingerprint(StaticWebAssetEndpoint ep) =>
141141
Success: true,
142142
Groups: [
143143
var _,
144-
{ Name: "project", Value: "ComponentApp", Success: true, },
145-
{ Name: "fingerprint", Value: "", Success: false },
146-
{ Name: "compress", Value: var compress, Success: true }
144+
{ Name: "project", Value: "ComponentApp", Success: true, },
145+
{ Name: "fingerprint", Value: "", Success: false },
146+
{ Name: "compress", Value: var compress, Success: true }
147147
]
148148
} && (compress == ".gz" || compress == ".br");
149149

@@ -152,9 +152,9 @@ private bool MatchUncompressedAppBundleWithFingerprint(StaticWebAssetEndpoint ep
152152
Success: true,
153153
Groups: [
154154
var m,
155-
{ Name: "project", Value: "ComponentApp", Success: true, },
156-
{ Name: "fingerprint", Value: var fingerprint, Success: true },
157-
{ Name: "compress", Value: "", Success: false }
155+
{ Name: "project", Value: "ComponentApp", Success: true, },
156+
{ Name: "fingerprint", Value: var fingerprint, Success: true },
157+
{ Name: "compress", Value: "", Success: false }
158158
]
159159
} && fingerprint == ep.EndpointProperties.Single(p => p.Name == "fingerprint").Value;
160160

@@ -163,9 +163,9 @@ private bool MatchCompressedAppBundleWithFingerprint(StaticWebAssetEndpoint ep)
163163
Success: true,
164164
Groups: [
165165
var m,
166-
{ Name: "project", Value: "ComponentApp", Success: true, },
167-
{ Name: "fingerprint", Value: var fingerprint, Success: true },
168-
{ Name: "compress", Value: var compress, Success: true }
166+
{ Name: "project", Value: "ComponentApp", Success: true, },
167+
{ Name: "fingerprint", Value: var fingerprint, Success: true },
168+
{ Name: "compress", Value: var compress, Success: true }
169169
]
170170
} && !string.IsNullOrWhiteSpace(fingerprint)
171171
&& (compress == ".gz" || compress == ".br");

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

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

44
#nullable disable
55

6-
using System.Diagnostics;
76
using System.Diagnostics.Metrics;
8-
using System.Globalization;
9-
using System.Net;
7+
using System.Diagnostics;
108
using Microsoft.AspNetCore.StaticWebAssets.Tasks;
119
using Microsoft.Build.Framework;
1210
using Microsoft.Build.Utilities;
1311
using Moq;
1412
using NuGet.Packaging.Core;
13+
using System.Net;
14+
using System.Globalization;
1515

1616
namespace Microsoft.NET.Sdk.StaticWebAssets.Tests;
1717

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void DiscoversPrecompressedAssetsCorrectly()
4444
CopyToOutputDirectory = StaticWebAsset.AssetCopyOptions.Never,
4545
Fingerprint = "uncompressed",
4646
RelatedAsset = string.Empty,
47-
ContentRoot = Path.Combine(Environment.CurrentDirectory, "wwwroot"),
47+
ContentRoot = Path.Combine(Environment.CurrentDirectory,"wwwroot"),
4848
SourceType = StaticWebAsset.SourceTypes.Discovered,
4949
Integrity = "uncompressed-integrity",
5050
AssetRole = StaticWebAsset.AssetRoles.Primary,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ public void FingerprintsContentUsingPatternsWhenMoreThanOneExtension(string file
217217
asset.GetMetadata(nameof(StaticWebAsset.OriginalItemSpec)).Should().Be(Path.Combine("wwwroot", fileName));
218218
}
219219

220-
[Fact]
221-
[Trait("Category", "FingerprintIdentity")]
222-
public void ComputesIdentity_UsingFingerprintPattern_ForComputedAssets_WhenIdentityNeedsComputation()
220+
[Fact]
221+
[Trait("Category", "FingerprintIdentity")]
222+
public void ComputesIdentity_UsingFingerprintPattern_ForComputedAssets_WhenIdentityNeedsComputation()
223223
{
224224
// Arrange: simulate a packaged asset (outside content root) with a RelativePath inside the app
225225
var errorMessages = new List<string>();
@@ -251,7 +251,7 @@ public void ComputesIdentity_UsingFingerprintPattern_ForComputedAssets_WhenIdent
251251
})
252252
],
253253
// No RelativePathPattern, we trigger the branch that synthesizes identity under content root.
254-
FingerprintPatterns = [new TaskItem("Js", new Dictionary<string, string> { { "Pattern", "*.js" }, { "Expression", "#[.{fingerprint}]!" } })],
254+
FingerprintPatterns = [ new TaskItem("Js", new Dictionary<string,string>{{"Pattern","*.js"},{"Expression","#[.{fingerprint}]!"}})],
255255
FingerprintCandidates = true,
256256
SourceType = "Computed",
257257
SourceId = "Client",

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Moq;
1010

1111
namespace Microsoft.NET.Sdk.StaticWebAssets.Tests.StaticWebAssets;
12-
1312
public class FilterStaticWebAssetEndpointsTest
1413
{
1514
[Fact]

0 commit comments

Comments
 (0)