Skip to content

Commit 7f0cf63

Browse files
committed
refactor: update tests and examples for major release
1 parent 735668f commit 7f0cf63

6 files changed

+25
-49
lines changed

Examples/ExamplePersonalityInsightsV3.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Collections.Generic;
2727
using System.IO;
2828
using UnityEngine;
29+
using System.Text;
2930

3031
namespace IBM.Watson.Examples
3132
{
@@ -62,18 +63,8 @@ private IEnumerator CreateService()
6263

6364
private IEnumerator Examples()
6465
{
65-
Content content = new Content()
66-
{
67-
ContentItems = new List<ContentItem>()
68-
{
69-
new ContentItem()
70-
{
71-
Content = testString,
72-
Contenttype = ContentItem.ContenttypeValue.TEXT_PLAIN,
73-
Language = ContentItem.LanguageValue.EN
74-
}
75-
}
76-
};
66+
byte[] bytes = Encoding.ASCII.GetBytes(testString);
67+
MemoryStream content = new MemoryStream(bytes);
7768

7869
Log.Debug("ExamplePersonalityInsights.Examples()", "Attempting to Profile...");
7970
service.Profile(OnProfile, content: content);

Examples/ExampleToneAnalyzerV3.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using IBM.Cloud.SDK;
2525
using IBM.Cloud.SDK.Authentication;
2626
using IBM.Cloud.SDK.Authentication.Iam;
27+
using System.Text;
28+
using System.IO;
2729

2830
namespace IBM.Watson.Examples
2931
{
@@ -79,10 +81,8 @@ private IEnumerator CreateService()
7981

8082
private IEnumerator Examples()
8183
{
82-
ToneInput toneInput = new ToneInput()
83-
{
84-
Text = stringToTestTone
85-
};
84+
byte[] bytes = Encoding.ASCII.GetBytes(stringToTestTone);
85+
MemoryStream toneInput = new MemoryStream(bytes);
8686

8787
List<string> tones = new List<string>()
8888
{

Examples/GenericSerialization.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ void Start()
3434

3535
MessageResponse messageResponse = JsonConvert.DeserializeObject<MessageResponse>(responseJson);
3636

37-
var name = messageResponse.Context.Skills["main skill"].UserDefined["name"].ToString();
37+
MessageContextSkill mainSkill;
38+
messageResponse.Context.Skills.TryGetValue("main skill", out mainSkill);
39+
var name = mainSkill.UserDefined["name"].ToString();
3840
Log.Debug("GenericSerialization", "name: {0}", name);
3941

4042
}

Tests/PersonalityInsightsV3IntegrationTests.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
using NUnit.Framework;
2626
using UnityEngine;
2727
using UnityEngine.TestTools;
28+
using System.Text;
29+
using System.IO;
2830

2931
namespace IBM.Watson.Tests
3032
{
@@ -64,18 +66,8 @@ public IEnumerator TestProfile()
6466
{
6567
Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Attempting to Profile...");
6668
Profile profileResponse = null;
67-
Content content = new Content()
68-
{
69-
ContentItems = new List<ContentItem>()
70-
{
71-
new ContentItem()
72-
{
73-
Contenttype = ContentItem.ContenttypeValue.TEXT_PLAIN,
74-
Language = ContentItem.LanguageValue.EN,
75-
Content = contentToProfile
76-
}
77-
}
78-
};
69+
byte[] bytes = Encoding.ASCII.GetBytes(contentToProfile);
70+
MemoryStream content = new MemoryStream(bytes);
7971

8072
service.Profile(
8173
callback: (DetailedResponse<Profile> response, IBMError error) =>
@@ -106,18 +98,8 @@ public IEnumerator TestProfileAsCsv()
10698
{
10799
Log.Debug("PersonalityInsightsServiceV3IntegrationTests", "Attempting to ProfileAsCsv...");
108100
System.IO.MemoryStream profileAsCsvResponse = null;
109-
Content content = new Content()
110-
{
111-
ContentItems = new List<ContentItem>()
112-
{
113-
new ContentItem()
114-
{
115-
Contenttype = ContentItem.ContenttypeValue.TEXT_PLAIN,
116-
Language = ContentItem.LanguageValue.EN,
117-
Content = contentToProfile
118-
}
119-
}
120-
};
101+
byte[] bytes = Encoding.ASCII.GetBytes(contentToProfile);
102+
MemoryStream content = new MemoryStream(bytes);
121103

122104
service.ProfileAsCsv(
123105
callback: (DetailedResponse<System.IO.MemoryStream> response, IBMError error) =>

Tests/SpeechToTextV1IntegrationTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public IEnumerator TestRecognize()
142142
{
143143
Log.Debug("SpeechToTextServiceV1IntegrationTests", "Attempting to Recognize...");
144144
SpeechRecognitionResults recognizeResponse = null;
145-
byte[] audio = File.ReadAllBytes(testAudioPath);
145+
MemoryStream audio = new MemoryStream(File.ReadAllBytes(testAudioPath));
146146

147147
service.Recognize(
148148
callback: (DetailedResponse<SpeechRecognitionResults> response, IBMError error) =>
@@ -171,7 +171,7 @@ public IEnumerator TestCreateJob()
171171
{
172172
Log.Debug("SpeechToTextServiceV1IntegrationTests", "Attempting to CreateJob...");
173173
RecognitionJob createJobResponse = null;
174-
byte[] audio = File.ReadAllBytes(testAudioPath);
174+
MemoryStream audio = new MemoryStream(File.ReadAllBytes(testAudioPath));
175175

176176
service.CreateJob(
177177
callback: (DetailedResponse<RecognitionJob> response, IBMError error) =>
@@ -687,7 +687,7 @@ public IEnumerator TestAddGrammar()
687687
},
688688
customizationId: customizationId,
689689
grammarName: grammarName,
690-
grammarFile: File.ReadAllText(grammarPath),
690+
grammarFile: new MemoryStream(File.ReadAllBytes(grammarPath)),
691691
contentType: grammarsContentType,
692692
allowOverwrite: true
693693
);
@@ -933,7 +933,7 @@ public IEnumerator TestAddAudio()
933933
},
934934
customizationId: acousticModelCustomizationId,
935935
audioName: acousticResourceName,
936-
audioResource: acousticResourceData,
936+
audioResource: new MemoryStream(acousticResourceData),
937937
allowOverwrite: true,
938938
contentType: acousticResourceMimeType,
939939
containedContentType: acousticResourceMimeType

Tests/ToneAnalyzerV3IntegrationTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
using IBM.Watson.ToneAnalyzer.V3.Model;
2424
using NUnit.Framework;
2525
using UnityEngine.TestTools;
26+
using System.Text;
27+
using System.IO;
28+
2629

2730
namespace IBM.Watson.Tests
2831
{
@@ -63,10 +66,8 @@ public IEnumerator TestTone()
6366
{
6467
Log.Debug("ToneAnalyzerServiceV3IntegrationTests", "Attempting to Tone...");
6568
ToneAnalysis toneResponse = null;
66-
ToneInput toneInput = new ToneInput()
67-
{
68-
Text = inputText
69-
};
69+
byte[] bytes = Encoding.ASCII.GetBytes(inputText);
70+
MemoryStream toneInput = new MemoryStream(bytes);
7071
service.Tone(
7172
callback: (DetailedResponse<ToneAnalysis> response, IBMError error) =>
7273
{

0 commit comments

Comments
 (0)