From 0ede8995e9edb5d368bea08e952eb2339825694c Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 9 Oct 2025 23:13:44 +0900 Subject: [PATCH 01/21] fix: update GithubModelsConnectorTests Related to: #451 --- .../Connectors/GitHubModelsConnectorTests.cs | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs index dbdf259f..15f39c85 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs @@ -1,3 +1,5 @@ +using Humanizer; + using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -5,7 +7,11 @@ namespace OpenChat.PlaygroundApp.Tests.Connectors; public class GitHubModelsConnectorTests { - private static AppSettings BuildAppSettings(string? endpoint = "https://models.github.ai/inference", string? token = "test-token", string? model = "openai/gpt-4o-mini") + private const string Endpoint = "https://models.github.ai/inference"; + private const string Token = "test-token"; + private const string Model = "openai/gpt-4o-mini"; + + private static AppSettings BuildAppSettings(string? endpoint = Endpoint, string? token = Token, string? model = Model) { return new AppSettings { @@ -28,10 +34,11 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked var connector = new GitHubModelsConnector(settings); // Act - var ex = Assert.Throws(() => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain("GitHubModels"); + action.ShouldThrow() + .Message.ShouldContain("GitHubModels"); } [Trait("Category", "UnitTest")] @@ -46,10 +53,11 @@ public void Given_Invalid_Endpoint_When_EnsureLanguageModelSettingsValid_Invoked var connector = new GitHubModelsConnector(settings); // Act - var ex = Assert.Throws(expectedType, () => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain(expectedMessage); + action.ShouldThrow(expectedType) + .Message.ShouldContain(expectedMessage); } [Trait("Category", "UnitTest")] @@ -64,10 +72,11 @@ public void Given_Invalid_Token_When_EnsureLanguageModelSettingsValid_Invoked_Th var connector = new GitHubModelsConnector(settings); // Act - var ex = Assert.Throws(expectedType, () => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain(expectedMessage); + action.ShouldThrow(expectedType) + .Message.ShouldContain(expectedMessage); } [Trait("Category", "UnitTest")] @@ -82,10 +91,11 @@ public void Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Th var connector = new GitHubModelsConnector(settings); // Act - var ex = Assert.Throws(expectedType, () => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain(expectedMessage); + action.ShouldThrow(expectedType) + .Message.ShouldContain(expectedMessage); } [Trait("Category", "UnitTest")] @@ -129,9 +139,10 @@ public async Task Given_Missing_Token_When_GetChatClient_Invoked_Then_It_Should_ var connector = new GitHubModelsConnector(settings); // Act - var ex = await Assert.ThrowsAsync(expected, connector.GetChatClientAsync); + Func func = connector.GetChatClientAsync; // Assert + var ex = await func.ShouldThrowAsync(expected); ex.Message.ShouldContain(message); } @@ -146,9 +157,10 @@ public async Task Given_Missing_Endpoint_When_GetChatClient_Invoked_Then_It_Shou var connector = new GitHubModelsConnector(settings); // Act - var ex = await Assert.ThrowsAsync(expected, connector.GetChatClientAsync); + Func func = connector.GetChatClientAsync; // Assert + var ex = await func.ShouldThrowAsync(expected); ex.Message.ShouldContain(message); } @@ -163,9 +175,10 @@ public async Task Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_ var connector = new GitHubModelsConnector(settings); // Act - var ex = await Assert.ThrowsAsync(expected, connector.GetChatClientAsync); + Func func = connector.GetChatClientAsync; // Assert + var ex = await func.ShouldThrowAsync(expected); ex.Message.ShouldContain(message); } } From c902fcf96f6e32f535003d037cb6f482f635f52f Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 9 Oct 2025 23:22:57 +0900 Subject: [PATCH 02/21] fix: update HuggingFaceConnectorTests Related to: #451 --- .../Connectors/HuggingFaceConnectorTests.cs | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index 1b184ac7..6a1a6065 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -22,19 +22,6 @@ private static AppSettings BuildAppSettings(string? baseUrl = BaseUrl, string? m }; } - [Trait("Category", "UnitTest")] - [Theory] - [InlineData(typeof(LanguageModelConnector), typeof(HuggingFaceConnector), true)] - [InlineData(typeof(HuggingFaceConnector), typeof(LanguageModelConnector), false)] - public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) - { - // Act - var result = baseType.IsAssignableFrom(derivedType); - - // Assert - result.ShouldBe(expected); - } - [Trait("Category", "UnitTest")] [Fact] public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw() @@ -44,10 +31,11 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked var connector = new HuggingFaceConnector(settings); // Act - var ex = Assert.Throws(() => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain("HuggingFace"); + action.ShouldThrow() + .Message.ShouldContain("HuggingFace"); } [Trait("Category", "UnitTest")] @@ -62,10 +50,11 @@ public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_ var connector = new HuggingFaceConnector(settings); // Act - var ex = Assert.Throws(expectedType, () => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain(expectedMessage); + action.ShouldThrow(expectedType) + .Message.ShouldContain(expectedMessage); } [Trait("Category", "UnitTest")] @@ -83,10 +72,11 @@ public void Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Th var connector = new HuggingFaceConnector(settings); // Act - var ex = Assert.Throws(expectedType, () => connector.EnsureLanguageModelSettingsValid()); + Action action = () => connector.EnsureLanguageModelSettingsValid(); // Assert - ex.Message.ShouldContain(expectedMessage); + action.ShouldThrow(expectedType) + .Message.ShouldContain(expectedMessage); } [Trait("Category", "UnitTest")] @@ -131,9 +121,10 @@ public async Task Given_Missing_BaseUrl_When_GetChatClient_Invoked_Then_It_Shoul var connector = new HuggingFaceConnector(settings); // Act - var ex = await Assert.ThrowsAsync(expected, connector.GetChatClientAsync); + Func func = connector.GetChatClientAsync; // Assert + var ex = await func.ShouldThrowAsync(expected); ex.Message.ShouldContain(message); } } From ed3c900785171596d17746c6f2dfc4625288b607 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Fri, 10 Oct 2025 00:22:34 +0900 Subject: [PATCH 03/21] fix: update OpenAIConnectorTests Related to: #451 --- .../Connectors/OpenAIConnectorTests.cs | 73 +++++-------------- 1 file changed, 18 insertions(+), 55 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs index 83d0678d..ccee3761 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs @@ -84,7 +84,7 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T public void Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? model, Type expectedType, string expectedMessage) { // Arrange - var settings = BuildAppSettings(apiKey: "valid-key", model: model); + var settings = BuildAppSettings(model: model); var connector = new OpenAIConnector(settings); // Act @@ -112,105 +112,68 @@ public async Task Given_Valid_Settings_When_GetChatClientAsync_Invoked_Then_It_S [Trait("Category", "UnitTest")] [Fact] - public void Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() + public async Task Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() { // Arrange - var settings = new AppSettings { ConnectorType = ConnectorType.OpenAI, OpenAI = null }; + var settings = new AppSettings { ConnectorType = ConnectorType.OpenAI, OpenAI = null! }; var connector = new OpenAIConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert - func.ShouldThrow() - .Message.ShouldContain("Missing configuration: OpenAI:ApiKey."); + var ex = await func.ShouldThrowAsync(); + ex.Message.ShouldContain("Missing configuration: OpenAI:ApiKey."); } [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(InvalidOperationException), "OpenAI:ApiKey")] [InlineData("", typeof(ArgumentException), "key")] - public void Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? apiKey, Type expected, string message) + public async Task Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? apiKey, Type expected, string message) { // Arrange var settings = BuildAppSettings(apiKey: apiKey); var connector = new OpenAIConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert - func.ShouldThrow(expected) - .Message.ShouldContain(message); + var ex = await func.ShouldThrowAsync(expected); + ex.Message.ShouldContain(message); } [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(ArgumentNullException), "model")] [InlineData("", typeof(ArgumentException), "model")] - public void Given_Missing_Model_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) + public async Task Given_Missing_Model_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) { // Arrange var settings = BuildAppSettings(model: model); var connector = new OpenAIConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert - func.ShouldThrow(expected) - .Message.ShouldContain(message); + var ex = await func.ShouldThrowAsync(expected); + ex.Message.ShouldContain(message); } [Trait("Category", "UnitTest")] [Fact] - public void Given_Valid_Format_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Pass() + public async Task Given_Valid_Format_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Pass() { // Arrange - var settings = BuildAppSettings(apiKey: "sk-test-key-with-proper-format", model: "gpt-3.5-turbo"); + var settings = BuildAppSettings(); var connector = new OpenAIConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert - func.ShouldNotThrow(); - } - - [Trait("Category", "UnitTest")] - [Fact] - public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_ChatClient() - { - // Arrange - var settings = BuildAppSettings(); - - // Act - var result = await LanguageModelConnector.CreateChatClientAsync(settings); - - // Assert - result.ShouldNotBeNull(); - result.ShouldBeAssignableTo(); - } - - [Trait("Category", "UnitTest")] - [Fact] - public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw() - { - // Arrange - var settings = new AppSettings - { - ConnectorType = ConnectorType.OpenAI, - OpenAI = new OpenAISettings - { - ApiKey = null, - Model = "test-model" - } - }; - - // Act - Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); - - // Assert - func.ShouldThrow(); + await func.ShouldNotThrowAsync(); } } \ No newline at end of file From 0d0190fd98545c6b168a4220dfa628151cce41cf Mon Sep 17 00:00:00 2001 From: sikutisa Date: Fri, 10 Oct 2025 00:28:18 +0900 Subject: [PATCH 04/21] fix: update ArgumentOptionsTests Related to: #451 --- .../Abstractions/ArgumentOptionsTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs index 682bca33..2f41b2be 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs @@ -190,7 +190,7 @@ public void Given_Empty_ConnectorType_When_Parse_Invoked_Then_It_Should_Return_U [InlineData(AppSettingConstants.ConnectorType, "AzureAIFoundry", ConnectorType.AzureAIFoundry)] [InlineData(AppSettingConstants.ConnectorType, "GitHubModels", ConnectorType.GitHubModels)] [InlineData(AppSettingConstants.ConnectorType, "GoogleVertexAI", ConnectorType.GoogleVertexAI)] - // [InlineData(AppSettingConstants.ConnectorType, "DockerModelRunner", ConnectorType.DockerModelRunner)] + [InlineData(AppSettingConstants.ConnectorType, "DockerModelRunner", ConnectorType.DockerModelRunner)] [InlineData(AppSettingConstants.ConnectorType, "FoundryLocal", ConnectorType.FoundryLocal)] [InlineData(AppSettingConstants.ConnectorType, "HuggingFace", ConnectorType.HuggingFace)] [InlineData(AppSettingConstants.ConnectorType, "Ollama", ConnectorType.Ollama)] @@ -217,11 +217,11 @@ public void Given_ConnectorType_When_Parse_Invoked_Then_It_Should_Return_Result( [InlineData(AppSettingConstants.ConnectorType, "AzureAIFoundry", "OpenAI", ConnectorType.OpenAI)] // [InlineData(AppSettingConstants.ConnectorType, "GitHubModels", "Naver", ConnectorType.Naver)] [InlineData(AppSettingConstants.ConnectorType, "GoogleVertexAI", "LG", ConnectorType.LG)] - // [InlineData(AppSettingConstants.ConnectorType, "DockerModelRunner", "Anthropic", ConnectorType.Anthropic)] + [InlineData(AppSettingConstants.ConnectorType, "DockerModelRunner", "Anthropic", ConnectorType.Anthropic)] [InlineData(AppSettingConstants.ConnectorType, "FoundryLocal", "Ollama", ConnectorType.Ollama)] [InlineData(AppSettingConstants.ConnectorType, "HuggingFace", "Ollama", ConnectorType.Ollama)] [InlineData(AppSettingConstants.ConnectorType, "Ollama", "FoundryLocal", ConnectorType.FoundryLocal)] - // [InlineData(AppSettingConstants.ConnectorType, "Anthropic", "DockerModelRunner", ConnectorType.DockerModelRunner)] + [InlineData(AppSettingConstants.ConnectorType, "Anthropic", "DockerModelRunner", ConnectorType.DockerModelRunner)] [InlineData(AppSettingConstants.ConnectorType, "LG", "GoogleVertexAI", ConnectorType.GoogleVertexAI)] [InlineData(AppSettingConstants.ConnectorType, "Naver", "GitHubModels", ConnectorType.GitHubModels)] [InlineData(AppSettingConstants.ConnectorType, "OpenAI", "AzureAIFoundry", ConnectorType.AzureAIFoundry)] @@ -244,7 +244,7 @@ public void Given_ConnectorType_And_Argument_When_Parse_Invoked_Then_It_Should_R [InlineData(AppSettingConstants.ConnectorType, "AzureAIFoundry", "MaaS", ConnectorType.AzureAIFoundry)] [InlineData(AppSettingConstants.ConnectorType, "GitHubModels", "MaaS", ConnectorType.GitHubModels)] [InlineData(AppSettingConstants.ConnectorType, "GoogleVertexAI", "MaaS", ConnectorType.GoogleVertexAI)] - // [InlineData(AppSettingConstants.ConnectorType, "DockerModelRunner", "Local", ConnectorType.DockerModelRunner)] + [InlineData(AppSettingConstants.ConnectorType, "DockerModelRunner", "Local", ConnectorType.DockerModelRunner)] [InlineData(AppSettingConstants.ConnectorType, "FoundryLocal", "Local", ConnectorType.FoundryLocal)] [InlineData(AppSettingConstants.ConnectorType, "HuggingFace", "Local", ConnectorType.HuggingFace)] [InlineData(AppSettingConstants.ConnectorType, "Ollama", "Local", ConnectorType.Ollama)] @@ -286,7 +286,7 @@ public void Given_Help_When_Parse_Invoked_Then_It_Should_Return_Help(string argu [InlineData(typeof(AzureAIFoundryArgumentOptions))] [InlineData(typeof(GitHubModelsArgumentOptions))] [InlineData(typeof(GoogleVertexAIArgumentOptions))] - // [InlineData(typeof(DockerModelRunnerArgumentOptions))] + [InlineData(typeof(DockerModelRunnerArgumentOptions))] [InlineData(typeof(FoundryLocalArgumentOptions))] [InlineData(typeof(HuggingFaceArgumentOptions))] [InlineData(typeof(OllamaArgumentOptions))] From 709c735b15311ebf42c868296d64c3628df75063 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Fri, 10 Oct 2025 00:44:57 +0900 Subject: [PATCH 05/21] fix: update LanguageModelConnectorTests Related to: #451 --- .../LanguageModelConnectorTests.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs index 8efc9cf3..816a854b 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs @@ -38,6 +38,34 @@ public async Task Given_GitHubModels_Settings_When_CreateChatClient_Invoked_Then client.ShouldNotBeNull(); } + [Trait("Category", "UnitTest")] + [Fact] + public async Task Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw() + { + // Arrange + var settings = BuildAppSettings(endpoint: null); + + // Act + Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + await func.ShouldThrowAsync(); + } + + [Trait("Category", "UnitTest")] + [Fact] + public async Task Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Throw() + { + // Arrange + AppSettings settings = null!; + + // Act + Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + await func.ShouldThrowAsync(); + } + [Trait("Category", "UnitTest")] [Theory] [InlineData(ConnectorType.Unknown)] @@ -79,4 +107,4 @@ public void Given_Concrete_Connectors_When_Checking_Inheritance_Then_Should_Inhe // Assert result.ShouldBeTrue(); } -} +} \ No newline at end of file From c4eb0588df02c64e7605e74b57cbc04a79784f7f Mon Sep 17 00:00:00 2001 From: sikutisa Date: Fri, 10 Oct 2025 00:52:19 +0900 Subject: [PATCH 06/21] fix: update tests Related to: #451 --- .../Connectors/GitHubModelsConnectorTests.cs | 5 +++-- .../Connectors/HuggingFaceConnectorTests.cs | 5 +++-- .../Connectors/OpenAIConnectorTests.cs | 3 --- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs index 15f39c85..a1c066e8 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs @@ -1,5 +1,3 @@ -using Humanizer; - using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -46,6 +44,7 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "GitHubModels:Endpoint")] [InlineData(" ", typeof(InvalidOperationException), "GitHubModels:Endpoint")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "GitHubModels:Endpoint")] public void Given_Invalid_Endpoint_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? endpoint, Type expectedType, string expectedMessage) { // Arrange @@ -65,6 +64,7 @@ public void Given_Invalid_Endpoint_When_EnsureLanguageModelSettingsValid_Invoked [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "GitHubModels:Token")] [InlineData(" ", typeof(InvalidOperationException), "GitHubModels:Token")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "GitHubModels:Token")] public void Given_Invalid_Token_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? token, Type expectedType, string expectedMessage) { // Arrange @@ -84,6 +84,7 @@ public void Given_Invalid_Token_When_EnsureLanguageModelSettingsValid_Invoked_Th [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "GitHubModels:Model")] [InlineData(" ", typeof(InvalidOperationException), "GitHubModels:Model")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "GitHubModels:Model")] public void Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? model, Type expectedType, string expectedMessage) { // Arrange diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index 6a1a6065..672c35a4 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -1,4 +1,3 @@ -using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -43,6 +42,7 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "HuggingFace:BaseUrl")] [InlineData(" ", typeof(InvalidOperationException), "HuggingFace:BaseUrl")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "HuggingFace:BaseUrl")] public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? baseUrl, Type expectedType, string expectedMessage) { // Arrange @@ -62,6 +62,7 @@ public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_ [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "HuggingFace:Model")] [InlineData(" ", typeof(InvalidOperationException), "HuggingFace:Model")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "HuggingFace:Model")] [InlineData("hf.co/org/model", typeof(InvalidOperationException), "HuggingFace:Model format")] [InlineData("org/model-gguf", typeof(InvalidOperationException), "HuggingFace:Model format")] [InlineData("hf.co//model-gguf", typeof(InvalidOperationException), "HuggingFace:Model format")] @@ -127,4 +128,4 @@ public async Task Given_Missing_BaseUrl_When_GetChatClient_Invoked_Then_It_Shoul var ex = await func.ShouldThrowAsync(expected); ex.Message.ShouldContain(message); } -} +} \ No newline at end of file diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs index ccee3761..c5581b7f 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs @@ -1,6 +1,3 @@ -using Microsoft.Extensions.AI; - -using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; From 9d7badef762ab034768deab6f7c2e93f8c447823 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Fri, 10 Oct 2025 21:39:49 +0900 Subject: [PATCH 07/21] fix: update LanguageModelConnectorTests Related to: #451 --- .../LanguageModelConnectorTests.cs | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs index 816a854b..1b219af8 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs @@ -40,7 +40,7 @@ public async Task Given_GitHubModels_Settings_When_CreateChatClient_Invoked_Then [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw() + public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw() { // Arrange var settings = BuildAppSettings(endpoint: null); @@ -49,12 +49,12 @@ public async Task Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - await func.ShouldThrowAsync(); + func.ShouldThrow(); } [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Throw() + public void Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Throw() { // Arrange AppSettings settings = null!; @@ -63,12 +63,20 @@ public async Task Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Shou Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - await func.ShouldThrowAsync(); + func.ShouldThrow(); } [Trait("Category", "UnitTest")] [Theory] [InlineData(ConnectorType.Unknown)] + [InlineData(ConnectorType.AmazonBedrock)] + [InlineData(ConnectorType.GoogleVertexAI)] + [InlineData(ConnectorType.DockerModelRunner)] + [InlineData(ConnectorType.FoundryLocal)] + [InlineData(ConnectorType.Ollama)] + [InlineData(ConnectorType.Anthropic)] + [InlineData(ConnectorType.Naver)] + [InlineData(ConnectorType.Upstage)] public async Task Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_Then_It_Should_Throw(ConnectorType connectorType) { // Arrange @@ -84,7 +92,7 @@ public async Task Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_ [Trait("Category", "UnitTest")] [Theory] // [InlineData(typeof(AmazonBedrockConnector))] - // [InlineData(typeof(AzureAIFoundryConnector))] + [InlineData(typeof(AzureAIFoundryConnector))] [InlineData(typeof(GitHubModelsConnector))] // [InlineData(typeof(GoogleVertexAIConnector))] // [InlineData(typeof(DockerModelRunnerConnector))] @@ -92,7 +100,7 @@ public async Task Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_ [InlineData(typeof(HuggingFaceConnector))] // [InlineData(typeof(OllamaConnector))] // [InlineData(typeof(AnthropicConnector))] - // [InlineData(typeof(LGConnector))] + [InlineData(typeof(LGConnector))] // [InlineData(typeof(NaverConnector))] [InlineData(typeof(OpenAIConnector))] // [InlineData(typeof(UpstageConnector))] @@ -100,11 +108,13 @@ public void Given_Concrete_Connectors_When_Checking_Inheritance_Then_Should_Inhe { // Arrange var baseType = typeof(LanguageModelConnector); - + // Act - var result = baseType.IsAssignableFrom(derivedType); + var isBaseAssignableFromDerived = baseType.IsAssignableFrom(derivedType); + var isDerivedAssignableFromBase = derivedType.IsAssignableFrom(baseType); // Assert - result.ShouldBeTrue(); + isBaseAssignableFromDerived.ShouldBeTrue(); + isDerivedAssignableFromBase.ShouldBeFalse(); } } \ No newline at end of file From 5b6149e6f45a8b2f051a7a654a60844d4e5f97c9 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Wed, 15 Oct 2025 18:45:14 +0900 Subject: [PATCH 08/21] fix: update ArgumentOptions inheritance test Related to: #451 --- .../Abstractions/ArgumentOptionsTests.cs | 24 ------------------- .../AmazonBedrockArgumentOptionsTests.cs | 14 +++++++++++ .../GitHubModelsArgumentOptionsTests.cs | 14 +++++++++++ .../GoogleVertexAIArgumentOptionsTests.cs | 14 +++++++++++ .../HuggingFaceArgumentOptionsTests.cs | 14 +++++++++++ .../Options/OpenAIArgumentOptionsTests.cs | 14 +++++++++++ .../Options/UpstageArgumentOptionsTests.cs | 14 +++++++++++ 7 files changed, 84 insertions(+), 24 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs index 580ff5a6..644a2994 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs @@ -280,30 +280,6 @@ public void Given_Help_When_Parse_Invoked_Then_It_Should_Return_Help(string argu settings.Help.ShouldBe(expected); } - [Trait("Category", "UnitTest")] - [Theory] - [InlineData(typeof(AmazonBedrockArgumentOptions))] - [InlineData(typeof(AzureAIFoundryArgumentOptions))] - [InlineData(typeof(GitHubModelsArgumentOptions))] - [InlineData(typeof(GoogleVertexAIArgumentOptions))] - [InlineData(typeof(DockerModelRunnerArgumentOptions))] - [InlineData(typeof(FoundryLocalArgumentOptions))] - [InlineData(typeof(HuggingFaceArgumentOptions))] - [InlineData(typeof(OllamaArgumentOptions))] - [InlineData(typeof(AnthropicArgumentOptions))] - [InlineData(typeof(LGArgumentOptions))] - // [InlineData(typeof(NaverArgumentOptions))] - [InlineData(typeof(OpenAIArgumentOptions))] - [InlineData(typeof(UpstageArgumentOptions))] - public void Given_Concrete_ArgumentOptions_When_Checking_Inheritance_Then_Should_Inherit_From_ArgumentOptions(Type type) - { - // Act - var isSubclass = type.IsSubclassOf(typeof(ArgumentOptions)); - - // Assert - isSubclass.ShouldBeTrue(); - } - [Trait("Category", "UnitTest")] [Theory] [InlineData(AppSettingConstants.ConnectorType, "AmazonBedrock", "AmazonBedrock:ModelId", "test-model-id", "test-model-id")] diff --git a/test/OpenChat.PlaygroundApp.Tests/Options/AmazonBedrockArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Options/AmazonBedrockArgumentOptionsTests.cs index eaa1989d..584550cd 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Options/AmazonBedrockArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Options/AmazonBedrockArgumentOptionsTests.cs @@ -3,6 +3,7 @@ using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Connectors; using OpenChat.PlaygroundApp.Constants; +using OpenChat.PlaygroundApp.Options; namespace OpenChat.PlaygroundApp.Tests.Options; @@ -83,6 +84,19 @@ private static IConfiguration BuildConfigWithAmazonBedrock( .Build(); } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(ArgumentOptions), typeof(AmazonBedrockArgumentOptions), true)] + [InlineData(typeof(AmazonBedrockArgumentOptions), typeof(ArgumentOptions), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Nothing_When_Parse_Invoked_Then_It_Should_Set_Config() diff --git a/test/OpenChat.PlaygroundApp.Tests/Options/GitHubModelsArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Options/GitHubModelsArgumentOptionsTests.cs index 4ee847f9..e9f2e7df 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Options/GitHubModelsArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Options/GitHubModelsArgumentOptionsTests.cs @@ -3,6 +3,7 @@ using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Connectors; using OpenChat.PlaygroundApp.Constants; +using OpenChat.PlaygroundApp.Options; namespace OpenChat.PlaygroundApp.Tests.Options; @@ -72,6 +73,19 @@ private static IConfiguration BuildConfigWithGitHubModels( .Build(); } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(ArgumentOptions), typeof(GitHubModelsArgumentOptions), true)] + [InlineData(typeof(GitHubModelsArgumentOptions), typeof(ArgumentOptions), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Nothing_When_Parse_Invoked_Then_It_Should_Set_Config() diff --git a/test/OpenChat.PlaygroundApp.Tests/Options/GoogleVertexAIArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Options/GoogleVertexAIArgumentOptionsTests.cs index c2c0fbec..ddff6eb8 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Options/GoogleVertexAIArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Options/GoogleVertexAIArgumentOptionsTests.cs @@ -3,6 +3,7 @@ using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Connectors; using OpenChat.PlaygroundApp.Constants; +using OpenChat.PlaygroundApp.Options; namespace OpenChat.PlaygroundApp.Tests.Options; @@ -56,6 +57,19 @@ private static IConfiguration BuildConfigWithGoogleVertexAI( .Build(); } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(ArgumentOptions), typeof(GoogleVertexAIArgumentOptions), true)] + [InlineData(typeof(GoogleVertexAIArgumentOptions), typeof(ArgumentOptions), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Nothing_When_Parse_Invoked_Then_It_Should_Set_Config() diff --git a/test/OpenChat.PlaygroundApp.Tests/Options/HuggingFaceArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Options/HuggingFaceArgumentOptionsTests.cs index 74ed38db..10277e77 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Options/HuggingFaceArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Options/HuggingFaceArgumentOptionsTests.cs @@ -3,6 +3,7 @@ using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Connectors; using OpenChat.PlaygroundApp.Constants; +using OpenChat.PlaygroundApp.Options; namespace OpenChat.PlaygroundApp.Tests.Options; @@ -59,6 +60,19 @@ private static IConfiguration BuildConfigWithHuggingFace( .Build(); } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(ArgumentOptions), typeof(HuggingFaceArgumentOptions), true)] + [InlineData(typeof(HuggingFaceArgumentOptions), typeof(ArgumentOptions), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Nothing_When_Parse_Invoked_Then_It_Should_Set_Config() diff --git a/test/OpenChat.PlaygroundApp.Tests/Options/OpenAIArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Options/OpenAIArgumentOptionsTests.cs index cc05113f..7b79e234 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Options/OpenAIArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Options/OpenAIArgumentOptionsTests.cs @@ -3,6 +3,7 @@ using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Connectors; using OpenChat.PlaygroundApp.Constants; +using OpenChat.PlaygroundApp.Options; namespace OpenChat.PlaygroundApp.Tests.Options; @@ -58,6 +59,19 @@ private static IConfiguration BuildConfigWithOpenAI( .Build(); } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(ArgumentOptions), typeof(OpenAIArgumentOptions), true)] + [InlineData(typeof(OpenAIArgumentOptions), typeof(ArgumentOptions), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Nothing_When_Parse_Invoked_Then_It_Should_Set_Config() diff --git a/test/OpenChat.PlaygroundApp.Tests/Options/UpstageArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Options/UpstageArgumentOptionsTests.cs index 2a07716a..7c2b237f 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Options/UpstageArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Options/UpstageArgumentOptionsTests.cs @@ -3,6 +3,7 @@ using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Connectors; using OpenChat.PlaygroundApp.Constants; +using OpenChat.PlaygroundApp.Options; namespace OpenChat.PlaygroundApp.Tests.Options; @@ -70,6 +71,19 @@ private static IConfiguration BuildConfigWithUpstage( .Build(); } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(ArgumentOptions), typeof(UpstageArgumentOptions), true)] + [InlineData(typeof(UpstageArgumentOptions), typeof(ArgumentOptions), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Nothing_When_Parse_Invoked_Then_It_Should_Set_Config() From 6e324b28049f0d183d587433678389452efeb183 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Wed, 15 Oct 2025 18:50:09 +0900 Subject: [PATCH 09/21] fix: update LanguageModelSettingsTests Related to: #451 --- .../Abstractions/LanguageModelConnectorTests.cs | 1 - .../Abstractions/LanguageModelSettingsTests.cs | 11 ++++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs index 1b219af8..6b6c014a 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs @@ -76,7 +76,6 @@ public void Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Thr [InlineData(ConnectorType.Ollama)] [InlineData(ConnectorType.Anthropic)] [InlineData(ConnectorType.Naver)] - [InlineData(ConnectorType.Upstage)] public async Task Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_Then_It_Should_Throw(ConnectorType connectorType) { // Arrange diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelSettingsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelSettingsTests.cs index 19a0de34..af10db9b 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelSettingsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelSettingsTests.cs @@ -22,10 +22,15 @@ public class LanguageModelSettingsTests [InlineData(typeof(UpstageSettings))] public void Given_Concrete_Settings_When_Checking_Inheritance_Then_Should_Inherit_From_LanguageModelSettings(Type type) { - // Act - var isSubclass = type.IsSubclassOf(typeof(LanguageModelSettings)); + // Arrange + var baseType = typeof(LanguageModelSettings); + // Act + var isBaseAssignableFromDerived = baseType.IsAssignableFrom(type); + var isDerivedAssignableFromBase = type.IsAssignableFrom(baseType); + // Assert - isSubclass.ShouldBeTrue(); + isBaseAssignableFromDerived.ShouldBeTrue(); + isDerivedAssignableFromBase.ShouldBeFalse(); } } \ No newline at end of file From 2e13c0a1d35315b9275693bca75822066e8d1ee1 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Wed, 15 Oct 2025 22:26:08 +0900 Subject: [PATCH 10/21] fix: update LanguageModelConnectorTests Related to: #451 --- .../LanguageModelConnectorTests.cs | 45 +++++-------------- 1 file changed, 11 insertions(+), 34 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs index 6b6c014a..dc52a413 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/LanguageModelConnectorTests.cs @@ -1,3 +1,5 @@ +using Microsoft.Extensions.AI; + using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -36,6 +38,7 @@ public async Task Given_GitHubModels_Settings_When_CreateChatClient_Invoked_Then // Assert client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); } [Trait("Category", "UnitTest")] @@ -49,7 +52,8 @@ public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Sh Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - func.ShouldThrow(); + func.ShouldThrow() + .Message.ShouldContain("Object reference not set to an instance of an object."); } [Trait("Category", "UnitTest")] @@ -63,7 +67,8 @@ public void Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Thr Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - func.ShouldThrow(); + func.ShouldThrow() + .Message.ShouldContain("Object reference not set to an instance of an object."); } [Trait("Category", "UnitTest")] @@ -76,44 +81,16 @@ public void Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Thr [InlineData(ConnectorType.Ollama)] [InlineData(ConnectorType.Anthropic)] [InlineData(ConnectorType.Naver)] - public async Task Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_Then_It_Should_Throw(ConnectorType connectorType) + public void Given_Unsupported_ConnectorType_When_CreateChatClient_Invoked_Then_It_Should_Throw(ConnectorType connectorType) { // Arrange var settings = BuildAppSettings(connectorType: connectorType); // Act - var ex = await Assert.ThrowsAsync(() => LanguageModelConnector.CreateChatClientAsync(settings)); - - // Assert - ex.Message.ShouldContain($"Connector type '{connectorType}'"); - } - - [Trait("Category", "UnitTest")] - [Theory] - // [InlineData(typeof(AmazonBedrockConnector))] - [InlineData(typeof(AzureAIFoundryConnector))] - [InlineData(typeof(GitHubModelsConnector))] - // [InlineData(typeof(GoogleVertexAIConnector))] - // [InlineData(typeof(DockerModelRunnerConnector))] - // [InlineData(typeof(FoundryLocalConnector))] - [InlineData(typeof(HuggingFaceConnector))] - // [InlineData(typeof(OllamaConnector))] - // [InlineData(typeof(AnthropicConnector))] - [InlineData(typeof(LGConnector))] - // [InlineData(typeof(NaverConnector))] - [InlineData(typeof(OpenAIConnector))] - // [InlineData(typeof(UpstageConnector))] - public void Given_Concrete_Connectors_When_Checking_Inheritance_Then_Should_Inherit_From_LanguageModelConnector(Type derivedType) - { - // Arrange - var baseType = typeof(LanguageModelConnector); - - // Act - var isBaseAssignableFromDerived = baseType.IsAssignableFrom(derivedType); - var isDerivedAssignableFromBase = derivedType.IsAssignableFrom(baseType); + Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - isBaseAssignableFromDerived.ShouldBeTrue(); - isDerivedAssignableFromBase.ShouldBeFalse(); + func.ShouldThrow() + .Message.ShouldContain($"Connector type '{connectorType}'"); } } \ No newline at end of file From e857911882ce512503a4ac68b73d0394ec0bda1a Mon Sep 17 00:00:00 2001 From: sikutisa Date: Wed, 15 Oct 2025 22:48:35 +0900 Subject: [PATCH 11/21] fix: update AzureFoundryConnectorTests Related to: #451 --- .../Connectors/AzureAIFoundryConnectorTests.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs index 8cd46b31..5992f43f 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs @@ -90,6 +90,7 @@ public void Given_Null_Settings_When_EnsureLanguageModelSettingsValid_Invoked_Th [InlineData(null, typeof(InvalidOperationException), "AzureAIFoundry:Endpoint")] [InlineData("", typeof(InvalidOperationException), "AzureAIFoundry:Endpoint")] [InlineData(" ", typeof(InvalidOperationException), "AzureAIFoundry:Endpoint")] + [InlineData("\t\r\n", typeof(InvalidOperationException), "AzureAIFoundry:Endpoint")] public void Given_Invalid_Endpoint_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? endpoint, Type expectedType, string expectedMessage) { // Arrange @@ -109,6 +110,7 @@ public void Given_Invalid_Endpoint_When_EnsureLanguageModelSettingsValid_Invoked [InlineData(null, typeof(InvalidOperationException), "AzureAIFoundry:ApiKey")] [InlineData("", typeof(InvalidOperationException), "AzureAIFoundry:ApiKey")] [InlineData(" ", typeof(InvalidOperationException), "AzureAIFoundry:ApiKey")] + [InlineData("\t\r\n", typeof(InvalidOperationException), "AzureAIFoundry:ApiKey")] public void Given_Invalid_ApiKey_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? apiKey, Type expectedType, string expectedMessage) { // Arrange @@ -128,6 +130,7 @@ public void Given_Invalid_ApiKey_When_EnsureLanguageModelSettingsValid_Invoked_T [InlineData(null, typeof(InvalidOperationException), "AzureAIFoundry:DeploymentName")] [InlineData("", typeof(InvalidOperationException), "AzureAIFoundry:DeploymentName")] [InlineData(" ", typeof(InvalidOperationException), "AzureAIFoundry:DeploymentName")] + [InlineData("\t\r\n", typeof(InvalidOperationException), "AzureAIFoundry:DeploymentName")] public void Given_Invalid_DeploymentName_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? deploymentName, Type expectedType, string expectedMessage) { // Arrange @@ -159,7 +162,7 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T [Trait("Category", "UnitTest")] [Fact] - public void Given_Null_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() + public void Given_Null_AzureAIFoundrySettings_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() { // Arrange var settings = new AppSettings @@ -170,7 +173,7 @@ public void Given_Null_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_T var connector = new AzureAIFoundryConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow() From 629327d52ee13074f1bf6fcc3c14287209cdbae3 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Wed, 15 Oct 2025 23:17:01 +0900 Subject: [PATCH 12/21] fix: update GithubModelsConnectorsTests Related to: #451 --- .../Connectors/GitHubModelsConnectorTests.cs | 141 ++++++++++++++++-- 1 file changed, 128 insertions(+), 13 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs index a1c066e8..51868bcb 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs @@ -1,3 +1,6 @@ +using Microsoft.Extensions.AI; + +using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -23,12 +26,55 @@ private static AppSettings BuildAppSettings(string? endpoint = Endpoint, string? }; } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(LanguageModelConnector), typeof(GitHubModelsConnector), true)] + [InlineData(typeof(GitHubModelsConnector), typeof(LanguageModelConnector), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Null_Settings_When_Instantiated_Then_It_Should_Throw() + { + // Act + Action action = () => new GitHubModelsConnector(null!); + + // Assert + action.ShouldThrow() + .Message.ShouldContain("settings"); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Settings_When_Instantiated_Then_It_Should_Return() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = new GitHubModelsConnector(settings); + + // Assert + result.ShouldNotBeNull(); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw() { // Arrange - var settings = new AppSettings { ConnectorType = ConnectorType.GitHubModels, GitHubModels = null }; + var settings = new AppSettings + { + ConnectorType = ConnectorType.GitHubModels, + GitHubModels = null + }; var connector = new GitHubModelsConnector(settings); // Act @@ -116,24 +162,29 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should_Return_ChatClient() + public void Given_Null_GitHubModelsSettings_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() { // Arrange - var settings = BuildAppSettings(); + var settings = new AppSettings + { + ConnectorType = ConnectorType.GitHubModels, + GitHubModels = null + }; var connector = new GitHubModelsConnector(settings); // Act - var client = await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert - client.ShouldNotBeNull(); + func.ShouldThrow() + .Message.ShouldContain("Missing configuration"); } [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(InvalidOperationException), "GitHubModels:Token")] [InlineData("", typeof(ArgumentException), "key")] - public async Task Given_Missing_Token_When_GetChatClient_Invoked_Then_It_Should_Throw(string? token, Type expected, string message) + public void Given_Missing_Token_When_GetChatClient_Invoked_Then_It_Should_Throw(string? token, Type expected, string message) { // Arrange var settings = BuildAppSettings(token: token); @@ -143,15 +194,15 @@ public async Task Given_Missing_Token_When_GetChatClient_Invoked_Then_It_Should_ Func func = connector.GetChatClientAsync; // Assert - var ex = await func.ShouldThrowAsync(expected); - ex.Message.ShouldContain(message); + func.ShouldThrow(expected) + .Message.ShouldContain(message); } [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(InvalidOperationException), "GitHubModels:Endpoint")] [InlineData("", typeof(UriFormatException), "empty")] - public async Task Given_Missing_Endpoint_When_GetChatClient_Invoked_Then_It_Should_Throw(string? endpoint, Type expected, string message) + public void Given_Missing_Endpoint_When_GetChatClient_Invoked_Then_It_Should_Throw(string? endpoint, Type expected, string message) { // Arrange var settings = BuildAppSettings(endpoint: endpoint); @@ -161,8 +212,8 @@ public async Task Given_Missing_Endpoint_When_GetChatClient_Invoked_Then_It_Shou Func func = connector.GetChatClientAsync; // Assert - var ex = await func.ShouldThrowAsync(expected); - ex.Message.ShouldContain(message); + func.ShouldThrow(expected) + .Message.ShouldContain(message); } [Trait("Category", "UnitTest")] @@ -179,7 +230,71 @@ public async Task Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_ Func func = connector.GetChatClientAsync; // Assert - var ex = await func.ShouldThrowAsync(expected); - ex.Message.ShouldContain(message); + func.ShouldThrow(expected) + .Message.ShouldContain(message); + } + + [Trait("Category", "UnitTest")] + [Fact] + public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should_Return_ChatClient() + { + // Arrange + var settings = BuildAppSettings(); + var connector = new GitHubModelsConnector(settings); + + // Act + var client = await connector.GetChatClientAsync(); + + // Assert + client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); + } + + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(null, null, null, typeof(NullReferenceException), "Object reference not set to an instance of an object.")] + [InlineData("", Token, Model, typeof(InvalidOperationException), "Missing configuration: GitHubModels:Endpoint")] + [InlineData(" ", Token, Model, typeof(InvalidOperationException), "Missing configuration: GitHubModels:Endpoint")] + [InlineData(Endpoint, null, Model, typeof(NullReferenceException), "Object reference not set to an instance of an object.")] + [InlineData(Endpoint, "", Model, typeof(InvalidOperationException), "Missing configuration: GitHubModels:Token")] + [InlineData(Endpoint, " ", Model, typeof(InvalidOperationException), "Missing configuration: GitHubModels:Token")] + [InlineData(Endpoint, Token, null, typeof(NullReferenceException), "Object reference not set to an instance of an object.")] + [InlineData(Endpoint, Token, "", typeof(InvalidOperationException), "Missing configuration: GitHubModels:Model")] + [InlineData(Endpoint, Token, " ", typeof(InvalidOperationException), "Missing configuration: GitHubModels:Model")] + public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? endpoint, string? token, string? model, Type expected, string expectedMessage) + { + // Arrange + var settings = new AppSettings + { + ConnectorType = ConnectorType.GitHubModels, + GitHubModels = new GitHubModelsSettings + { + Endpoint = endpoint, + Token = token, + Model = model + } + }; + + // Act + Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + func.ShouldThrow(expected) + .Message.ShouldContain(expectedMessage); + } + + [Trait("Category", "UnitTest")] + [Fact] + public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_IChatClient() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + result.ShouldNotBeNull(); + result.ShouldBeAssignableTo(); } } From 8e2e11d48ba149cf5d29519915ae94f5ce68b6f9 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Wed, 15 Oct 2025 23:48:35 +0900 Subject: [PATCH 13/21] fix: update OpenAIconnectorTests Related to: #451 --- .../AzureAIFoundryConnectorTests.cs | 3 +- .../Connectors/OpenAIConnectorTests.cs | 154 +++++++++++++----- 2 files changed, 119 insertions(+), 38 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs index 5992f43f..e20932f4 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs @@ -230,7 +230,7 @@ public void Given_Invalid_DeploymentName_When_GetChatClientAsync_Invoked_Then_It var connector = new AzureAIFoundryConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow() @@ -250,6 +250,7 @@ public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should // Assert result.ShouldNotBeNull(); + result.ShouldBeAssignableTo(); } [Trait("Category", "UnitTest")] diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs index c5581b7f..5f8abb07 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs @@ -1,3 +1,6 @@ +using Microsoft.Extensions.AI; + +using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -21,12 +24,54 @@ private static AppSettings BuildAppSettings(string? apiKey = ApiKey, string? mod }; } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(LanguageModelConnector), typeof(OpenAIConnector), true)] + [InlineData(typeof(OpenAIConnector), typeof(LanguageModelConnector), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Null_Settings_When_Instantiated_Then_It_Should_Throw() + { + // Act + Action action = () => new OpenAIConnector(null!); + + // Assert + action.ShouldThrow() + .Message.ShouldContain("settings"); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Settings_When_Instantiated_Then_It_Should_Return() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = new OpenAIConnector(settings); + + // Assert + result.ShouldNotBeNull(); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw() { // Arrange - var settings = new AppSettings { ConnectorType = ConnectorType.OpenAI, OpenAI = null }; + var settings = new AppSettings { + ConnectorType = ConnectorType.OpenAI, + OpenAI = null + }; var connector = new OpenAIConnector(settings); // Act @@ -57,21 +102,6 @@ public void Given_Invalid_ApiKey_When_EnsureLanguageModelSettingsValid_Invoked_T .Message.ShouldContain(expectedMessage); } - [Trait("Category", "UnitTest")] - [Fact] - public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Return_True() - { - // Arrange - var settings = BuildAppSettings(); - var connector = new OpenAIConnector(settings); - - // Act - var result = connector.EnsureLanguageModelSettingsValid(); - - // Assert - result.ShouldBeTrue(); - } - [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] @@ -91,43 +121,47 @@ public void Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Th action.ShouldThrow(expectedType) .Message.ShouldContain(expectedMessage); } - + [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Valid_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Return_ChatClient() + public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Return_True() { // Arrange var settings = BuildAppSettings(); var connector = new OpenAIConnector(settings); // Act - var client = await connector.GetChatClientAsync(); + var result = connector.EnsureLanguageModelSettingsValid(); // Assert - client.ShouldNotBeNull(); + result.ShouldBeTrue(); } - + [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() + public void Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() { // Arrange - var settings = new AppSettings { ConnectorType = ConnectorType.OpenAI, OpenAI = null! }; + var settings = new AppSettings + { + ConnectorType = ConnectorType.OpenAI, + OpenAI = null! + }; var connector = new OpenAIConnector(settings); // Act Func func = connector.GetChatClientAsync; // Assert - var ex = await func.ShouldThrowAsync(); - ex.Message.ShouldContain("Missing configuration: OpenAI:ApiKey."); + func.ShouldThrow() + .Message.ShouldContain("Missing configuration"); } - + [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(InvalidOperationException), "OpenAI:ApiKey")] [InlineData("", typeof(ArgumentException), "key")] - public async Task Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? apiKey, Type expected, string message) + public void Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? apiKey, Type expected, string message) { // Arrange var settings = BuildAppSettings(apiKey: apiKey); @@ -137,15 +171,15 @@ public async Task Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_S Func func = connector.GetChatClientAsync; // Assert - var ex = await func.ShouldThrowAsync(expected); - ex.Message.ShouldContain(message); + func.ShouldThrow(expected) + .Message.ShouldContain(message); } - + [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(ArgumentNullException), "model")] [InlineData("", typeof(ArgumentException), "model")] - public async Task Given_Missing_Model_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) + public void Given_Missing_Model_When_GetChatClientAsync_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) { // Arrange var settings = BuildAppSettings(model: model); @@ -155,22 +189,68 @@ public async Task Given_Missing_Model_When_GetChatClientAsync_Invoked_Then_It_Sh Func func = connector.GetChatClientAsync; // Assert - var ex = await func.ShouldThrowAsync(expected); - ex.Message.ShouldContain(message); + func.ShouldThrow(expected) + .Message.ShouldContain(message); } [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Valid_Format_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Pass() + public async Task Given_Valid_Settings_When_GetChatClientAsync_Invoked_Then_It_Should_Return_ChatClient() { // Arrange var settings = BuildAppSettings(); var connector = new OpenAIConnector(settings); // Act - Func func = connector.GetChatClientAsync; - + var client = await connector.GetChatClientAsync(); + + // Assert + client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); + } + + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(null, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData(null, Model, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData("", Model, typeof(InvalidOperationException), "Missing configuration: OpenAI")] + [InlineData(" ", Model, typeof(InvalidOperationException), "Missing configuration: OpenAI")] + [InlineData(ApiKey, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData(ApiKey, "", typeof(InvalidOperationException), "Missing configuration: OpenAI")] + [InlineData(ApiKey, " ", typeof(InvalidOperationException), "Missing configuration: OpenAI")] + public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? apiKey, string? model, Type expected, string expectedMessage) + { + // Arrange + var settings = new AppSettings + { + ConnectorType = ConnectorType.OpenAI, + OpenAI = new OpenAISettings + { + ApiKey = apiKey, + Model = model + } + }; + + // Act + Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + func.ShouldThrow(expected) + .Message.ShouldContain(expectedMessage); + } + + [Trait("Category", "UnitTest")] + [Fact] + public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_IChatClient() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = await LanguageModelConnector.CreateChatClientAsync(settings); + // Assert - await func.ShouldNotThrowAsync(); + result.ShouldNotBeNull(); + result.ShouldBeAssignableTo(); } } \ No newline at end of file From a972e8dea98538171f4556504f2cdd2d89dd29ed Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 00:02:32 +0900 Subject: [PATCH 14/21] fix: update UpstageConnectorTests Related to: #451 --- .../AzureAIFoundryConnectorTests.cs | 4 +- .../Connectors/UpstageConnectorTests.cs | 113 ++++++++++++------ 2 files changed, 79 insertions(+), 38 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs index e20932f4..8a73749e 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs @@ -194,7 +194,7 @@ public void Given_Invalid_Endpoint_When_GetChatClientAsync_Invoked_Then_It_Shoul var connector = new AzureAIFoundryConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow(expectedType) @@ -300,4 +300,4 @@ public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_I result.ShouldNotBeNull(); result.ShouldBeAssignableTo(); } -} +} \ No newline at end of file diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs index 88d158cd..8b65a6ca 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs @@ -1,11 +1,11 @@ +using Microsoft.Extensions.AI; + using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; namespace OpenChat.PlaygroundApp.Tests.Connectors; - - public class UpstageConnectorTests { private const string BaseUrl = "https://api.upstage.ai/v1/solar"; @@ -39,12 +39,41 @@ public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type bas result.ShouldBe(expected); } + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Null_Settings_When_Instantiated_Then_It_Should_Throw() + { + // Act + Action action = () => new UpstageConnector(null!); + + // Assert + action.ShouldThrow() + .Message.ShouldContain("Object reference not set to an instance of an object"); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Settings_When_Instantiated_Then_It_Should_Return() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = new UpstageConnector(settings); + + // Assert + result.ShouldNotBeNull(); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw() { // Arrange - var appSettings = new AppSettings { ConnectorType = ConnectorType.Upstage, Upstage = null }; + var appSettings = new AppSettings { + ConnectorType = ConnectorType.Upstage, + Upstage = null + }; var connector = new UpstageConnector(appSettings); // Act @@ -60,6 +89,7 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked [InlineData(null, typeof(InvalidOperationException), "Upstage:BaseUrl")] [InlineData("", typeof(InvalidOperationException), "Upstage:BaseUrl")] [InlineData(" ", typeof(InvalidOperationException), "Upstage:BaseUrl")] + [InlineData("\t\r\n", typeof(InvalidOperationException), "Upstage:BaseUrl")] public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? baseUrl, Type expectedType, string expectedMessage) { // Arrange @@ -79,6 +109,7 @@ public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_ [InlineData(null, typeof(InvalidOperationException), "Upstage:ApiKey")] [InlineData("", typeof(InvalidOperationException), "Upstage:ApiKey")] [InlineData(" ", typeof(InvalidOperationException), "Upstage:ApiKey")] + [InlineData("\t\r\n", typeof(InvalidOperationException), "Upstage:ApiKey")] public void Given_Invalid_ApiKey_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? apiKey, Type expectedType, string expectedMessage) { // Arrange @@ -98,6 +129,7 @@ public void Given_Invalid_ApiKey_When_EnsureLanguageModelSettingsValid_Invoked_T [InlineData(null, typeof(InvalidOperationException), "Upstage:Model")] [InlineData("", typeof(InvalidOperationException), "Upstage:Model")] [InlineData(" ", typeof(InvalidOperationException), "Upstage:Model")] + [InlineData("\t\r\n", typeof(InvalidOperationException), "Upstage:Model")] public void Given_Invalid_Model_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? model, Type expectedType, string expectedMessage) { // Arrange @@ -129,47 +161,39 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should_Return_ChatClient() + public void Given_Null_UpstageSettings_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() { // Arrange - var settings = BuildAppSettings(); + var settings = new AppSettings + { + ConnectorType = ConnectorType.Upstage, + Upstage = null + }; var connector = new UpstageConnector(settings); // Act - var client = await connector.GetChatClientAsync(); - - // Assert - client.ShouldNotBeNull(); - } - - [Trait("Category", "UnitTest")] - [Fact] - public void Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Should_Throw() - { - // Arrange - var appSettings = new AppSettings { ConnectorType = ConnectorType.Upstage, Upstage = null }; - var connector = new UpstageConnector(appSettings); - - // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow() - .Message.ShouldContain("Missing configuration: Upstage:ApiKey."); + .Message.ShouldContain("Missing configuration"); } [Trait("Category", "UnitTest")] [Theory] - [InlineData(null, typeof(InvalidOperationException), "Upstage:ApiKey")] - [InlineData("", typeof(ArgumentException), "key")] - public void Given_Missing_ApiKey_When_GetChatClient_Invoked_Then_It_Should_Throw(string? apiKey, Type expected, string message) + [InlineData(null, typeof(InvalidOperationException), "Upstage:BaseUrl")] + [InlineData("", typeof(UriFormatException), "empty")] + [InlineData("invalid-uri-format", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + [InlineData("not-a-url", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + public void Given_Missing_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expected, string message) { // Arrange - var settings = BuildAppSettings(apiKey: apiKey); + var settings = BuildAppSettings(baseUrl: baseUrl); var connector = new UpstageConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow(expected) @@ -178,16 +202,16 @@ public void Given_Missing_ApiKey_When_GetChatClient_Invoked_Then_It_Should_Throw [Trait("Category", "UnitTest")] [Theory] - [InlineData(null, typeof(InvalidOperationException), "Upstage:BaseUrl")] - [InlineData("", typeof(UriFormatException), "empty")] - public void Given_Missing_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expected, string message) + [InlineData(null, typeof(InvalidOperationException), "Upstage:ApiKey")] + [InlineData("", typeof(ArgumentException), "key")] + public void Given_Missing_ApiKey_When_GetChatClient_Invoked_Then_It_Should_Throw(string? apiKey, Type expected, string message) { // Arrange - var settings = BuildAppSettings(baseUrl: baseUrl); + var settings = BuildAppSettings(apiKey: apiKey); var connector = new UpstageConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow(expected) @@ -205,7 +229,7 @@ public void Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_Throw( var connector = new UpstageConnector(settings); // Act - Func func = async () => await connector.GetChatClientAsync(); + Func func = connector.GetChatClientAsync; // Assert func.ShouldThrow(expected) @@ -214,16 +238,18 @@ public void Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_Throw( [Trait("Category", "UnitTest")] [Fact] - public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_ChatClient() + public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should_Return_ChatClient() { // Arrange var settings = BuildAppSettings(); + var connector = new UpstageConnector(settings); // Act - var client = await LanguageModelConnector.CreateChatClientAsync(settings); + var client = await connector.GetChatClientAsync(); // Assert client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); } [Trait("Category", "UnitTest")] @@ -258,4 +284,19 @@ public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Sh func.ShouldThrow(expectedType) .Message.ShouldContain(expectedMessage); } -} + + [Trait("Category", "UnitTest")] + [Fact] + public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_ChatClient() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var client = await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); + } +} \ No newline at end of file From 4a7b0af08e800ca392ca6703501ae14299557fc8 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 01:37:50 +0900 Subject: [PATCH 15/21] fix: update Connector tests Related to: #451 --- .../Abstractions/ArgumentOptionsTests.cs | 5 +- .../AzureAIFoundryConnectorTests.cs | 6 +- .../Connectors/GitHubModelsConnectorTests.cs | 8 +- .../Connectors/HuggingFaceConnectorTests.cs | 183 ++++++++++++++++-- .../Connectors/LGConnectorTests.cs | 11 +- .../Connectors/OpenAIConnectorTests.cs | 6 +- .../Connectors/UpstageConnectorTests.cs | 8 +- 7 files changed, 188 insertions(+), 39 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs b/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs index 644a2994..d3652000 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Abstractions/ArgumentOptionsTests.cs @@ -165,9 +165,10 @@ public void Given_Unimplemented_ConnectorType_When_Parse_Invoked_Then_It_Should_ var config = BuildConfig((key, value)); var args = Array.Empty(); - var ex = Assert.Throws(() => ArgumentOptions.Parse(config, args)); + var action = () => ArgumentOptions.Parse(config, args); - ex.Message.ShouldContain($"{value}ArgumentOptions"); + action.ShouldThrow() + .Message.ShouldContain($"{value}ArgumentOptions"); } [Trait("Category", "UnitTest")] diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs index 8a73749e..a1b073ea 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/AzureAIFoundryConnectorTests.cs @@ -173,7 +173,7 @@ public void Given_Null_AzureAIFoundrySettings_When_GetChatClientAsync_Invoked_Th var connector = new AzureAIFoundryConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow() @@ -194,7 +194,7 @@ public void Given_Invalid_Endpoint_When_GetChatClientAsync_Invoked_Then_It_Shoul var connector = new AzureAIFoundryConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expectedType) @@ -230,7 +230,7 @@ public void Given_Invalid_DeploymentName_When_GetChatClientAsync_Invoked_Then_It var connector = new AzureAIFoundryConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow() diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs index 51868bcb..d997683d 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs @@ -173,7 +173,7 @@ public void Given_Null_GitHubModelsSettings_When_GetChatClientAsync_Invoked_Then var connector = new GitHubModelsConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow() @@ -191,7 +191,7 @@ public void Given_Missing_Token_When_GetChatClient_Invoked_Then_It_Should_Throw( var connector = new GitHubModelsConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) @@ -209,7 +209,7 @@ public void Given_Missing_Endpoint_When_GetChatClient_Invoked_Then_It_Should_Thr var connector = new GitHubModelsConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) @@ -227,7 +227,7 @@ public async Task Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_ var connector = new GitHubModelsConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index 672c35a4..aa27e0a5 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -1,3 +1,6 @@ +using Microsoft.Extensions.AI; + +using OpenChat.PlaygroundApp.Abstractions; using OpenChat.PlaygroundApp.Configurations; using OpenChat.PlaygroundApp.Connectors; @@ -21,13 +24,42 @@ private static AppSettings BuildAppSettings(string? baseUrl = BaseUrl, string? m }; } + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(typeof(LanguageModelConnector), typeof(HuggingFaceConnector), true)] + [InlineData(typeof(HuggingFaceConnector), typeof(LanguageModelConnector), false)] + public void Given_BaseType_Then_It_Should_Be_AssignableFrom_DerivedType(Type baseType, Type derivedType, bool expected) + { + // Act + var result = baseType.IsAssignableFrom(derivedType); + + // Assert + result.ShouldBe(expected); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Null_Settings_When_Instantiated_Then_It_Should_Throw() + { + // Act + Action action = () => new HuggingFaceConnector(null!); + + // Assert + action.ShouldThrow() + .Message.ShouldContain("settings"); + } + [Trait("Category", "UnitTest")] [Fact] public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw() { - // Arrange - var settings = new AppSettings { ConnectorType = ConnectorType.HuggingFace, HuggingFace = null }; - var connector = new HuggingFaceConnector(settings); + // Arrange + var settings = new AppSettings + { + ConnectorType = ConnectorType.HuggingFace, + HuggingFace = null + }; + var connector = new HuggingFaceConnector(settings); // Act Action action = () => connector.EnsureLanguageModelSettingsValid(); @@ -37,6 +69,40 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked .Message.ShouldContain("HuggingFace"); } + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Settings_When_Instantiated_Then_It_Should_Return() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = new HuggingFaceConnector(settings); + + // Assert + result.ShouldNotBeNull(); + } + + [Trait("Category", "UnitTest")] + [Fact] + public void Given_Null_Settings_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw() + { + // Arrange + var settings = new AppSettings + { + ConnectorType = ConnectorType.HuggingFace, + HuggingFace = null + }; + var connector = new HuggingFaceConnector(settings); + + // Act + Action action = () => connector.EnsureLanguageModelSettingsValid(); + + // Assert + action.ShouldThrow() + .Message.ShouldContain("HuggingFace"); + } + [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] @@ -86,7 +152,7 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T { // Arrange var settings = BuildAppSettings(); - var connector = new HuggingFaceConnector(settings); + var connector = new HuggingFaceConnector(settings); // Act var result = connector.EnsureLanguageModelSettingsValid(); @@ -95,37 +161,112 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T result.ShouldBeTrue(); } - [Trait("Category", "IntegrationTest")] - [Trait("Category", "LLMRequired")] - [Fact] - public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should_Return_ChatClient() + [Trait("Category", "UnitTest")] + [Theory] + [InlineData(null, typeof(ArgumentNullException), "null")] + [InlineData("", typeof(UriFormatException), "empty")] + [InlineData("invalid-uri-format", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + [InlineData("not-a-url", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expected, string message) { // Arrange - var settings = BuildAppSettings(); - var connector = new HuggingFaceConnector(settings); + var settings = BuildAppSettings(baseUrl: baseUrl); + var connector = new HuggingFaceConnector(settings); // Act - var client = await connector.GetChatClientAsync(); + Func func = async () => await connector.GetChatClientAsync(); // Assert - client.ShouldNotBeNull(); + func.ShouldThrow(expected) + .Message.ShouldContain(message); } - [Trait("Category", "UnitTest")] + [Trait("Category", "IntegrationTest")] + [Trait("Category", "LLMRequired")] [Theory] - [InlineData(null, typeof(ArgumentNullException), "null")] - [InlineData("", typeof(UriFormatException), "empty")] - public async Task Given_Missing_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expected, string message) + [InlineData(null, typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData(" ", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("\t\n\r", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("hf.co/org/model", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("org/model-gguf", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("hf.co//model-gguf", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + public void Given_Invalid_Model_When_GetChatClient_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) + { + // Arrange + var settings = BuildAppSettings(model: model); + var connector = new HuggingFaceConnector(settings); + + // Act + Func func = async () => await connector.GetChatClientAsync(); + + // Assert + func.ShouldThrow(expected) + .Message.ShouldContain(message); + } + + [Trait("Category", "IntegrationTest")] + [Trait("Category", "LLMRequired")] + [Fact] + public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should_Return_ChatClient() { // Arrange - var settings = BuildAppSettings(baseUrl: baseUrl); - var connector = new HuggingFaceConnector(settings); + var settings = BuildAppSettings(); + var connector = new HuggingFaceConnector(settings); // Act - Func func = connector.GetChatClientAsync; + var client = await connector.GetChatClientAsync(); // Assert - var ex = await func.ShouldThrowAsync(expected); - ex.Message.ShouldContain(message); + client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); } + + [Trait("Category", "IntegrationTest")] + [Trait("Category", "LLMRequired")] + [Theory] + [InlineData(null, null, "Missing configuration: HUggingFace")] + [InlineData(null, Model, "Missing configuration: HUggingFace")] + [InlineData("", Model, "Missing configuration: HUggingFace")] + [InlineData(" ", Model, "Missing configuration: HUggingFace")] + [InlineData(BaseUrl, null, "Missing configuration: HUggingFace")] + [InlineData(BaseUrl, "", "Missing configuration: HUggingFace")] + [InlineData(BaseUrl, " ", "Missing configuration: HUggingFace")] + public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? baseUrl, string? model, string expectedMessage) + { + // Arrange + var settings = new AppSettings + { + ConnectorType = ConnectorType.HuggingFace, + HuggingFace = new HuggingFaceSettings + { + BaseUrl = baseUrl, + Model = model + } + }; + + // Act + Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + func.ShouldThrow() + .Message.ShouldContain(expectedMessage); + } + + [Trait("Category", "IntegrationTest")] + [Trait("Category", "LLMRequired")] + [Fact] + public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Return_IChatClient() + { + // Arrange + var settings = BuildAppSettings(); + + // Act + var result = await LanguageModelConnector.CreateChatClientAsync(settings); + + // Assert + result.ShouldNotBeNull(); + result.ShouldBeAssignableTo(); + } } \ No newline at end of file diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs index 4d9d11e5..fd634882 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs @@ -88,6 +88,7 @@ public void Given_Null_Settings_When_EnsureLanguageModelSettingsValid_Invoked_Th [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "LG:BaseUrl")] [InlineData(" ", typeof(InvalidOperationException), "LG:BaseUrl")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "LG:BaseUrl")] public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_Then_It_Should_Throw(string? baseUrl, Type expectedType, string expectedMessage) { // Arrange @@ -107,6 +108,7 @@ public void Given_Invalid_BaseUrl_When_EnsureLanguageModelSettingsValid_Invoked_ [InlineData(null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData("", typeof(InvalidOperationException), "LG:Model")] [InlineData(" ", typeof(InvalidOperationException), "LG:Model")] + [InlineData("\t\n\r", typeof(InvalidOperationException), "LG:Model")] [InlineData("invalid-model-format", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] [InlineData("random-name", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] [InlineData("hf.co/other-org/model-GGUF", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] @@ -148,6 +150,9 @@ public void Given_Valid_Model_Format_When_EnsureLanguageModelSettingsValid_Invok [Theory] [InlineData(null, typeof(ArgumentNullException), "null")] [InlineData("", typeof(UriFormatException), "empty")] + [InlineData("invalid-uri-format", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + [InlineData("not-a-url", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] + [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expectedType, string message) { // Arrange @@ -202,9 +207,11 @@ public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should // Assert client.ShouldNotBeNull(); + client.ShouldBeAssignableTo(); } - [Trait("Category", "UnitTest")] + [Trait("Category", "IntegrationTest")] + [Trait("Category", "LLMRequired")] [Theory] [InlineData(null, "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF", typeof(NullReferenceException))] [InlineData("", "hf.co/LGAI-EXAONE/EXAONE-4.0-32B-GGUF", typeof(InvalidOperationException))] @@ -245,4 +252,4 @@ public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_I result.ShouldNotBeNull(); result.ShouldBeAssignableTo(); } -} +} \ No newline at end of file diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs index 5f8abb07..95feeece 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/OpenAIConnectorTests.cs @@ -150,7 +150,7 @@ public void Given_Settings_Is_Null_When_GetChatClientAsync_Invoked_Then_It_Shoul var connector = new OpenAIConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow() @@ -168,7 +168,7 @@ public void Given_Missing_ApiKey_When_GetChatClientAsync_Invoked_Then_It_Should_ var connector = new OpenAIConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) @@ -186,7 +186,7 @@ public void Given_Missing_Model_When_GetChatClientAsync_Invoked_Then_It_Should_T var connector = new OpenAIConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs index 8b65a6ca..a1e9a417 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/UpstageConnectorTests.cs @@ -172,7 +172,7 @@ public void Given_Null_UpstageSettings_When_GetChatClientAsync_Invoked_Then_It_S var connector = new UpstageConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow() @@ -193,7 +193,7 @@ public void Given_Missing_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Thro var connector = new UpstageConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) @@ -211,7 +211,7 @@ public void Given_Missing_ApiKey_When_GetChatClient_Invoked_Then_It_Should_Throw var connector = new UpstageConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) @@ -229,7 +229,7 @@ public void Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_Throw( var connector = new UpstageConnector(settings); // Act - Func func = connector.GetChatClientAsync; + Func func = async () => await connector.GetChatClientAsync(); // Assert func.ShouldThrow(expected) From f7ee5d97ef747e8497746f16f3e816b001fa854f Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 01:59:01 +0900 Subject: [PATCH 16/21] fix: update HuggingFaceConnectorTests Related to: #451 --- .../Connectors/HuggingFaceConnectorTests.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index aa27e0a5..65b7b40b 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -223,17 +223,19 @@ public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should client.ShouldBeAssignableTo(); } - [Trait("Category", "IntegrationTest")] - [Trait("Category", "LLMRequired")] + [Trait("Category", "UnitTest")] [Theory] - [InlineData(null, null, "Missing configuration: HUggingFace")] - [InlineData(null, Model, "Missing configuration: HUggingFace")] - [InlineData("", Model, "Missing configuration: HUggingFace")] - [InlineData(" ", Model, "Missing configuration: HUggingFace")] - [InlineData(BaseUrl, null, "Missing configuration: HUggingFace")] - [InlineData(BaseUrl, "", "Missing configuration: HUggingFace")] - [InlineData(BaseUrl, " ", "Missing configuration: HUggingFace")] - public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? baseUrl, string? model, string expectedMessage) + [InlineData(null, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData(null, Model, typeof(NullReferenceException),"Object reference not set to an instance of an object")] + [InlineData("", Model, typeof(InvalidOperationException), "Missing configuration: HUggingFace")] + [InlineData(" ", Model, typeof(InvalidOperationException), "Missing configuration: HUggingFace")] + [InlineData(BaseUrl, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData(BaseUrl, "", typeof(InvalidOperationException), "Missing configuration: HUggingFace")] + [InlineData(BaseUrl, " ", typeof(InvalidOperationException), "Missing configuration: HUggingFace")] + [InlineData(BaseUrl, "hf.co/org/model", typeof(InvalidOperationException), "Invalid configuration: HuggingFace:Model format")] + [InlineData(BaseUrl, "org/model-gguf", typeof(InvalidOperationException), "Invalid configuration: HuggingFace:Model format")] + [InlineData(BaseUrl, "hf.co//model-gguf", typeof(InvalidOperationException), "Invalid configuration: HuggingFace:Model format")] + public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? baseUrl, string? model, Type expected, string expectedMessage) { // Arrange var settings = new AppSettings @@ -250,7 +252,7 @@ public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Sh Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - func.ShouldThrow() + func.ShouldThrow(expected) .Message.ShouldContain(expectedMessage); } From a7b607fd358969be1a4d09cb76d172994eeedff4 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 02:20:14 +0900 Subject: [PATCH 17/21] fix: update LGConnectorTest Related to: #451 --- .../Connectors/HuggingFaceConnectorTests.cs | 2 +- .../Connectors/LGConnectorTests.cs | 54 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index 65b7b40b..47f3415b 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -165,9 +165,9 @@ public void Given_Valid_Settings_When_EnsureLanguageModelSettingsValid_Invoked_T [Theory] [InlineData(null, typeof(ArgumentNullException), "null")] [InlineData("", typeof(UriFormatException), "empty")] + [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] [InlineData("invalid-uri-format", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] [InlineData("not-a-url", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] - [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expected, string message) { // Arrange diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs index fd634882..9f624e87 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs @@ -8,7 +8,9 @@ namespace OpenChat.PlaygroundApp.Tests.Connectors; public class LGConnectorTests { - private const string BaseUrl = "https://test.lg-exaone/api"; + // private const string BaseUrl = "https://test.lg-exaone/api"; + // private const string Model = "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF"; + private const string BaseUrl = "http://localhost:11434"; private const string Model = "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF"; private static AppSettings BuildAppSettings(string? baseUrl = BaseUrl, string? model = Model) @@ -150,9 +152,9 @@ public void Given_Valid_Model_Format_When_EnsureLanguageModelSettingsValid_Invok [Theory] [InlineData(null, typeof(ArgumentNullException), "null")] [InlineData("", typeof(UriFormatException), "empty")] + [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] [InlineData("invalid-uri-format", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] [InlineData("not-a-url", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] - [InlineData(" ", typeof(UriFormatException), "Invalid URI: The format of the URI could not be determined.")] public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Throw(string? baseUrl, Type expectedType, string message) { // Arrange @@ -170,15 +172,15 @@ public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Thro [Trait("Category", "IntegrationTest")] [Trait("Category", "LLMRequired")] [Theory] - [InlineData(null, typeof(ArgumentNullException), "null")] - [InlineData("", typeof(UriFormatException), "empty")] - [InlineData(" ", typeof(InvalidOperationException), "LG:Model")] - [InlineData("invalid-model-format", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] - [InlineData("random-name", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] - [InlineData("hf.co/other-org/model-GGUF", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] - [InlineData("hf.co/LGAI-EXAONE/other-model-GGUF", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] - [InlineData("hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] - [InlineData("hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-FP8", typeof(InvalidOperationException), "Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + [InlineData(null, typeof(OllamaSharp.Models.Exceptions.OllamaException), "invalid model name")] + [InlineData("", typeof(OllamaSharp.Models.Exceptions.OllamaException), "invalid model name")] + [InlineData(" ", typeof(OllamaSharp.Models.Exceptions.OllamaException), "invalid model name")] + [InlineData("invalid-model-format", typeof(OllamaSharp.Models.Exceptions.ResponseError), "pull model manifest")] + [InlineData("random-name", typeof(OllamaSharp.Models.Exceptions.ResponseError), "pull model manifest")] + [InlineData("hf.co/other-org/model-GGUF", typeof(OllamaSharp.Models.Exceptions.ResponseError), "pull model manifest")] + [InlineData("hf.co/LGAI-EXAONE/other-model-GGUF", typeof(OllamaSharp.Models.Exceptions.ResponseError), "pull model manifest")] + [InlineData("hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B", typeof(OllamaSharp.Models.Exceptions.ResponseError), "pull model manifest")] + [InlineData("hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-FP8", typeof(OllamaSharp.Models.Exceptions.ResponseError), "pull model manifest")] public void Given_Invalid_Model_When_GetChatClient_Invoked_Then_It_Should_Throw(string? model, Type expectedType, string message) { // Arrange @@ -213,19 +215,20 @@ public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should [Trait("Category", "IntegrationTest")] [Trait("Category", "LLMRequired")] [Theory] - [InlineData(null, "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF", typeof(NullReferenceException))] - [InlineData("", "hf.co/LGAI-EXAONE/EXAONE-4.0-32B-GGUF", typeof(InvalidOperationException))] - [InlineData(" ", "hf.co/LGAI-EXAONE/EXAONE-4.0-32B-GGUF", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", null, typeof(NullReferenceException))] - [InlineData("https://test.lg-exaone/api", "", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", " ", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", "invalid-model-format", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", "random-name", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", "hf.co/other-org/model-GGUF", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", "hf.co/LGAI-EXAONE/other-model-GGUF", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B", typeof(InvalidOperationException))] - [InlineData("https://test.lg-exaone/api", "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-FP8", typeof(InvalidOperationException))] - public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? baseUrl, string? model, Type expectedType) + [InlineData(null, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData(null, Model, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData("", Model, typeof(InvalidOperationException), "Missing configuration: LG:BaseUrl")] + [InlineData(" ", Model, typeof(InvalidOperationException), "Missing configuration: LG:BaseUrl")] + [InlineData(BaseUrl, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] + [InlineData(BaseUrl, "", typeof(InvalidOperationException), "Missing configuration: LG:Model")] + [InlineData(BaseUrl, " ", typeof(InvalidOperationException), "Missing configuration: LG:Model")] + [InlineData(BaseUrl, "invalid-model-format", typeof(InvalidOperationException), "Invalid configuration: Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + [InlineData(BaseUrl, "random-name", typeof(InvalidOperationException), "Invalid configuration: Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + [InlineData(BaseUrl, "hf.co/other-org/model-GGUF", typeof(InvalidOperationException), "Invalid configuration: Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + [InlineData(BaseUrl, "hf.co/LGAI-EXAONE/other-model-GGUF", typeof(InvalidOperationException), "Invalid configuration: Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + [InlineData(BaseUrl, "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B", typeof(InvalidOperationException), "Invalid configuration: Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + [InlineData(BaseUrl, "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-FP8", typeof(InvalidOperationException), "Invalid configuration: Expected 'hf.co/LGAI-EXAONE/EXAONE-*-GGUF' format")] + public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Should_Throw(string? baseUrl, string? model, Type expected, string message) { // Arrange var settings = BuildAppSettings(baseUrl: baseUrl, model: model); @@ -234,7 +237,8 @@ public void Given_Invalid_Settings_When_CreateChatClientAsync_Invoked_Then_It_Sh Func func = async () => await LanguageModelConnector.CreateChatClientAsync(settings); // Assert - func.ShouldThrow(expectedType); + func.ShouldThrow(expected) + .Message.ShouldContain(message); } [Trait("Category", "IntegrationTest")] From 36f1cbe20a39ffc051188973bb76cd07e196d358 Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 02:25:55 +0900 Subject: [PATCH 18/21] fix: refactor test traits Related to: #451 --- .../Connectors/GitHubModelsConnectorTests.cs | 2 +- .../Connectors/HuggingFaceConnectorTests.cs | 3 +-- .../Connectors/LGConnectorTests.cs | 7 ++----- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs index d997683d..2ed9ebb1 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs @@ -297,4 +297,4 @@ public async Task Given_Valid_Settings_When_CreateChatClientAsync_Invoked_Then_I result.ShouldNotBeNull(); result.ShouldBeAssignableTo(); } -} +} \ No newline at end of file diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index 47f3415b..a8b2fc6f 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -182,8 +182,7 @@ public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Thro .Message.ShouldContain(message); } - [Trait("Category", "IntegrationTest")] - [Trait("Category", "LLMRequired")] + [Trait("Category", "UnitTest")] [Theory] [InlineData(null, typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] [InlineData("", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs index 9f624e87..e67dede6 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/LGConnectorTests.cs @@ -8,9 +8,7 @@ namespace OpenChat.PlaygroundApp.Tests.Connectors; public class LGConnectorTests { - // private const string BaseUrl = "https://test.lg-exaone/api"; - // private const string Model = "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF"; - private const string BaseUrl = "http://localhost:11434"; + private const string BaseUrl = "https://test.lg-exaone/api"; private const string Model = "hf.co/LGAI-EXAONE/EXAONE-4.0-1.2B-GGUF"; private static AppSettings BuildAppSettings(string? baseUrl = BaseUrl, string? model = Model) @@ -212,8 +210,7 @@ public async Task Given_Valid_Settings_When_GetChatClient_Invoked_Then_It_Should client.ShouldBeAssignableTo(); } - [Trait("Category", "IntegrationTest")] - [Trait("Category", "LLMRequired")] + [Trait("Category", "UnitTest")] [Theory] [InlineData(null, null, typeof(NullReferenceException), "Object reference not set to an instance of an object")] [InlineData(null, Model, typeof(NullReferenceException), "Object reference not set to an instance of an object")] From df536504d4d4df58e0ac1d75099ade31f9f285df Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 02:31:02 +0900 Subject: [PATCH 19/21] fix: refactor test trait Related to: #451 --- .../Connectors/HuggingFaceConnectorTests.cs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index a8b2fc6f..62ad25d3 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -182,15 +182,16 @@ public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Thro .Message.ShouldContain(message); } - [Trait("Category", "UnitTest")] + [Trait("Category", "IntegrationTest")] + [Trait("Category", "LLMRequired")] [Theory] - [InlineData(null, typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] - [InlineData("", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] - [InlineData(" ", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] - [InlineData("\t\n\r", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] - [InlineData("hf.co/org/model", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] - [InlineData("org/model-gguf", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] - [InlineData("hf.co//model-gguf", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData(null, typeof(HttpRequestException), "Name or service not known")] + [InlineData("", typeof(HttpRequestException), "Name or service not known")] + [InlineData(" ", typeof(HttpRequestException), "Name or service not known")] + [InlineData("\t\n\r", typeof(HttpRequestException), "Name or service not known")] + [InlineData("hf.co/org/model", typeof(HttpRequestException), "Name or service not known")] + [InlineData("org/model-gguf", typeof(HttpRequestException), "Name or service not known")] + [InlineData("hf.co//model-gguf", typeof(HttpRequestException), "Name or service not known")] public void Given_Invalid_Model_When_GetChatClient_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) { // Arrange From 0a6661765abb7d9a50ccf9588845b594276ae2dc Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 02:32:55 +0900 Subject: [PATCH 20/21] fix: refacetor inline data Related to: #451 --- .../Connectors/HuggingFaceConnectorTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs index 62ad25d3..47f3415b 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/HuggingFaceConnectorTests.cs @@ -185,13 +185,13 @@ public void Given_Invalid_BaseUrl_When_GetChatClient_Invoked_Then_It_Should_Thro [Trait("Category", "IntegrationTest")] [Trait("Category", "LLMRequired")] [Theory] - [InlineData(null, typeof(HttpRequestException), "Name or service not known")] - [InlineData("", typeof(HttpRequestException), "Name or service not known")] - [InlineData(" ", typeof(HttpRequestException), "Name or service not known")] - [InlineData("\t\n\r", typeof(HttpRequestException), "Name or service not known")] - [InlineData("hf.co/org/model", typeof(HttpRequestException), "Name or service not known")] - [InlineData("org/model-gguf", typeof(HttpRequestException), "Name or service not known")] - [InlineData("hf.co//model-gguf", typeof(HttpRequestException), "Name or service not known")] + [InlineData(null, typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData(" ", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("\t\n\r", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("hf.co/org/model", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("org/model-gguf", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] + [InlineData("hf.co//model-gguf", typeof(HttpRequestException), "The requested name is valid, but no data of the requested type was found")] public void Given_Invalid_Model_When_GetChatClient_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) { // Arrange From 7dc0668cdebaed6de84ffc07b667dff482e5c5cc Mon Sep 17 00:00:00 2001 From: sikutisa Date: Thu, 16 Oct 2025 02:46:59 +0900 Subject: [PATCH 21/21] fix: remove async Task Related to: #451 --- .../Connectors/GitHubModelsConnectorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs index 2ed9ebb1..1e966a0d 100644 --- a/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs +++ b/test/OpenChat.PlaygroundApp.Tests/Connectors/GitHubModelsConnectorTests.cs @@ -220,7 +220,7 @@ public void Given_Missing_Endpoint_When_GetChatClient_Invoked_Then_It_Should_Thr [Theory] [InlineData(null, typeof(ArgumentNullException), "model")] [InlineData("", typeof(ArgumentException), "model")] - public async Task Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) + public void Given_Missing_Model_When_GetChatClient_Invoked_Then_It_Should_Throw(string? model, Type expected, string message) { // Arrange var settings = BuildAppSettings(model: model);