|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Extensions.Hosting;
using Xunit;
namespace Aspire.NATS.Net.Tests;
public class NatsClientPublicApiTests
{
[Fact]
public void AddNatsClientShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
var connectionName = "Nats";
var action = () => builder.AddNatsClient(connectionName);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void AddNatsClientShouldThrowWhenConnectionNameIsNull()
{
var builder = Host.CreateEmptyApplicationBuilder(null);
string connectionName = null!;
var action = () => builder.AddNatsClient(connectionName);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(connectionName), exception.ParamName);
}
[Fact]
public void AddNatsClientShouldThrowWhenConnectionNameIsEmpty()
{
var builder = Host.CreateEmptyApplicationBuilder(null);
var connectionName = "";
var action = () => builder.AddNatsClient(connectionName);
var exception = Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(connectionName), exception.ParamName);
}
[Fact]
public void AddKeyedNatsClientShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
var connectionName = "Nats";
var action = () => builder.AddKeyedNatsClient(connectionName);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Fact]
public void AddKeyedNatsClientShouldThrowWhenNameIsNull()
{
var builder = Host.CreateEmptyApplicationBuilder(null);
string name = null!;
var action = () => builder.AddKeyedNatsClient(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
[Fact]
public void AddKeyedNatsClientShouldThrowWhenNameIsEmpty()
{
var builder = Host.CreateEmptyApplicationBuilder(null);
var name = "";
var action = () => builder.AddKeyedNatsClient(name);
var exception = Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
[Fact]
public void AddNatsJetStreamShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
var action = builder.AddNatsJetStream;
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
}
|