1
+ using System . Reflection ;
2
+
3
+ using AzureOpenAIProxy . ApiApp . Builders ;
4
+ using AzureOpenAIProxy . ApiApp . Configurations ;
5
+
6
+ using FluentAssertions ;
7
+
8
+ namespace AzureOpenAIProxy . ApiApp . Tests . Builders ;
9
+
10
+ public class OpenAIServiceRequestBuilderTests
11
+ {
12
+ [ Theory ]
13
+ [ InlineData ( "https://localhost" , "my-api-key" , "deployment-name-1" ) ]
14
+ public void Given_OpenAISettings_When_Invoked_SetOpenAIInstance_Then_It_Should_Store_Value ( string endpoint , string apiKey , string deploymentName )
15
+ {
16
+ // Arrange
17
+ var instance = new OpenAIInstanceSettings
18
+ {
19
+ Endpoint = endpoint ,
20
+ ApiKey = apiKey ,
21
+ DeploymentNames = new List < string > ( ) { deploymentName } ,
22
+ } ;
23
+ var settings = new OpenAISettings ( )
24
+ {
25
+ Instances = { instance }
26
+ } ;
27
+
28
+ // Act
29
+ var builder = new OpenAIServiceRequestBuilder ( ) ;
30
+ builder . SetOpenAIInstance ( settings , deploymentName ) ;
31
+
32
+ // Assert
33
+ var _endpoint = builder . GetType ( ) . GetField ( "_endpoint" , BindingFlags . NonPublic | BindingFlags . Instance ) ? . GetValue ( builder ) as string ;
34
+ var _apiKey = builder . GetType ( ) . GetField ( "_apiKey" , BindingFlags . NonPublic | BindingFlags . Instance ) ? . GetValue ( builder ) as string ;
35
+
36
+ _endpoint . Should ( ) . Be ( endpoint ) ;
37
+ _apiKey . Should ( ) . Be ( apiKey ) ;
38
+ }
39
+
40
+ [ Theory ]
41
+ [ InlineData ( "https://localhost" , "my-api-key" , "deployment-name-1" , "deployment-name-2" ) ]
42
+ public void Given_OpenAISettings_When_Invoked_SetOpenAIInstance_Then_It_Should_Return_Null ( string endpoint , string apiKey , string deploymentName , string nonDeploymentName )
43
+ {
44
+ // Arrange
45
+ var instance = new OpenAIInstanceSettings
46
+ {
47
+ Endpoint = endpoint ,
48
+ ApiKey = apiKey ,
49
+ DeploymentNames = new List < string > ( ) { deploymentName } ,
50
+ } ;
51
+ var settings = new OpenAISettings ( )
52
+ {
53
+ Instances = { instance }
54
+ } ;
55
+
56
+ // Act
57
+ var builder = new OpenAIServiceRequestBuilder ( ) ;
58
+ builder . SetOpenAIInstance ( settings , nonDeploymentName ) ;
59
+
60
+ // Assert
61
+ var _endpoint = builder . GetType ( ) . GetField ( "_endpoint" , BindingFlags . NonPublic | BindingFlags . Instance ) ? . GetValue ( builder ) as string ;
62
+ var _apiKey = builder . GetType ( ) . GetField ( "_apiKey" , BindingFlags . NonPublic | BindingFlags . Instance ) ? . GetValue ( builder ) as string ;
63
+
64
+ _endpoint . Should ( ) . BeNull ( ) ;
65
+ _apiKey . Should ( ) . BeNull ( ) ;
66
+ }
67
+ }
0 commit comments