1- /**
2- * Copyright 2017 IBM Corp. All Rights Reserved.
3- *
4- * Licensed under the Apache License, Version 2.0 (the "License");
5- * you may not use this file except in compliance with the License.
6- * You may obtain a copy of the License at
7- *
8- * http://www.apache.org/licenses/LICENSE-2.0
9- *
10- * Unless required by applicable law or agreed to in writing, software
11- * distributed under the License is distributed on an "AS IS" BASIS,
12- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13- * See the License for the specific language governing permissions and
14- * limitations under the License.
15- *
16- */
17-
18- using IBM . Watson . Assistant . v2 . Model ;
19- using IBM . Cloud . SDK . Core . Util ;
20- using Microsoft . VisualStudio . TestTools . UnitTesting ;
21- using Newtonsoft . Json ;
22- using Newtonsoft . Json . Linq ;
23- using System ;
24- using System . IO ;
1+ /**
2+ * Copyright 2017 IBM Corp. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ *
16+ */
17+
18+ using IBM . Watson . Assistant . v2 . Model ;
19+ using IBM . Cloud . SDK . Core . Util ;
20+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
21+ using Newtonsoft . Json ;
22+ using Newtonsoft . Json . Linq ;
23+ using System ;
24+ using System . IO ;
2525using IBM . Cloud . SDK . Core . Authentication . Iam ;
2626
27- namespace IBM . Watson . Assistant . v2 . IntegrationTests
28- {
29- [ TestClass ]
30- public class AssistantServiceIntegrationConfigTests
31- {
32- private static string apikey ;
33- private static string endpoint ;
34- private AssistantService service ;
35- private static string credentials = string . Empty ;
36-
37- private static string assistantId ;
38- private static string sessionId ;
39- private readonly string inputString = "Hello" ;
40- private readonly string versionDate = "2018-09-17" ;
41-
42- [ TestInitialize ]
43- public void Setup ( )
44- {
45- Utility . LoadExternalCredentials ( ) ;
46- var apikey = Environment . GetEnvironmentVariable ( "ASSISTANT_APIKEY" ) ;
47- var url = Environment . GetEnvironmentVariable ( "ASSISTANT_URL" ) ;
48- IamConfig iamConfig = new IamConfig (
49- apikey : apikey
50- ) ;
51- service = new AssistantService ( versionDate , iamConfig ) ;
52- service . SetEndpoint ( url ) ;
53- assistantId = Environment . GetEnvironmentVariable ( "ASSISTANT_ASSISTANT_ID" ) ;
54- }
55-
56- #region Sessions
57- [ TestMethod ]
58- public void CreateDeleteSession_Success ( )
59- {
27+ namespace IBM . Watson . Assistant . v2 . IntegrationTests
28+ {
29+ [ TestClass ]
30+ public class AssistantServiceIntegrationConfigTests
31+ {
32+ private static string apikey ;
33+ private static string endpoint ;
34+ private AssistantService service ;
35+ private static string credentials = string . Empty ;
36+
37+ private static string assistantId ;
38+ private static string sessionId ;
39+ private readonly string inputString0 = "Hello" ;
40+ private readonly string inputString1 = "Are you open on christmas?" ;
41+ private readonly string inputString2 = "I'd like to make an appointment." ;
42+ private readonly string inputString3 = "Tomorrow at 3pm" ;
43+ private readonly string inputString4 = "Make that thursday at 2pm" ;
44+ private readonly string inputString5 = "Who did watson beat in jeopardy?" ;
45+ private readonly string versionDate = "2019-02-28" ;
46+
47+ [ TestInitialize ]
48+ public void Setup ( )
49+ {
50+ Utility . LoadExternalCredentials ( ) ;
51+ var apikey = Environment . GetEnvironmentVariable ( "ASSISTANT_APIKEY" ) ;
52+ var url = Environment . GetEnvironmentVariable ( "ASSISTANT_URL" ) ;
53+ IamConfig iamConfig = new IamConfig (
54+ apikey : apikey
55+ ) ;
56+ service = new AssistantService ( versionDate , iamConfig ) ;
57+ service . SetEndpoint ( url ) ;
58+ assistantId = Environment . GetEnvironmentVariable ( "ASSISTANT_ASSISTANT_ID" ) ;
59+ }
60+
61+ #region Sessions
62+ [ TestMethod ]
63+ public void CreateDeleteSession_Success ( )
64+ {
6065 service . WithHeader ( "X-Watson-Test" , "1" ) ;
61- var createSessionResult = service . CreateSession (
62- assistantId : assistantId
63- ) ;
64- sessionId = createSessionResult . Result . SessionId ;
65-
66+ var createSessionResult = service . CreateSession (
67+ assistantId : assistantId
68+ ) ;
69+ sessionId = createSessionResult . Result . SessionId ;
70+
6671 service . WithHeader ( "X-Watson-Test" , "1" ) ;
67- var deleteSessionResult = service . DeleteSession (
72+ var deleteSessionResult = service . DeleteSession (
6873 assistantId : assistantId ,
69- sessionId : sessionId
70- ) ;
71-
72- sessionId = string . Empty ;
73-
74- Assert . IsNotNull ( createSessionResult ) ;
75- Assert . IsNotNull ( deleteSessionResult ) ;
76- Assert . IsTrue ( ! string . IsNullOrEmpty ( createSessionResult . Result . SessionId ) ) ;
77- }
78- #endregion
79-
80- #region Message
81- [ TestMethod ]
82- public void Message_Success ( )
83- {
74+ sessionId : sessionId
75+ ) ;
76+
77+ sessionId = string . Empty ;
78+
79+ Assert . IsNotNull ( createSessionResult ) ;
80+ Assert . IsNotNull ( deleteSessionResult ) ;
81+ Assert . IsTrue ( ! string . IsNullOrEmpty ( createSessionResult . Result . SessionId ) ) ;
82+ }
83+ #endregion
84+
85+ #region Message
86+ [ TestMethod ]
87+ public void Message_Success ( )
88+ {
8489 service . WithHeader ( "X-Watson-Test" , "1" ) ;
85- var createSessionResult = service . CreateSession (
86- assistantId : assistantId
87- ) ;
88- sessionId = createSessionResult . Result . SessionId ;
89-
90+ var createSessionResult = service . CreateSession (
91+ assistantId : assistantId
92+ ) ;
93+ sessionId = createSessionResult . Result . SessionId ;
94+
9095 MessageInput input = new MessageInput ( )
9196 {
9297 MessageType = MessageInput . MessageTypeEnumValue . TEXT ,
93- Text = inputString ,
98+ Text = inputString0 ,
9499 Options = new MessageInputOptions ( )
95100 {
96101 ReturnContext = true ,
97102 AlternateIntents = true
98103 }
99- } ;
100-
104+ } ;
105+
101106 service . WithHeader ( "X-Watson-Test" , "1" ) ;
102- var messageResult = service . Message (
107+ var messageResult = service . Message (
103108 assistantId : assistantId ,
104109 sessionId : sessionId ,
105- input : input
106- ) ;
107-
110+ input : input
111+ ) ;
112+
108113 service . WithHeader ( "X-Watson-Test" , "1" ) ;
109- var deleteSessionResult = service . DeleteSession (
114+ var deleteSessionResult = service . DeleteSession (
110115 assistantId : assistantId ,
111- sessionId : sessionId
112- ) ;
113- sessionId = string . Empty ;
114-
115- Assert . IsNotNull ( createSessionResult ) ;
116- Assert . IsNotNull ( messageResult ) ;
117- Assert . IsNotNull ( deleteSessionResult ) ;
118- Assert . IsTrue ( ! string . IsNullOrEmpty ( createSessionResult . Result . SessionId ) ) ;
116+ sessionId : sessionId
117+ ) ;
118+ sessionId = string . Empty ;
119+
120+ Assert . IsNotNull ( createSessionResult ) ;
121+ Assert . IsNotNull ( messageResult ) ;
122+ Assert . IsNotNull ( deleteSessionResult ) ;
123+ Assert . IsTrue ( ! string . IsNullOrEmpty ( createSessionResult . Result . SessionId ) ) ;
124+ }
125+ #endregion
126+
127+ #region MultiMessage
128+ [ TestMethod ]
129+ public void MultiMessage_Success ( )
130+ {
131+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
132+ var createSessionResult = service . CreateSession (
133+ assistantId : assistantId
134+ ) ;
135+ sessionId = createSessionResult . Result . SessionId ;
136+
137+ MessageInput input = new MessageInput ( )
138+ {
139+ MessageType = MessageInput . MessageTypeEnumValue . TEXT ,
140+ Text = inputString0 ,
141+ Options = new MessageInputOptions ( )
142+ {
143+ ReturnContext = true ,
144+ AlternateIntents = true
145+ }
146+ } ;
147+
148+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
149+ var messageResult0 = service . Message (
150+ assistantId : assistantId ,
151+ sessionId : sessionId ,
152+ input : input
153+ ) ;
154+
155+
156+
157+ input . Text = inputString1 ;
158+
159+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
160+ var messageResult1 = service . Message (
161+ assistantId : assistantId ,
162+ sessionId : sessionId ,
163+ input : input
164+ ) ;
165+
166+ input . Text = inputString2 ;
167+
168+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
169+ var messageResult2 = service . Message (
170+ assistantId : assistantId ,
171+ sessionId : sessionId ,
172+ input : input
173+ ) ;
174+
175+ input . Text = inputString3 ;
176+
177+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
178+ var messageResult3 = service . Message (
179+ assistantId : assistantId ,
180+ sessionId : sessionId ,
181+ input : input
182+ ) ;
183+
184+ input . Text = inputString4 ;
185+
186+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
187+ var messageResult4 = service . Message (
188+ assistantId : assistantId ,
189+ sessionId : sessionId ,
190+ input : input
191+ ) ;
192+
193+ input . Text = inputString5 ;
194+
195+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
196+ var messageResult5 = service . Message (
197+ assistantId : assistantId ,
198+ sessionId : sessionId ,
199+ input : input
200+ ) ;
201+
202+ service . WithHeader ( "X-Watson-Test" , "1" ) ;
203+ var deleteSessionResult = service . DeleteSession (
204+ assistantId : assistantId ,
205+ sessionId : sessionId
206+ ) ;
207+ sessionId = string . Empty ;
208+
209+ Assert . IsNotNull ( createSessionResult . Result . SessionId ) ;
210+ Assert . IsNotNull ( messageResult0 . Result . Output ) ;
211+ Assert . IsNotNull ( messageResult1 . Result . Output ) ;
212+ Assert . IsNotNull ( messageResult2 . Result . Output ) ;
213+ Assert . IsNotNull ( messageResult3 . Result . Output ) ;
214+ Assert . IsNotNull ( messageResult4 . Result . Output ) ;
215+ Assert . IsNotNull ( messageResult5 . Result . Output ) ;
216+ Assert . IsTrue ( messageResult5 . Result . Output . Generic [ 0 ] . ResponseType == "search" ) ;
217+ Assert . IsTrue ( deleteSessionResult . StatusCode == 200 ) ;
218+ Assert . IsTrue ( ! string . IsNullOrEmpty ( createSessionResult . Result . SessionId ) ) ;
119219 }
120- #endregion
121- }
122- }
220+ #endregion
221+ }
222+ }
0 commit comments