File: PublicApiTests\AppConfigurationPublicApiTests.cs
Web Access
Project: src\tests\Aspire.Hosting.Azure.Tests\Aspire.Hosting.Azure.Tests.csproj (Aspire.Hosting.Azure.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;
using Xunit;
 
namespace Aspire.Hosting.Azure.Tests.PublicApiTests;
 
public class AppConfigurationPublicApiTests
{
    [Fact]
    public void AddAzureAppConfigurationShouldThrowWhenBuilderIsNull()
    {
        IDistributedApplicationBuilder builder = null!;
        const string name = "azure";
 
        var action = () => builder.AddAzureAppConfiguration(name);
 
        var exception = Assert.Throws<ArgumentNullException>(action);
        Assert.Equal(nameof(builder), exception.ParamName);
    }
 
    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void AddAzureAppConfigurationShouldThrowWhenNameIsNullOrEmpty(bool isNull)
    {
        var builder = TestDistributedApplicationBuilder.Create();
        var name = isNull ? null! : string.Empty;
 
        var action = () => builder.AddAzureAppConfiguration(name);
 
        var exception = isNull
            ? Assert.Throws<ArgumentNullException>(action)
            : Assert.Throws<ArgumentException>(action);
        Assert.Equal(nameof(name), exception.ParamName);
    }
 
    [Theory]
    [InlineData(true)]
    [InlineData(false)]
    public void CtorAzureAppConfigurationResourceShouldThrowWhenNameIsNullOrEmpty(bool isNull)
    {
        var name = isNull ? null! : string.Empty;
        Action<AzureResourceInfrastructure> configureInfrastructure = (c) => { };
 
        var action = () => new AzureAppConfigurationResource(name, configureInfrastructure);
 
        var exception = isNull
            ? Assert.Throws<ArgumentNullException>(action)
            : Assert.Throws<ArgumentException>(action);
        Assert.Equal(nameof(name), exception.ParamName);
    }
 
    [Fact]
    public void CtorAzureAppConfigurationResourceShouldThrowWhenConfigureInfrastructureIsNull()
    {
        const string name = "azure";
        Action<AzureResourceInfrastructure> configureInfrastructure = null!;
 
        var action = () => new AzureAppConfigurationResource(name, configureInfrastructure);
 
        var exception = Assert.Throws<ArgumentNullException>(action);
        Assert.Equal(nameof(configureInfrastructure), exception.ParamName);
    }
}