-
Notifications
You must be signed in to change notification settings - Fork 680
Better malformed launchsettings error #5145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
cc142ff
aa14fef
3568ffa
8586e51
2466723
b6c82f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,6 +14,47 @@ namespace Aspire.Hosting.Tests; | |||||||||||||||||||||||
|
||||||||||||||||||||||||
public class ProjectResourceTests | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||
[Fact] | ||||||||||||||||||||||||
public async Task AddProjectWithInvalidLaunchSettingsShouldThrowSpecificError() | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||
var projectDetails = await PrepareProjectWithMalformedLaunchSettingsAsync(); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
var ex = Assert.Throws<DistributedApplicationException>(() => | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||
var appBuilder = CreateBuilder(); | ||||||||||||||||||||||||
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(nit) I like to keep the action inside the Assert.Throws as minimal as possible, so it is obvious what line is throwing the exception. |
||||||||||||||||||||||||
appBuilder.AddProject("project", projectDetails.ProjectFilePath); | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
var expectedMessage = $"Failed to get effective launch profile for project resource 'project'. There is malformed JSON in the project's launch settings file at '{projectDetails.LaunchSettingsFilePath}'."; | ||||||||||||||||||||||||
Assert.Equal(expectedMessage, ex.Message); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
async static Task<(string ProjectFilePath, string LaunchSettingsFilePath)> PrepareProjectWithMalformedLaunchSettingsAsync() | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||
var csProjContent = """ | ||||||||||||||||||||||||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||||||||||||||||||||||||
<!-- Not a real project, just a stub for testing --> | ||||||||||||||||||||||||
</Project> | ||||||||||||||||||||||||
"""; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
var launchSettingsContent = """ | ||||||||||||||||||||||||
this { is } { mal formed! > | ||||||||||||||||||||||||
"""; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
var projectDirectoryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||||||||||||||||||||||||
var projectFilePath = Path.Combine(projectDirectoryPath, "Project.csproj"); | ||||||||||||||||||||||||
var propertiesDirectoryPath = Path.Combine(projectDirectoryPath, "Properties"); | ||||||||||||||||||||||||
var launchSettingsFilePath = Path.Combine(propertiesDirectoryPath, "launchSettings.json"); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Directory.CreateDirectory(projectDirectoryPath); | ||||||||||||||||||||||||
Comment on lines
+43
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Using CreateTempSubdirectory is easier.
Comment on lines
+43
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be deleting this directory when the test is done so we don't clutter up the temp directory? |
||||||||||||||||||||||||
await File.WriteAllTextAsync(projectFilePath, csProjContent); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Directory.CreateDirectory(propertiesDirectoryPath); | ||||||||||||||||||||||||
await File.WriteAllTextAsync(launchSettingsFilePath, launchSettingsContent); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return (projectFilePath, launchSettingsFilePath); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
[Fact] | ||||||||||||||||||||||||
public async Task AddProjectAddsEnvironmentVariablesAndServiceMetadata() | ||||||||||||||||||||||||
{ | ||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.