Skip to content

Commit cc0cb5c

Browse files
committed
refactor: hand written changes and more integration tests
1 parent a89aab0 commit cc0cb5c

File tree

3 files changed

+67
-24
lines changed

3 files changed

+67
-24
lines changed

Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,8 @@ public bool TranslateDocument(Callback<DocumentStatus> callback, System.IO.Memor
795795
throw new ArgumentNullException("`callback` is required for `TranslateDocument`");
796796
if (file == null)
797797
throw new ArgumentNullException("`file` is required for `TranslateDocument`");
798+
if (filename == null)
799+
throw new ArgumentNullException("`filename` is required for `TranslateDocument`");
798800

799801
RequestObject<DocumentStatus> req = new RequestObject<DocumentStatus>
800802
{

Scripts/Services/SpeechToText/V1/Model/SpeechRecognitionAlternative.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public class SpeechRecognitionAlternative
4242
/// `[[\"hello\",0.0,1.2],[\"world\",1.2,2.5]]`. Timestamps are returned only for the best alternative.
4343
/// </summary>
4444
[JsonProperty("timestamps", NullValueHandling = NullValueHandling.Ignore)]
45-
public List<string> Timestamps { get; set; }
45+
public string[][] Timestamps { get; set; }
4646
/// <summary>
4747
/// A confidence score for each word of the transcript as a list of lists. Each inner list consists of two
4848
/// elements: the word and its confidence score in the range of 0.0 to 1.0, for example:
4949
/// `[[\"hello\",0.95],[\"world\",0.866]]`. Confidence scores are returned only for the best alternative and
5050
/// only with results marked as final.
5151
/// </summary>
5252
[JsonProperty("word_confidence", NullValueHandling = NullValueHandling.Ignore)]
53-
public List<string> WordConfidence { get; set; }
53+
public string[][] WordConfidence { get; set; }
5454
}
5555
}

Tests/LanguageTranslatorV3IntegrationTests.cs

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class LanguageTranslatorV3IntegrationTests
3333
private string versionDate = "2019-02-13";
3434
private string forcedGlossaryFilepath;
3535
private string translateDocumentPath;
36+
private string documentId;
3637
private string englishText = "Where is the library?";
3738
private string spanishText = "¿Dónde está la biblioteca?";
3839
private string englishToSpanishModel = "en-es";
@@ -266,14 +267,15 @@ public IEnumerator TestTranslateDocument()
266267
service.TranslateDocument(
267268
callback: (DetailedResponse<DocumentStatus> response, IBMError error) =>
268269
{
269-
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Translate result: {0}", response.Response);
270+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Translate Document result: {0}", response.Response);
270271
documentStatus = response.Result;
271272
Assert.IsNotNull(documentStatus);
272273
Assert.IsNotNull(documentStatus.DocumentId);
274+
documentId = documentStatus.DocumentId;
273275
Assert.IsNull(error);
274276
},
275277
file: ms,
276-
filename: "trabslate-document.txt",
278+
filename: "translate-document.txt",
277279
modelId: "en-fr"
278280
);
279281

@@ -285,32 +287,71 @@ public IEnumerator TestTranslateDocument()
285287
#endregion
286288

287289
#region List Documents
288-
[UnityTest, Order(99)]
290+
[UnityTest, Order(9)]
289291
public IEnumerator TestListDocuments()
290292
{
291-
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Attempting to Translate...");
293+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Getting the document list...");
292294
DocumentList documents = null;
293295

294-
using (FileStream fs = File.OpenRead(translateDocumentPath))
295-
{
296-
using (MemoryStream ms = new MemoryStream())
296+
service.ListDocuments(
297+
callback: (DetailedResponse<DocumentList> response, IBMError error) =>
297298
{
298-
fs.CopyTo(ms);
299-
service.ListDocuments(
300-
callback: (DetailedResponse<DocumentList> response, IBMError error) =>
301-
{
302-
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Translate result: {0}", response.Response);
303-
documents = response.Result;
304-
Assert.IsNotNull(documents);
305-
Assert.IsNull(error);
306-
}
307-
);
308-
309-
while (documents == null)
310-
yield return null;
299+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "List Documents result: {0}", response.Response);
300+
documents = response.Result;
301+
Assert.IsNotNull(documents);
302+
Assert.IsNull(error);
311303
}
312-
}
304+
);
305+
306+
while (documents == null)
307+
yield return null;
313308
}
314309
#endregion
310+
311+
#region Get Document Status
312+
[UnityTest, Order(10)]
313+
public IEnumerator TestGetDocumentStatus()
314+
{
315+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Getting document status...");
316+
DocumentStatus documentStatus = null;
317+
318+
service.GetDocumentStatus(
319+
callback: (DetailedResponse<DocumentStatus> response, IBMError error) =>
320+
{
321+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Get Document Status: {0}", response.Response);
322+
documentStatus = response.Result;
323+
Assert.IsNotNull(documentStatus);
324+
Assert.IsNull(error);
325+
},
326+
documentId: documentId
327+
);
328+
329+
while (documentStatus == null)
330+
yield return null;
315331
}
316-
}
332+
#endregion
333+
334+
#region Delete Document
335+
[UnityTest, Order(99)]
336+
public IEnumerator TestDeletetDocument()
337+
{
338+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Deleteing the Document...");
339+
object deleteResponse = null;
340+
341+
service.DeleteDocument(
342+
callback: (DetailedResponse<object> response, IBMError error) =>
343+
{
344+
Log.Debug("LanguageTranslatorServiceV3IntegrationTests", "Delete Document result: {0}", response.Response);
345+
deleteResponse = response.Result;
346+
Assert.IsTrue(response.StatusCode == 204);
347+
Assert.IsNull(error);
348+
},
349+
documentId: documentId
350+
);
351+
352+
while (deleteResponse == null)
353+
yield return null;
354+
}
355+
#endregion
356+
}
357+
}

0 commit comments

Comments
 (0)