From 223b1ed886b113bcab245bcc38d6d063f40d251b Mon Sep 17 00:00:00 2001 From: Alireza Baloochi Date: Sun, 4 Aug 2024 21:14:27 +0330 Subject: [PATCH 1/2] Adding public API test coverage for Aspire.Milvus.Client --- .../AspireMilvusExtensions.cs | 5 ++ .../MilvusClientPublicApiTests.cs | 88 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs diff --git a/src/Components/Aspire.Milvus.Client/AspireMilvusExtensions.cs b/src/Components/Aspire.Milvus.Client/AspireMilvusExtensions.cs index 3118c0a720..a632ba7af9 100644 --- a/src/Components/Aspire.Milvus.Client/AspireMilvusExtensions.cs +++ b/src/Components/Aspire.Milvus.Client/AspireMilvusExtensions.cs @@ -32,6 +32,9 @@ public static void AddMilvusClient( string connectionName, Action? configureSettings = null) { + ArgumentNullException.ThrowIfNull(builder); + ArgumentException.ThrowIfNullOrEmpty(connectionName); + AddMilvus(builder, DefaultConfigSectionName, configureSettings, connectionName, serviceKey: null); } @@ -49,6 +52,8 @@ public static void AddKeyedMilvusClient( string name, Action? configureSettings = null) { + ArgumentNullException.ThrowIfNull(builder); + ArgumentException.ThrowIfNullOrEmpty(name); AddMilvus(builder, $"{DefaultConfigSectionName}:{name}", configureSettings, connectionName: name, serviceKey: name); } diff --git a/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs b/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs new file mode 100644 index 0000000000..f5d9c171ac --- /dev/null +++ b/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs @@ -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(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(action); + Assert.Equal(nameof(connectionName), exception.ParamName); + } + + [Fact] + public void AddMilvusClientShouldThrowWhenNameEmpty() + { + var builder = Host.CreateEmptyApplicationBuilder(null); + + string connectionName = ""; + + var action = () => builder.AddMilvusClient(connectionName); + + var exception = Assert.Throws(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(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(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(action); + Assert.Equal(nameof(name), exception.ParamName); + } +} From b4ac9e55551c9a0af0291e066ba7a2f61ffd9f9f Mon Sep 17 00:00:00 2001 From: Alireza Baloochi Date: Sun, 4 Aug 2024 21:31:38 +0330 Subject: [PATCH 2/2] Update tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs --- tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs b/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs index f5d9c171ac..cb349f207f 100644 --- a/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs +++ b/tests/Aspire.Milvus.Client.Tests/MilvusClientPublicApiTests.cs @@ -35,7 +35,7 @@ public void AddMilvusClientShouldThrowWhenNameIsNull() } [Fact] - public void AddMilvusClientShouldThrowWhenNameEmpty() + public void AddMilvusClientShouldThrowWhenNameIsEmpty() { var builder = Host.CreateEmptyApplicationBuilder(null);