Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand All @@ -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)]
Expand Down Expand Up @@ -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))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Task> func = async () => await LanguageModelConnector.CreateChatClientAsync(settings);

// Assert
await func.ShouldThrowAsync<NullReferenceException>();
}

[Trait("Category", "UnitTest")]
[Fact]
public async Task Given_Null_Settings_When_CreateChatClient_Invoked_Then_It_Should_Throw()
{
// Arrange
AppSettings settings = null!;

// Act
Func<Task> func = async () => await LanguageModelConnector.CreateChatClientAsync(settings);

// Assert
await func.ShouldThrowAsync<NullReferenceException>();
}

[Trait("Category", "UnitTest")]
[Theory]
[InlineData(ConnectorType.Unknown)]
Expand Down Expand Up @@ -79,4 +107,4 @@ public void Given_Concrete_Connectors_When_Checking_Inheritance_Then_Should_Inhe
// Assert
result.ShouldBeTrue();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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
{
Expand All @@ -28,64 +32,71 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked
var connector = new GitHubModelsConnector(settings);

// Act
var ex = Assert.Throws<InvalidOperationException>(() => connector.EnsureLanguageModelSettingsValid());
Action action = () => connector.EnsureLanguageModelSettingsValid();

// Assert
ex.Message.ShouldContain("GitHubModels");
action.ShouldThrow<InvalidOperationException>()
.Message.ShouldContain("GitHubModels");
}

[Trait("Category", "UnitTest")]
[Theory]
[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
var settings = BuildAppSettings(endpoint: endpoint);
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")]
[Theory]
[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
var settings = BuildAppSettings(token: token);
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")]
[Theory]
[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
var settings = BuildAppSettings(model: model);
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")]
Expand Down Expand Up @@ -129,9 +140,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<Task> func = connector.GetChatClientAsync;

// Assert
var ex = await func.ShouldThrowAsync(expected);
ex.Message.ShouldContain(message);
}

Expand All @@ -146,9 +158,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<Task> func = connector.GetChatClientAsync;

// Assert
var ex = await func.ShouldThrowAsync(expected);
ex.Message.ShouldContain(message);
}

Expand All @@ -163,9 +176,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<Task> func = connector.GetChatClientAsync;

// Assert
var ex = await func.ShouldThrowAsync(expected);
ex.Message.ShouldContain(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using OpenChat.PlaygroundApp.Abstractions;
using OpenChat.PlaygroundApp.Configurations;
using OpenChat.PlaygroundApp.Connectors;

Expand All @@ -22,19 +21,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()
Expand All @@ -44,35 +30,39 @@ public void Given_Settings_Is_Null_When_EnsureLanguageModelSettingsValid_Invoked
var connector = new HuggingFaceConnector(settings);

// Act
var ex = Assert.Throws<InvalidOperationException>(() => connector.EnsureLanguageModelSettingsValid());
Action action = () => connector.EnsureLanguageModelSettingsValid();

// Assert
ex.Message.ShouldContain("HuggingFace");
action.ShouldThrow<InvalidOperationException>()
.Message.ShouldContain("HuggingFace");
}

[Trait("Category", "UnitTest")]
[Theory]
[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
var settings = BuildAppSettings(baseUrl: baseUrl);
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")]
[Theory]
[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")]
Expand All @@ -83,10 +73,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")]
Expand Down Expand Up @@ -131,9 +122,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<Task> func = connector.GetChatClientAsync;

// Assert
var ex = await func.ShouldThrowAsync(expected);
ex.Message.ShouldContain(message);
}
}
}
Loading