-
Notifications
You must be signed in to change notification settings - Fork 480
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
Adding public API test coverage Aspire.Hosting.NodeJs #5161
Merged
sebastienros
merged 4 commits into
dotnet:main
from
Alirexaa:validate-arguments-of-public-methods#aspire-hosting-nodejs
Aug 14, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
53d7217
Adding public API test coverage Aspire.Hosting.NodeJs
sebastienros 180a953
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Alirexaa 5d569d1
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Alirexaa 97f7042
Merge branch 'dotnet:main' into validate-arguments-of-public-methods#…
Alirexaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
tests/Aspire.Hosting.NodeJs.Tests/NodeJsPublicApiTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using Xunit; | ||
|
||
namespace Aspire.Hosting.NodeJs.Tests; | ||
|
||
public class NodeJsPublicApiTests | ||
{ | ||
[Fact] | ||
public void AddNodeAppShouldThrowWhenBuilderIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = null!; | ||
var name = "nodeapp"; | ||
var scriptPath = ".\\app.js"; | ||
|
||
var action = () => builder.AddNodeApp(name: name, scriptPath: scriptPath); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddNodeAppShouldThrowWhenNameIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
string name = null!; | ||
var scriptPath = ".\\app.js"; | ||
|
||
var action = () => builder.AddNodeApp(name: name, scriptPath: scriptPath); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddNodeAppShouldThrowWhenScriptPathIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
var name = "nodeapp"; | ||
string scriptPath = null!; | ||
|
||
var action = () => builder.AddNodeApp(name: name, scriptPath: scriptPath); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(scriptPath), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddNpmAppShouldThrowWhenBuilderIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = null!; | ||
var name = "npmapp"; | ||
var workingDirectory = ".\\app"; | ||
|
||
var action = () => builder.AddNpmApp(name: name, workingDirectory: workingDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddNpmAppShouldThrowWhenWorkingDirectoryIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
var name = "npmapp"; | ||
string workingDirectory = null!; | ||
|
||
var action = () => builder.AddNpmApp(name: name, workingDirectory: workingDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(workingDirectory), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddNpmAppShouldThrowWhenNameIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
string name = null!; | ||
var workingDirectory = ".\\app"; | ||
|
||
var action = () => builder.AddNpmApp(name: name, workingDirectory: workingDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddNpmAppShouldThrowWhenScriptNameIsNull() | ||
{ | ||
var builder = DistributedApplication.CreateBuilder(); | ||
var name = "npmapp"; | ||
var workingDirectory = ".\\app"; | ||
string scriptName = null!; | ||
|
||
var action = () => builder.AddNpmApp(name: name, workingDirectory: workingDirectory, scriptName: scriptName); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(scriptName), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void CtorNodeAppResourceShouldThrowWhenNameIsNull() | ||
{ | ||
string name = null!; | ||
var command = "start"; | ||
var workingDirectory = ".\\app"; | ||
|
||
var action = () => new NodeAppResource(name, command, workingDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void CtorNodeAppResourceShouldThrowWhenCommandIsNull() | ||
{ | ||
var name = "nodeapp"; | ||
string command = null!; | ||
var workingDirectory = ".\\app"; | ||
|
||
var action = () => new NodeAppResource(name, command, workingDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(command), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void CtorNodeAppResourceShouldThrowWhenWorkingDirectoryIsNull() | ||
{ | ||
var name = "nodeapp"; | ||
var command = "start"; | ||
string workingDirectory = null!; | ||
|
||
var action = () => new NodeAppResource(name, command, workingDirectory); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(workingDirectory), exception.ParamName); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Alirexaa you missed this one. It has a default value but it doesn't mean we still can't call it with a
null
value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I had to force push to revert the changes in the .sln file.