File: ElasticsearchClientPublicApiTests.cs
Web Access
Project: src\tests\Aspire.Elastic.Clients.Elasticsearch.Tests\Aspire.Elastic.Clients.Elasticsearch.Tests.csproj (Aspire.Elastic.Clients.Elasticsearch.Tests)
// 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.Elastic.Clients.Elasticsearch.Tests;
 
public class ElasticsearchClientPublicApiTests
{
    [Fact]
    public void AddElasticsearchClientShouldThrowWhenBuilderIsNull()
    {
        IHostApplicationBuilder builder = null!;
 
        var connectionName = "elasticseach";
 
        var action = () => builder.AddElasticsearchClient(connectionName);
 
        var exception = Assert.Throws<ArgumentNullException>(action);
        Assert.Equal(nameof(builder), exception.ParamName);
    }
 
    [Fact]
    public void AddElasticsearchClientShouldThrowWhenNameIsNull()
    {
        var builder = Host.CreateEmptyApplicationBuilder(null);
 
        string connectionName = null!;
 
        var action = () => builder.AddElasticsearchClient(connectionName);
 
        var exception = Assert.Throws<ArgumentNullException>(action);
        Assert.Equal(nameof(connectionName), exception.ParamName);
    }
 
    [Fact]
    public void AddElasticsearchClientShouldThrowWhenNameIsEmpty()
    {
        var builder = Host.CreateEmptyApplicationBuilder(null);
 
        string connectionName = "";
 
        var action = () => builder.AddElasticsearchClient(connectionName);
 
        var exception = Assert.Throws<ArgumentException>(action);
        Assert.Equal(nameof(connectionName), exception.ParamName);
    }
 
    [Fact]
    public void AddKeyedElasticsearchClientShouldThrowWhenBuilderIsNull()
    {
        IHostApplicationBuilder builder = null!;
 
        var connectionName = "elasticseach";
 
        var action = () => builder.AddKeyedElasticsearchClient(connectionName);
 
        var exception = Assert.Throws<ArgumentNullException>(action);
        Assert.Equal(nameof(builder), exception.ParamName);
    }
 
    [Fact]
    public void AddKeyedElasticsearchClientShouldThrowWhenNameIsNull()
    {
        var builder = Host.CreateEmptyApplicationBuilder(null);
 
        string name = null!;
 
        var action = () => builder.AddKeyedElasticsearchClient(name);
 
        var exception = Assert.Throws<ArgumentNullException>(action);
        Assert.Equal(nameof(name), exception.ParamName);
    }
 
    [Fact]
    public void AddKeyedElasticsearchClientShouldThrowWhenNameIsEmpty()
    {
        var builder = Host.CreateEmptyApplicationBuilder(null);
 
        string name = "";
 
        var action = () => builder.AddKeyedElasticsearchClient(name);
 
        var exception = Assert.Throws<ArgumentException>(action);
        Assert.Equal(nameof(name), exception.ParamName);
    }
}