|
| 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 | +} |
0 commit comments