Skip to content

Commit 87626da

Browse files
committed
tests(Assistant v2): Added integration tests for Assistant v2
1 parent 8b7c474 commit 87626da

File tree

7 files changed

+240
-1
lines changed

7 files changed

+240
-1
lines changed

IBM.WatsonDeveloperCloud.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AssistantV2", "AssistantV2"
125125
EndProject
126126
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IBM.WatsonDeveloperCloud.Assistant.v2", "src\IBM.WatsonDeveloperCloud.Assistant.v2\IBM.WatsonDeveloperCloud.Assistant.v2.csproj", "{817CCCEB-FBAF-4BEB-A99B-3EE4F09F9200}"
127127
EndProject
128+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.WatsonDeveloperCloud.Assistant.v2.UnitTests", "test\IBM.WatsonDeveloperCloud.Assistant.v2.UnitTests\IBM.WatsonDeveloperCloud.Assistant.v2.UnitTests.csproj", "{5FBF32E9-0352-4D8B-BED2-D6EE04363A47}"
129+
EndProject
130+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IBM.WatsonDeveloperCloud.Assistant.v2.IntTests", "test\IBM.WatsonDeveloperCloud.Assistant.v2.IntTests\IBM.WatsonDeveloperCloud.Assistant.v2.IntTests.csproj", "{200FC8C7-ED91-4F66-8674-D678588FC450}"
131+
EndProject
128132
Global
129133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
130134
Debug|Any CPU = Debug|Any CPU
@@ -307,6 +311,14 @@ Global
307311
{817CCCEB-FBAF-4BEB-A99B-3EE4F09F9200}.Debug|Any CPU.Build.0 = Debug|Any CPU
308312
{817CCCEB-FBAF-4BEB-A99B-3EE4F09F9200}.Release|Any CPU.ActiveCfg = Release|Any CPU
309313
{817CCCEB-FBAF-4BEB-A99B-3EE4F09F9200}.Release|Any CPU.Build.0 = Release|Any CPU
314+
{5FBF32E9-0352-4D8B-BED2-D6EE04363A47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
315+
{5FBF32E9-0352-4D8B-BED2-D6EE04363A47}.Debug|Any CPU.Build.0 = Debug|Any CPU
316+
{5FBF32E9-0352-4D8B-BED2-D6EE04363A47}.Release|Any CPU.ActiveCfg = Release|Any CPU
317+
{5FBF32E9-0352-4D8B-BED2-D6EE04363A47}.Release|Any CPU.Build.0 = Release|Any CPU
318+
{200FC8C7-ED91-4F66-8674-D678588FC450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
319+
{200FC8C7-ED91-4F66-8674-D678588FC450}.Debug|Any CPU.Build.0 = Debug|Any CPU
320+
{200FC8C7-ED91-4F66-8674-D678588FC450}.Release|Any CPU.ActiveCfg = Release|Any CPU
321+
{200FC8C7-ED91-4F66-8674-D678588FC450}.Release|Any CPU.Build.0 = Release|Any CPU
310322
EndGlobalSection
311323
GlobalSection(SolutionProperties) = preSolution
312324
HideSolutionNode = FALSE
@@ -371,6 +383,8 @@ Global
371383
{019DEDBF-2929-4AB3-AA58-A6C9D42604FC} = {A1BC3262-1837-40D9-A530-DCFE679927C2}
372384
{90E09BF8-A647-43B8-B721-05CAECFADD72} = {28E61676-E9FF-4DA9-99CC-5E0D16F02380}
373385
{817CCCEB-FBAF-4BEB-A99B-3EE4F09F9200} = {90E09BF8-A647-43B8-B721-05CAECFADD72}
386+
{5FBF32E9-0352-4D8B-BED2-D6EE04363A47} = {90E09BF8-A647-43B8-B721-05CAECFADD72}
387+
{200FC8C7-ED91-4F66-8674-D678588FC450} = {90E09BF8-A647-43B8-B721-05CAECFADD72}
374388
EndGlobalSection
375389
GlobalSection(ExtensibilityGlobals) = postSolution
376390
SolutionGuid = {B9D9D17B-1C17-402F-B701-DC671528690A}

src/IBM.WatsonDeveloperCloud/Util/Credentials.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public class Credential
8989
public string EnvironmentId { get; set; }
9090
[JsonProperty("classifier_id", NullValueHandling = NullValueHandling.Ignore)]
9191
public string ClassifierId { get; set; }
92+
[JsonProperty("assistant_id", NullValueHandling = NullValueHandling.Ignore)]
93+
public string AssistantId { get; set; }
9294
}
9395

9496
/// <summary>

test/IBM.WatsonDeveloperCloud.Assistant.v1.UnitTests/IBM.WatsonDeveloperCloud.Assistant.v1.UnitTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
<VersionPrefix>2.7.0</VersionPrefix>
55
<TargetFramework>netcoreapp1.0</TargetFramework>
66
<AssemblyName>IBM.WatsonDeveloperCloud.Conversation.v1.UnitTests</AssemblyName>
7-
<PackageId>IBM.WatsonDeveloperCloud.Conversation.v1.UnitTests</PackageId>
7+
<PackageId>IBM.WatsonDeveloperCloud.Assistant.v1.UnitTests</PackageId>
88
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
99
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
1010
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
1111
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1212
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1313
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1414
<Version>2.7.0</Version>
15+
<Authors>IBM.WatsonDeveloperCloud.Assistant.v1.UnitTests</Authors>
1516
</PropertyGroup>
1617

1718
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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.WatsonDeveloperCloud.Assistant.v2.Model;
19+
using IBM.WatsonDeveloperCloud.Util;
20+
using Microsoft.VisualStudio.TestTools.UnitTesting;
21+
using Newtonsoft.Json;
22+
using Newtonsoft.Json.Linq;
23+
using System;
24+
using System.IO;
25+
26+
namespace IBM.WatsonDeveloperCloud.Assistant.v2.IntTests
27+
{
28+
[TestClass]
29+
public class AssistantServiceIntegrationTests
30+
{
31+
private static string username;
32+
private static string password;
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+
#region Get Credentials
46+
if (string.IsNullOrEmpty(credentials))
47+
{
48+
var parentDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.Parent.Parent.Parent.FullName;
49+
string credentialsFilepath = parentDirectory + Path.DirectorySeparatorChar + "sdk-credentials" + Path.DirectorySeparatorChar + "credentials.json";
50+
if (File.Exists(credentialsFilepath))
51+
{
52+
try
53+
{
54+
credentials = File.ReadAllText(credentialsFilepath);
55+
credentials = Utility.AddTopLevelObjectToJson(credentials, "VCAP_SERVICES");
56+
}
57+
catch (Exception e)
58+
{
59+
throw new Exception(string.Format("Failed to load credentials: {0}", e.Message));
60+
}
61+
}
62+
else
63+
{
64+
Console.WriteLine("Credentials file does not exist.");
65+
}
66+
67+
VcapCredentials vcapCredentials = JsonConvert.DeserializeObject<VcapCredentials>(credentials);
68+
var vcapServices = JObject.Parse(credentials);
69+
70+
Credential credential = vcapCredentials.GetCredentialByname("assistantV2-sdk-staging")[0].Credentials;
71+
endpoint = credential.Url;
72+
username = credential.Username;
73+
password = credential.Password;
74+
assistantId = credential.AssistantId;
75+
}
76+
#endregion
77+
78+
service = new AssistantService(username, password, versionDate);
79+
service.SetEndpoint(endpoint);
80+
}
81+
82+
#region Sessions
83+
[TestMethod]
84+
public void CreateDeleteSession_Success()
85+
{
86+
var createSessionResult = service.CreateSession(assistantId);
87+
sessionId = createSessionResult.SessionId;
88+
89+
var deleteSessionResult = service.DeleteSession(assistantId, sessionId);
90+
sessionId = string.Empty;
91+
92+
Assert.IsNotNull(createSessionResult);
93+
Assert.IsNotNull(deleteSessionResult);
94+
Assert.IsTrue(!string.IsNullOrEmpty(createSessionResult.SessionId));
95+
}
96+
#endregion
97+
98+
#region Message
99+
[TestMethod]
100+
public void Message_Success()
101+
{
102+
var createSessionResult = service.CreateSession(assistantId);
103+
sessionId = createSessionResult.SessionId;
104+
105+
MessageRequest request = new MessageRequest()
106+
{
107+
Input = new MessageInput()
108+
{
109+
MessageType = MessageInput.MessageTypeEnum.TEXT,
110+
Text = inputString,
111+
Options = new MessageInputOptions()
112+
{
113+
ReturnContext = true,
114+
AlternateIntents = true
115+
}
116+
}
117+
};
118+
var messageResult = service.Message(assistantId, sessionId, request);
119+
120+
var deleteSessionResult = service.DeleteSession(assistantId, sessionId);
121+
sessionId = string.Empty;
122+
123+
Assert.IsNotNull(createSessionResult);
124+
Assert.IsNotNull(messageResult);
125+
Assert.IsNotNull(deleteSessionResult);
126+
Assert.IsTrue(!string.IsNullOrEmpty(createSessionResult.SessionId));
127+
}
128+
#endregion
129+
}
130+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<VersionPrefix>2.7.0</VersionPrefix>
5+
<TargetFramework>netcoreapp1.0</TargetFramework>
6+
<AssemblyName>IBM.WatsonDeveloperCloud.Assistant.v2.IntTests</AssemblyName>
7+
<PackageId>IBM.WatsonDeveloperCloud.Assistant.v2.IntTests</PackageId>
8+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
9+
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.4;portable-net451+win8</PackageTargetFallback>
10+
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
11+
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
12+
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
13+
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
14+
<Version>2.7.0</Version>
15+
</PropertyGroup>
16+
17+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
18+
<DebugType>full</DebugType>
19+
<DebugSymbols>true</DebugSymbols>
20+
</PropertyGroup>
21+
22+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
23+
<DebugType>full</DebugType>
24+
<DebugSymbols>true</DebugSymbols>
25+
</PropertyGroup>
26+
27+
<ItemGroup>
28+
<None Update="appsettings.json">
29+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<ProjectReference Include="..\..\src\IBM.WatsonDeveloperCloud.Assistant.v2\IBM.WatsonDeveloperCloud.Assistant.v2.csproj" />
35+
</ItemGroup>
36+
37+
<ItemGroup>
38+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
39+
<PackageReference Include="MSTest.TestAdapter" Version="1.1.8-rc" />
40+
<PackageReference Include="MSTest.TestFramework" Version="1.0.8-rc" />
41+
<PackageReference Include="NSubstitute" Version="3.1.0" />
42+
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
43+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.0.2" />
44+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
45+
<PackageReference Include="OpenCover" Version="4.6.519" />
46+
<PackageReference Include="coveralls.net" Version="0.7.0" />
47+
<PackageReference Include="ReportGenerator" Version="2.4.5" />
48+
</ItemGroup>
49+
50+
<ItemGroup>
51+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
52+
</ItemGroup>
53+
54+
</Project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 System;
19+
20+
namespace IBM.WatsonDeveloperCloud.Assistant.v2.UnitTests
21+
{
22+
class AssistantV2UnitTests
23+
{
24+
static void Main(string[] args)
25+
{
26+
Console.WriteLine("Hello World!");
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp1.0</TargetFramework>
6+
<Version>2.7.0</Version>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)