| File: NodeJsPublicApiTests.cs | Web Access |
| Project: src\tests\Aspire.Hosting.JavaScript.Tests\Aspire.Hosting.JavaScript.Tests.csproj (Aspire.Hosting.JavaScript.Tests) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Aspire.Hosting.Utils; namespace Aspire.Hosting.JavaScript.Tests; public class NodeJsPublicApiTests { [Theory] [InlineData(true)] [InlineData(false)] public void CtorNodeAppResourceShouldThrowWhenNameIsNullOrEmpty(bool isNull) { var name = isNull ? null! : string.Empty; const string command = "npm"; const string workingDirectory = ".\\app"; var action = () => new NodeAppResource(name, command, workingDirectory); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(name), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void CtorNodeAppResourceShouldThrowWhenCommandIsNullOrEmpty(bool isNull) { const string name = "NodeApp"; var command = isNull ? null! : string.Empty; const string workingDirectory = ".\\app"; var action = () => new NodeAppResource(name, command, workingDirectory); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(command), exception.ParamName); } [Fact] public void CtorNodeAppResourceShouldThrowWhenWorkingDirectoryIsNull() { const string name = "NodeApp"; const string command = "npm"; string workingDirectory = null!; var action = () => new NodeAppResource(name, command, workingDirectory); var exception = Assert.Throws<ArgumentNullException>(action); Assert.Equal(nameof(workingDirectory), exception.ParamName); } [Fact] public void AddNodeAppShouldThrowWhenBuilderIsNull() { IDistributedApplicationBuilder builder = null!; const string name = "NodeApp"; const string scriptPath = ".\\app.js"; var action = () => builder.AddNodeApp(name, ".", scriptPath); var exception = Assert.Throws<ArgumentNullException>(action); Assert.Equal(nameof(builder), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddNodeAppShouldThrowWhenNameIsNullOrEmpty(bool isNull) { var builder = TestDistributedApplicationBuilder.Create(); var name = isNull ? null! : string.Empty; const string scriptPath = ".\\app.js"; var action = () => builder.AddNodeApp(name, ".", scriptPath); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(name), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddNodeAppShouldThrowWhenScriptPathIsNullOrEmpty(bool isNull) { var builder = TestDistributedApplicationBuilder.Create(); const string name = "NodeApp"; var scriptPath = isNull ? null! : string.Empty; var action = () => builder.AddNodeApp(name, ".", scriptPath); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(scriptPath), exception.ParamName); } [Fact] public void AddJavaScriptAppShouldThrowWhenBuilderIsNull() { IDistributedApplicationBuilder builder = null!; const string name = "NpmApp"; const string workingDirectory = ".\\app"; var action = () => builder.AddJavaScriptApp(name: name, workingDirectory); var exception = Assert.Throws<ArgumentNullException>(action); Assert.Equal(nameof(builder), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddJavaScriptAppShouldThrowWhenNameIsNullOrEmpty(bool isNull) { var builder = TestDistributedApplicationBuilder.Create(); var name = isNull ? null! : string.Empty; const string workingDirectory = ".\\app"; var action = () => builder.AddJavaScriptApp(name: name, workingDirectory); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(name), exception.ParamName); } [Fact] public void AddJavaScriptAppShouldThrowWhenWorkingDirectoryIsNull() { var builder = TestDistributedApplicationBuilder.Create(); const string name = "NpmApp"; string appDirectory = null!; var action = () => builder.AddJavaScriptApp(name, appDirectory); var exception = Assert.Throws<ArgumentNullException>(action); Assert.Equal(nameof(appDirectory), exception.ParamName); } [Theory] [InlineData(true)] [InlineData(false)] public void AddJavaScriptAppShouldThrowWhenScriptNameIsNullOrEmpty(bool isNull) { var builder = TestDistributedApplicationBuilder.Create(); const string name = "NpmApp"; const string workingDirectory = ".\\app"; var runScriptName = isNull ? null! : string.Empty; var action = () => builder.AddJavaScriptApp(name, workingDirectory, runScriptName); var exception = isNull ? Assert.Throws<ArgumentNullException>(action) : Assert.Throws<ArgumentException>(action); Assert.Equal(nameof(runScriptName), exception.ParamName); } }