Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/Aspire.Hosting/ApplicationModel/ExecutableResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Aspire.Hosting.ApplicationModel;
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="command">The command to execute.</param>
/// <param name="workingDirectory">The working directory of the executable.</param>
/// <param name="workingDirectory">The working directory of the executable. Can be empty.</param>
public class ExecutableResource(string name, string command, string workingDirectory)
: Resource(name), IResourceWithEnvironment, IResourceWithArgs, IResourceWithEndpoints, IResourceWithWaitSupport
{
Expand All @@ -23,7 +23,7 @@ public class ExecutableResource(string name, string command, string workingDirec
/// <summary>
/// Gets the working directory for the executable resource.
/// </summary>
public string WorkingDirectory { get; } = ThrowIfNullOrEmpty(workingDirectory);
public string WorkingDirectory { get; } = workingDirectory ?? throw new ArgumentNullException(nameof(workingDirectory));

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
Expand Down
19 changes: 19 additions & 0 deletions tests/Aspire.Hosting.Tests/ExecutableResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ public async Task AddExecutableWithArgs()
Assert.Equal(expectedManifest, manifest.ToString());
}

[Fact]
public void ExecutableResourceNullCommand()
=> Assert.Throws<ArgumentNullException>("command", () => new ExecutableResource("name", command: null!, workingDirectory: "."));

[Fact]
public void ExecutableResourceEmptyCommand()
=> Assert.Throws<ArgumentException>("command", () => new ExecutableResource("name", command: "", workingDirectory: "."));

[Fact]
public void ExecutableResourceNullWorkingDirectory()
=> Assert.Throws<ArgumentNullException>("workingDirectory", () => new ExecutableResource("name", command: "cmd", workingDirectory: null!));

[Fact]
public void ExecutableResourceEmptyWorkingDirectory()
{
var er = new ExecutableResource("name", command: "cmd", workingDirectory: "");
Assert.Empty(er.WorkingDirectory);
}

private sealed class TestResource(string name, string connectionString) : Resource(name), IResourceWithConnectionString
{
public ReferenceExpression ConnectionStringExpression =>
Expand Down
Loading