|
// 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.Azure.AI.OpenAI.Tests;
public class AIOpenAIPublicApiTests
{
[Fact]
public void CtorAspireAzureOpenAIClientBuilderShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder hostBuilder = null!;
const string connectionName = "openai";
const string? serviceKey = null;
const bool disableTracing = false;
var action = () => new AspireAzureOpenAIClientBuilder(hostBuilder, connectionName, serviceKey, disableTracing);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(hostBuilder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void CtorAspireAzureOpenAIClientBuilderShouldThrowWhenConnectionNameIsNullOrEmpty(bool isNull)
{
var hostBuilder = Host.CreateEmptyApplicationBuilder(null);
var connectionName = isNull ? null! : string.Empty;
const string? serviceKey = null;
const bool disableTracing = false;
var action = () => new AspireAzureOpenAIClientBuilder(hostBuilder, connectionName, serviceKey, disableTracing);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(connectionName), exception.ParamName);
}
[Fact]
public void AddAzureOpenAIClientShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
const string connectionName = "openai";
var action = () => builder.AddAzureOpenAIClient(connectionName);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void AddAzureOpenAIClientShouldThrowWhenConnectionNameIsNullOrEmpty(bool isNull)
{
var builder = Host.CreateEmptyApplicationBuilder(null);
var connectionName = isNull ? null! : string.Empty;
var action = () => builder.AddAzureOpenAIClient(connectionName);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(connectionName), exception.ParamName);
}
[Fact]
public void AddKeyedAzureOpenAIClientShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
const string name = "openai";
var action = () => builder.AddKeyedAzureOpenAIClient(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void AddKeyedAzureOpenAIClientShouldThrowWhenNameIsNullOrEmpty(bool isNull)
{
var builder = Host.CreateEmptyApplicationBuilder(null);
var name = isNull ? null! : string.Empty;
var action = () => builder.AddKeyedAzureOpenAIClient(name);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
[Fact]
public void AddOpenAIClientFromConfigurationShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
const string connectionName = "openai";
var action = () => builder.AddOpenAIClientFromConfiguration(connectionName);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void AddOpenAIClientFromConfigurationShouldThrowWhenConnectionNameIsNullOrEmpty(bool isNull)
{
var builder = Host.CreateEmptyApplicationBuilder(null);
var connectionName = isNull ? null! : string.Empty;
var action = () => builder.AddOpenAIClientFromConfiguration(connectionName);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action); ;
Assert.Equal(nameof(connectionName), exception.ParamName);
}
[Fact]
public void AddKeyedOpenAIClientFromConfigurationShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;
const string name = "openai";
var action = () => builder.AddKeyedOpenAIClientFromConfiguration(name);
var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void AddKeyedOpenAIClientFromConfigurationShouldThrowWhenNameIsNullOrEmpty(bool isNull)
{
var builder = Host.CreateEmptyApplicationBuilder(null);
var name = isNull ? null! : string.Empty;
var action = () => builder.AddKeyedOpenAIClientFromConfiguration(name);
var exception = isNull
? Assert.Throws<ArgumentNullException>(action)
: Assert.Throws<ArgumentException>(action); ;
Assert.Equal(nameof(name), exception.ParamName);
}
}
|