1
+ using skUnit . Scenarios ;
2
+ using skUnit ;
3
+ using Xunit . Abstractions ;
4
+ using Microsoft . VisualStudio . TestPlatform . Utilities ;
5
+
6
+ namespace Demo . TddRepl . Test
7
+ {
8
+ public class BrainTests
9
+ {
10
+ protected SemanticKernelAssert SemanticAssert { get ; set ; }
11
+ public BrainTests ( ITestOutputHelper output )
12
+ {
13
+ var endPoint = Environment . GetEnvironmentVariable ( "openai-endpoint" ) ?? throw new InvalidOperationException ( "No key provided." ) ;
14
+ var apiKey = Environment . GetEnvironmentVariable ( "openai-api-key" ) ?? throw new InvalidOperationException ( "No key provided." ) ;
15
+ var deploymentName = Environment . GetEnvironmentVariable ( "openai-deployment-name" ) ?? throw new InvalidOperationException ( "No key provided." ) ;
16
+
17
+ SemanticAssert = new SemanticKernelAssert ( deploymentName , endPoint , apiKey , output . WriteLine ) ;
18
+ }
19
+
20
+ [ Fact ]
21
+ public async Task Greeting ( )
22
+ {
23
+ var brain = new Brain ( ) ;
24
+
25
+ var scenarios = await ChatScenario . LoadFromResourceAsync ( @"Demo.TddRepl.Test.Scenarios.01-Greeting.md" , GetType ( ) . Assembly ) ;
26
+ await SemanticAssert . CheckChatScenarioAsync ( scenarios , async history =>
27
+ {
28
+ var result = await brain . GetChatAnswerAsync ( history ) ;
29
+
30
+ return result ? . ToString ( ) ?? string . Empty ;
31
+ } ) ;
32
+ }
33
+
34
+ [ Fact ]
35
+ public async Task WhoIsMehran_Normal ( )
36
+ {
37
+ var brain = new Brain ( ) ;
38
+
39
+ var scenarios = await ChatScenario . LoadFromResourceAsync ( @"Demo.TddRepl.Test.Scenarios.02-WhoIsMehran-Normal.md" , GetType ( ) . Assembly ) ;
40
+ await SemanticAssert . CheckChatScenarioAsync ( scenarios , async history =>
41
+ {
42
+ var result = await brain . GetChatAnswerAsync ( history ) ;
43
+
44
+ return result ? . ToString ( ) ?? string . Empty ;
45
+ } ) ;
46
+ }
47
+
48
+ [ Fact ]
49
+ public async Task WhoIsMehran_Angry ( )
50
+ {
51
+ var brain = new Brain ( ) ;
52
+
53
+ var scenarios = await ChatScenario . LoadFromResourceAsync ( @"Demo.TddRepl.Test.Scenarios.03-WhoIsMehran-Angry.md" , GetType ( ) . Assembly ) ;
54
+ await SemanticAssert . CheckChatScenarioAsync ( scenarios , async history =>
55
+ {
56
+ var result = await brain . GetChatAnswerAsync ( history ) ;
57
+
58
+ return result ? . ToString ( ) ?? string . Empty ;
59
+ } ) ;
60
+ }
61
+
62
+ [ Fact ]
63
+ public async Task WhoIsMehran_AngryNormal ( )
64
+ {
65
+ var brain = new Brain ( ) ;
66
+
67
+ var scenarios = await ChatScenario . LoadFromResourceAsync ( @"Demo.TddRepl.Test.Scenarios.04-WhoIsMehran-AngryNormal.md" , GetType ( ) . Assembly ) ;
68
+ await SemanticAssert . CheckChatScenarioAsync ( scenarios , async history =>
69
+ {
70
+ var result = await brain . GetChatAnswerAsync ( history ) ;
71
+
72
+ return result ? . ToString ( ) ?? string . Empty ;
73
+ } ) ;
74
+ }
75
+ }
76
+ }
0 commit comments