Skip to content

Commit c2ead76

Browse files
committed
Fix random csproj generation
1 parent 6036bb1 commit c2ead76

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

test/Azure.Functions.Sdk.Tests/Integration/MSBuildSdkTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected virtual void Dispose(bool disposing)
5454
}
5555

5656
// Ensure this starts with a non-numeric character to be a valid csproj name.
57-
protected string GetTempCsproj() => "azfunc.test." + _temp.GetRandomFile(ext: ".csproj");
57+
protected string GetTempCsproj() => _temp.GetRandomCsproj();
5858

5959
private static string GetArtifactsPath()
6060
{

test/Azure.Functions.Sdk.Tests/Tasks/Extensions/ResolveExtensionPackagesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static ResolveExtensionPackages CreateTask(
156156
private string RestoreProject(Action<ProjectCreator>? configure = null)
157157
{
158158
ProjectCreator project = ProjectCreator.Templates.NetCoreProject(
159-
path: _temp.GetRandomFile(ext: ".csproj"), targetFramework: "net8.0", configure: configure);
159+
path: _temp.GetRandomCsproj(), targetFramework: "net8.0", configure: configure);
160160

161161
project.Restore().Should().BeSuccessful(); // use assertion to throw on failure.
162162
project.TryGetPropertyValue("ProjectAssetsFile", out string? value);

test/Azure.Functions.Sdk.Tests/TempDirectory.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ public TempDirectory()
1515

1616
public string Path { get; }
1717

18-
public string GetRandomFile(string? ext = null)
18+
// GetRandomFileName() might start with numbers. Prefixing az.func_ to ensure it's a valid C# identifier.
19+
public string GetRandomCsproj() => GetRandomFile(prefix: "az.func_", ext: ".csproj");
20+
21+
public string GetRandomFile(string? prefix = null, string? ext = null)
1922
{
20-
string path = IOPath.Combine(Path, IOPath.GetRandomFileName());
23+
string fileName = $"{prefix}{IOPath.GetRandomFileName()}";
24+
string path = IOPath.Combine(Path, fileName);
2125
if (!string.IsNullOrEmpty(ext))
2226
{
2327
if (!ext.StartsWith('.'))

0 commit comments

Comments
 (0)