Skip to content
Merged
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
24 changes: 8 additions & 16 deletions tests/Aspire.Hosting.NodeJs.Tests/NodeJsPublicApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ public void CtorNodeAppResourceShouldThrowWhenCommandIsNullOrEmpty(bool isNull)
Assert.Equal(nameof(command), exception.ParamName);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void CtorNodeAppResourceShouldThrowWhenWorkingDirectoryIsNullOrEmpty(bool isNull)
[Fact]
public void CtorNodeAppResourceShouldThrowWhenWorkingDirectoryIsNull()
{
const string name = "NodeApp";
const string command = "npm";
var workingDirectory = isNull ? null! : string.Empty;
string workingDirectory = null!;

var action = () => new NodeAppResource(name, command, workingDirectory);

var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(workingDirectory), exception.ParamName);
}

Expand Down Expand Up @@ -136,20 +132,16 @@ public void AddNpmAppShouldThrowWhenNameIsNullOrEmpty(bool isNull)
Assert.Equal(nameof(name), exception.ParamName);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void AddNpmAppShouldThrowWhenWorkingDirectoryIsNullOrEmpty(bool isNull)
[Fact]
public void AddNpmAppShouldThrowWhenWorkingDirectoryIsNull()
{
var builder = TestDistributedApplicationBuilder.Create();
const string name = "NpmApp";
var workingDirectory = isNull ? null! : string.Empty;
string workingDirectory = null!;

var action = () => builder.AddNpmApp(name, workingDirectory);

var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(workingDirectory), exception.ParamName);
}

Expand Down
26 changes: 8 additions & 18 deletions tests/Aspire.Hosting.Python.Tests/PythonPublicApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,15 @@ public void CtorPythonAppResourceShouldThrowWhenExecutablePathIsNullOrEmpty(bool
Assert.Equal("command", exception.ParamName);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void CtorPythonAppResourceShouldThrowWhenAppDirectoryIsNullOrEmpty(bool isNull)
[Fact]
public void CtorPythonAppResourceShouldThrowWhenAppDirectoryIsNull()
{
const string name = "Python";
const string executablePath = "/src/python";
var appDirectory = isNull ? null! : string.Empty;

var action = () => new PythonAppResource(name, executablePath, appDirectory);
var action = () => new PythonAppResource(name, executablePath, appDirectory: null!);

var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal("workingDirectory", exception.ParamName);
}

Expand Down Expand Up @@ -379,21 +374,16 @@ public void CtorPythonProjectResourceShouldThrowWhenExecutablePathIsNullOrEmpty(
Assert.Equal("command", exception.ParamName);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
[Fact]
[Obsolete("PythonProjectResource is deprecated. Please use PythonAppResource instead.")]
public void CtorPythonProjectResourceShouldThrowWhenAppDirectoryIsNullOrEmpty(bool isNull)
public void CtorPythonProjectResourceShouldThrowWhenAppDirectoryIsNull()
{
const string name = "Python";
const string executablePath = "/src/python";
var projectDirectory = isNull ? null! : string.Empty;

var action = () => new PythonProjectResource(name, executablePath, projectDirectory);
var action = () => new PythonProjectResource(name, executablePath, projectDirectory: null!);

var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal("workingDirectory", exception.ParamName);
}

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