Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding public API test coverage for Aspire.Milvus.Client #5170

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public static void AddMilvusClient(
string connectionName,
Action<MilvusClientSettings>? configureSettings = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(connectionName);

AddMilvus(builder, DefaultConfigSectionName, configureSettings, connectionName, serviceKey: null);
}

Expand All @@ -49,6 +52,8 @@ public static void AddKeyedMilvusClient(
string name,
Action<MilvusClientSettings>? configureSettings = null)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);
AddMilvus(builder, $"{DefaultConfigSectionName}:{name}", configureSettings, connectionName: name, serviceKey: name);
}

Expand Down
88 changes: 88 additions & 0 deletions tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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.Milvus.Client.Tests;

public class MilvusClientPublicApiTests
{
[Fact]
public void AddMilvusClientShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;

var connectionName = "milvus";

var action = () => builder.AddMilvusClient(connectionName);

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}

[Fact]
public void AddMilvusClientShouldThrowWhenNameIsNull()
{
var builder = Host.CreateEmptyApplicationBuilder(null);

string connectionName = null!;

var action = () => builder.AddMilvusClient(connectionName);

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(connectionName), exception.ParamName);
}

[Fact]
public void AddMilvusClientShouldThrowWhenNameEmpty()
Alirexaa marked this conversation as resolved.
Show resolved Hide resolved
{
var builder = Host.CreateEmptyApplicationBuilder(null);

string connectionName = "";

var action = () => builder.AddMilvusClient(connectionName);

var exception = Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(connectionName), exception.ParamName);
}

[Fact]
public void AddKeyedMilvusClientShouldThrowWhenBuilderIsNull()
{
IHostApplicationBuilder builder = null!;

var connectionName = "milvus";

var action = () => builder.AddKeyedMilvusClient(connectionName);

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(builder), exception.ParamName);
}

[Fact]
public void AddKeyedMilvusClientShouldThrowWhenNameIsNull()
{
var builder = Host.CreateEmptyApplicationBuilder(null);

string name = null!;

var action = () => builder.AddKeyedMilvusClient(name);

var exception = Assert.Throws<ArgumentNullException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}

[Fact]
public void AddKeyedMilvusClientShouldThrowWhenNameIsEmpty()
{
var builder = Host.CreateEmptyApplicationBuilder(null);

string name = "";

var action = () => builder.AddKeyedMilvusClient(name);

var exception = Assert.Throws<ArgumentException>(action);
Assert.Equal(nameof(name), exception.ParamName);
}
}
Loading