Skip to content

Commit

Permalink
Fix tests errors
Browse files Browse the repository at this point in the history
  • Loading branch information
v-wuzhai committed Dec 9, 2024
1 parent bf3c488 commit ecd3d95
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TestProject([CallerMemberName] string? name = null)

public bool UseArtifactsOutput { get; set; }

public List<TestProject> ReferencedProjects { get; } = new List<TestProject>();
public List<TestProject?> ReferencedProjects { get; } = new List<TestProject?>();

public List<string> References { get; } = new List<string>();

Expand Down Expand Up @@ -303,7 +303,7 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder,
foreach (var referencedProject in ReferencedProjects)
{
projectReferenceItemGroup.Add(new XElement(ns + "ProjectReference",
new XAttribute("Include", $"../{referencedProject.Name}/{referencedProject.Name}.csproj")));
new XAttribute("Include", $"../{referencedProject?.Name}/{referencedProject?.Name}.csproj")));
}
}

Expand Down Expand Up @@ -419,7 +419,7 @@ static void Main(string[] args)

foreach (var dependency in ReferencedProjects)
{
string? safeDependencyName = dependency.Name?.Replace('.', '_');
string? safeDependencyName = dependency?.Name?.Replace('.', '_');

source += $" Console.WriteLine({safeDependencyName}.{safeDependencyName}Class.Name);" + Environment.NewLine;
source += $" Console.WriteLine({safeDependencyName}.{safeDependencyName}Class.List);" + Environment.NewLine;
Expand Down Expand Up @@ -448,7 +448,7 @@ public class {safeThisName}Class
";
foreach (var dependency in ReferencedProjects)
{
string? safeDependencyName = dependency.Name?.Replace('.', '_');
string? safeDependencyName = dependency?.Name?.Replace('.', '_');

source += $" public string {safeDependencyName}Name {{ get {{ return {safeDependencyName}.{safeDependencyName}Class.Name; }} }}" + Environment.NewLine;
source += $" public List<string> {safeDependencyName}List {{ get {{ return {safeDependencyName}.{safeDependencyName}Class.List; }} }}" + Environment.NewLine;
Expand Down
5 changes: 4 additions & 1 deletion test/Microsoft.NET.TestFramework/TestAssetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ private TestAsset CreateTestProjectsInDirectory(

foreach (var referencedProject in project.ReferencedProjects)
{
projectStack.Push(referencedProject);
if(referencedProject is not null)
{
projectStack.Push(referencedProject);
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/dotnet-watch.Tests/MsBuildFileSetFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ private async Task<EvaluationResult> Evaluate(string projectPath)
return result;
}

private static string GetTestProjectPath(TestAsset target) => Path.Combine(GetTestProjectDirectory(target), target.TestProject.Name + ".csproj");
private static string GetTestProjectPath(TestAsset target) => Path.Combine(GetTestProjectDirectory(target), target.TestProject?.Name + ".csproj");

private static string WriteFile(TestAsset testAsset, string name, string contents = "")
{
Expand All @@ -443,6 +443,6 @@ private static string WriteFile(TestDirectory testAsset, string name, string con
}

private static string GetTestProjectDirectory(TestAsset testAsset)
=> Path.Combine(testAsset.Path, testAsset.TestProject.Name);
=> Path.Combine(testAsset.Path, testAsset.TestProject?.Name ?? string.Empty);
}
}

0 comments on commit ecd3d95

Please sign in to comment.