-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding public API test coverage for Aspire.Hosting.Elasticsearch (#5119)
* Add tests and argument null exception * Apply suggested changes
- Loading branch information
Showing
2 changed files
with
110 additions
and
2 deletions.
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
97 changes: 97 additions & 0 deletions
97
tests/Aspire.Hosting.Elasticsearch.Tests/ElasticsearchPublicApiTests.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,97 @@ | ||
// 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.ApplicationModel; | ||
using Xunit; | ||
|
||
namespace Aspire.Hosting.Elasticsearch.Tests; | ||
|
||
public class ElasticsearchPublicApiTests | ||
{ | ||
[Fact] | ||
public void AddElasticsearchContainerShouldThrowWhenBuilderIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = null!; | ||
const string name = "Elasticsearch"; | ||
|
||
var action = () => builder.AddElasticsearch(name); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void AddElasticsearchContainerShouldThrowWhenNameIsNull() | ||
{ | ||
IDistributedApplicationBuilder builder = new DistributedApplicationBuilder([]); | ||
string name = null!; | ||
|
||
var action = () => builder.AddElasticsearch(name); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
|
||
[Theory] | ||
[InlineData(false)] | ||
[InlineData(true)] | ||
public void WithDataShouldThrowWhenBuilderIsNull(bool useVolume) | ||
{ | ||
IResourceBuilder<ElasticsearchResource> builder = null!; | ||
|
||
Func<IResourceBuilder<ElasticsearchResource>>? action = null; | ||
|
||
if (useVolume) | ||
{ | ||
action = () => builder.WithDataVolume(); | ||
} | ||
else | ||
{ | ||
const string source = "/data"; | ||
|
||
action = () => builder.WithDataBindMount(source); | ||
} | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(builder), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void WithDataBindMountShouldThrowWhenSourceIsNull() | ||
{ | ||
var builder = new DistributedApplicationBuilder([]); | ||
var resourceBuilder = builder.AddElasticsearch("Elasticsearch"); | ||
|
||
string source = null!; | ||
|
||
var action = () => resourceBuilder.WithDataBindMount(source); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(source), exception.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void CtorElasticsearchResourceShouldThrowWhenNameIsNull() | ||
{ | ||
var builder = new DistributedApplicationBuilder([]); | ||
builder.Configuration["Parameters:Password"] = "p@ssw0rd"; | ||
var password = builder.AddParameter("Password"); | ||
const string name = null!; | ||
|
||
var action = () => new ElasticsearchResource(name, password.Resource); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(name), exception.ParamName); | ||
} | ||
[Fact] | ||
public void CtorElasticsearchResourceShouldThrowWhenPasswordIsNull() | ||
{ | ||
const string name = "Elasticsearch"; | ||
ParameterResource password = null!; | ||
|
||
var action = () => new ElasticsearchResource(name, password); | ||
|
||
var exception = Assert.Throws<ArgumentNullException>(action); | ||
Assert.Equal(nameof(password), exception.ParamName); | ||
} | ||
} |