Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,16 @@ private void SetContentRoot(IWebHostBuilder builder)
}
}

private static string GetContentRootFromFile(string file)
private static string? GetContentRootFromFile(string file)
{
var data = JsonSerializer.Deserialize<IDictionary<string, string>>(File.ReadAllBytes(file))!;
var key = typeof(TEntryPoint).Assembly.GetName().FullName;

// If the `ContentRoot` is not provided in the app manifest, then return null
// and fallback to setting the content root relative to the entrypoint's assembly.
if (!data.TryGetValue(key, out var contentRoot))
{
throw new KeyNotFoundException($"Could not find content root for project '{key}' in test manifest file '{file}'");
return null;
}

return (contentRoot == "~") ? AppContext.BaseDirectory : contentRoot;
Expand Down