Skip to content

Commit 45e0af1

Browse files
committed
Adding merged files for Test/AI/OpenAI-TEW
1 parent fc68934 commit 45e0af1

3 files changed

Lines changed: 172 additions & 0 deletions

File tree

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using Microsoft.SemanticKernel.AI.OpenAI.Services;
4+
using Microsoft.SemanticKernel.Diagnostics;
5+
using Xunit;
6+
7+
namespace SemanticKernelTests.AI.OpenAI.Services;
8+
9+
public class AzureOpenAIConfigTests
10+
{
11+
[Fact]
12+
public void ConstructorWithValidParametersSetsProperties()
13+
{
14+
// Arrange
15+
string label = "testLabel";
16+
string deploymentName = "testDeploymentName";
17+
string endpoint = "https://testEndpoint.com";
18+
string apiKey = "testApiKey";
19+
string apiVersion = "testApiVersion";
20+
21+
// Act
22+
var config = new AzureOpenAIConfig(label, deploymentName, endpoint, apiKey, apiVersion);
23+
24+
// Assert
25+
Assert.Equal(label, config.Label);
26+
Assert.Equal(deploymentName, config.DeploymentName);
27+
Assert.Equal(endpoint, config.Endpoint);
28+
Assert.Equal(apiKey, config.APIKey);
29+
Assert.Equal(apiVersion, config.APIVersion);
30+
}
31+
32+
[Theory]
33+
[InlineData("", "testDeploymentName", "https://testEndpoint.com", "testApiKey", "testApiVersion")]
34+
[InlineData("testLabel", "", "https://testEndpoint.com", "testApiKey", "testApiVersion")]
35+
[InlineData("testLabel", "testDeploymentName", "", "testApiKey", "testApiVersion")]
36+
[InlineData("testLabel", "testDeploymentName", "https://testEndpoint.com", "", "testApiVersion")]
37+
public void ConstructorWithEmptyParametersThrowsValidationException(
38+
string label, string deploymentName, string endpoint, string apiKey, string apiVersion)
39+
{
40+
// Act + Assert
41+
var exception = Assert.Throws<ValidationException>(() => new AzureOpenAIConfig(label, deploymentName, endpoint, apiKey, apiVersion));
42+
Assert.Equal(ValidationException.ErrorCodes.EmptyValue, exception?.ErrorCode);
43+
}
44+
45+
[Theory]
46+
[InlineData("testLabel", "testDeploymentName", "http://testEndpoint.com", "testApiKey", "testApiVersion")]
47+
[InlineData("testLabel", "testDeploymentName", "testEndpoint.com", "testApiKey", "testApiVersion")]
48+
[InlineData("testLabel", "testDeploymentName", "testEndpoint", "testApiKey", "testApiVersion")]
49+
public void ConstructorWithMissingPrefixParametersThrowsValidationException(
50+
string label, string deploymentName, string endpoint, string apiKey, string apiVersion)
51+
{
52+
// Act + Assert
53+
var exception = Assert.Throws<ValidationException>(() => new AzureOpenAIConfig(label, deploymentName, endpoint, apiKey, apiVersion));
54+
Assert.Equal(ValidationException.ErrorCodes.MissingPrefix, exception?.ErrorCode);
55+
}
56+
57+
[Fact]
58+
public void EndpointWithValidValueDoesNotThrow()
59+
{
60+
// Arrange
61+
string label = "testLabel";
62+
string deploymentName = "testDeploymentName";
63+
string endpoint = "https://testEndpoint.com";
64+
string apiKey = "testApiKey";
65+
string apiVersion = "testApiVersion";
66+
67+
// Act
68+
var config = new AzureOpenAIConfig(label, deploymentName, endpoint, apiKey, apiVersion);
69+
70+
// Assert
71+
Assert.Equal(endpoint, config.Endpoint);
72+
}
73+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using Microsoft.SemanticKernel.AI.OpenAI.Services;
4+
using Microsoft.SemanticKernel.Diagnostics;
5+
using Xunit;
6+
7+
namespace SemanticKernelTests.AI.OpenAI.Services;
8+
9+
public class BackendConfigTests
10+
{
11+
[Fact]
12+
public void ConstructorWithValidParametersSetsProperties()
13+
{
14+
// Arrange
15+
string label = "testLabel";
16+
17+
// Act
18+
var config = new FakeBackendConfig(label);
19+
20+
// Assert
21+
Assert.Equal(label, config.Label);
22+
}
23+
24+
[Fact]
25+
public void ConstructorWithEmptyRequiredParameterThrowsArgumentException()
26+
{
27+
// Act + Assert
28+
var exception = Assert.Throws<ValidationException>(() => new FakeBackendConfig(string.Empty));
29+
30+
Assert.Equal(ValidationException.ErrorCodes.EmptyValue, exception?.ErrorCode);
31+
}
32+
33+
private class FakeBackendConfig : BackendConfig
34+
{
35+
public FakeBackendConfig(string label) : base(label)
36+
{
37+
}
38+
}
39+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using Microsoft.SemanticKernel.AI.OpenAI.Services;
4+
using Microsoft.SemanticKernel.Diagnostics;
5+
using Xunit;
6+
7+
namespace SemanticKernelTests.AI.OpenAI.Services;
8+
9+
/// <summary>
10+
/// Unit tests of <see cref="OpenAIConfig"/>
11+
/// </summary>
12+
public class OpenAIConfigTests
13+
{
14+
[Fact]
15+
public void ConstructorWithValidParametersSetsProperties()
16+
{
17+
// Arrange
18+
string label = "testLabel";
19+
string modelId = "testModelId";
20+
string apiKey = "testApiKey";
21+
string orgId = "testOrgId";
22+
23+
// Act
24+
var config = new OpenAIConfig(label, modelId, apiKey, orgId);
25+
26+
// Assert
27+
Assert.Equal(label, config.Label);
28+
Assert.Equal(modelId, config.ModelId);
29+
Assert.Equal(apiKey, config.APIKey);
30+
Assert.Equal(orgId, config.OrgId);
31+
}
32+
33+
[Theory]
34+
[InlineData("", "testModelId", "testApiKey", "testOrgId")]
35+
[InlineData("testLabel", "", "testApiKey", "testOrgId")]
36+
[InlineData("testLabel", "testModelId", "", "testOrgId")]
37+
public void ConstructorWithEmptyRequiredParameterThrowsArgumentException(
38+
string label, string modelId, string apiKey, string orgId)
39+
{
40+
// Act + Assert
41+
var exception = Assert.Throws<ValidationException>(() => new OpenAIConfig(label, modelId, apiKey, orgId));
42+
43+
Assert.Equal(ValidationException.ErrorCodes.EmptyValue, exception?.ErrorCode);
44+
}
45+
46+
[Fact]
47+
public void OrgIdWithNullValueDoesNotThrow()
48+
{
49+
// Arrange
50+
string label = "testLabel";
51+
string modelId = "testModelId";
52+
string apiKey = "testApiKey";
53+
54+
// Act
55+
var config = new OpenAIConfig(label, modelId, apiKey, null);
56+
57+
// Assert
58+
Assert.Null(config.OrgId);
59+
}
60+
}

0 commit comments

Comments
 (0)