public async Task Translator_PatternsTest_EmptyLanguagePatternsData() { if (!EnvironmentVariablesDefined()) { Assert.Inconclusive("Missing Translator Environment variables - Skipping test"); return; } Translator translator = new Translator(translatorKey); //using an empty language list won't throw an exception, but it won't affect the post processing for this language Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >(); List <string> spanishPatterns = new List <string>(); patterns.Add("es", spanishPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mi perro se llama Enzo"; var translatedDocuments = await translator.TranslateArray(new string[] { sentence }, "es", "en"); Assert.IsNotNull(translatedDocuments); string postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "es").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My dog's name is Enzo", postProcessedMessage); }
public async Task Translator_PatternsTest_FrenchPatterns() { if (!EnvironmentVariablesDefined()) { Assert.Inconclusive("Missing Translator Environment variables - Skipping test"); return; } Translator translator = new Translator(translatorKey); Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >(); List <string> frenchPatterns = new List <string> { "mon nom est (.+)" }; patterns.Add("fr", frenchPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mon nom est l'etat"; var translatedDocuments = await translator.TranslateArray(new string[] { sentence }, "fr", "en"); Assert.IsNotNull(translatedDocuments); string postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "fr").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My name is l'etat", postProcessedMessage); }
public async Task Translator_PatternsTest_SpanishPatterns() { if (!EnvironmentVariablesDefined()) { Assert.Inconclusive("Missing Translator Environment variables - Skipping test"); return; } Translator translator = new Translator(translatorKey); Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >(); List <string> spanishPatterns = new List <string> { "perr[oa]" }; patterns.Add("es", spanishPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mi perro se llama Enzo"; var translatedDocuments = await translator.TranslateArray(new string[] { sentence }, "es", "en"); Assert.IsNotNull(translatedDocuments); string postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "es").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My perro's name is Enzo", postProcessedMessage); }
public async Task Translator_PatternsTest_EmptyLanguagePatternsData() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, "https://api.cognitive.microsoft.com/sts/v1.0/issueToken") .Respond("application/jwt", "<--valid-bearer-token-->"); mockHttp.When(HttpMethod.Get, GetRequestDetect("mi perro se llama Enzo")) .Respond("application/xml", GetResponseDetect("es")); mockHttp.When(HttpMethod.Post, @"https://api.microsofttranslator.com/v2/Http.svc/TranslateArray2") .Respond("application/xml", GetResponse("Translator_PatternsTest_EmptyLanguagePatternsData.xml")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); //using an empty language list won't throw an exception, but it won't affect the post processing for this language var patterns = new Dictionary <string, List <string> >(); var spanishPatterns = new List <string>(); patterns.Add("es", spanishPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mi perro se llama Enzo"; var translatedDocuments = await translator.TranslateArrayAsync(new string[] { sentence }, "es", "en"); Assert.IsNotNull(translatedDocuments); var postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "es").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My dog's name is Enzo", postProcessedMessage); }
public async Task Translator_PatternsTest_FrenchPatterns() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, "https://api.cognitive.microsoft.com/sts/v1.0/issueToken") .Respond("application/jwt", "<--valid-bearer-token-->"); mockHttp.When(HttpMethod.Get, GetRequestDetect("mon nom est l'etat")) .Respond("application/xml", GetResponseDetect("fr")); mockHttp.When(HttpMethod.Post, @"https://api.microsofttranslator.com/v2/Http.svc/TranslateArray2") .Respond("application/xml", GetResponse("Translator_PatternsTest_FrenchPatterns.xml")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); var patterns = new Dictionary <string, List <string> >(); var frenchPatterns = new List <string> { "mon nom est (.+)" }; patterns.Add("fr", frenchPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mon nom est l'etat"; var translatedDocuments = await translator.TranslateArrayAsync(new string[] { sentence }, "fr", "en"); Assert.IsNotNull(translatedDocuments); var postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "fr").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My name is l'etat", postProcessedMessage); }
public async Task Translator_PatternsTest_FrenchPatterns() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetTranslateUri("fr", "en")) .Respond("application/json", GetResponse("Translator_PatternsTest_FrenchPatterns.json")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); var patterns = new Dictionary <string, List <string> >(); var frenchPatterns = new List <string> { "mon nom est (.+)" }; patterns.Add("fr", frenchPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mon nom est l'etat"; var translatedDocuments = await translator.TranslateArrayAsync(new string[] { sentence }, "fr", "en"); Assert.IsNotNull(translatedDocuments); var postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "fr").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My name is l'etat", postProcessedMessage); }
public async Task Translator_PatternsTest_EmptyLanguagePatternsData() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetTranslateUri("es", "en")) .Respond("application/json", GetResponse("Translator_PatternsTest_EmptyLanguagePatternsData.json")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); //using an empty language list won't throw an exception, but it won't affect the post processing for this language var patterns = new Dictionary <string, List <string> >(); var spanishPatterns = new List <string>(); patterns.Add("es", spanishPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mi perro se llama Enzo"; var translatedDocuments = await translator.TranslateArrayAsync(new string[] { sentence }, "es", "en"); Assert.IsNotNull(translatedDocuments); var postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "es").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My dog's name is Enzo", postProcessedMessage); }
public async Task Translator_PatternsTest_SpanishPatterns() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetTranslateUri("es", "en")) .Respond("application/json", GetResponse("Translator_PatternsTest_SpanishPatterns.json")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); var patterns = new Dictionary <string, List <string> >(); var spanishPatterns = new List <string> { "perr[oa]" }; patterns.Add("es", spanishPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); var sentence = "mi perro se llama Enzo"; var translatedDocuments = await translator.TranslateArrayAsync(new string[] { sentence }, "es", "en"); Assert.IsNotNull(translatedDocuments); var postProcessedMessage = patternsPostProcessor.Process(translatedDocuments[0], "es").PostProcessedMessage; Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My perro's name is Enzo", postProcessedMessage); }
public async Task Translator_PatternsAndDictionaryTest() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, "https://api.cognitive.microsoft.com/sts/v1.0/issueToken") .Respond("application/jwt", "<--valid-bearer-token-->"); mockHttp.When(HttpMethod.Get, GetRequestDetect("mon nom est eta")) .Respond("application/xml", GetResponseDetect("fr")); mockHttp.When(HttpMethod.Post, @"https://api.microsofttranslator.com/v2/Http.svc/TranslateArray2") .Respond("application/xml", GetResponse("Translator_PatternsAndDictionaryTest.xml")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); //creating the patterns post processor var attachedPostProcessors = new List <IPostProcessor>(); var patterns = new Dictionary <string, List <string> >(); var frenchPatterns = new List <string> { "mon nom est (.+)" }; patterns.Add("fr", frenchPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); //attaching patterns post processor to the list of post processors attachedPostProcessors.Add(patternsPostProcessor); //creating user custom dictionary post processor var userCustomDictonaries = new CustomDictionary(); var frenctDictionary = new Dictionary <string, string> { { "etat", "Eldad" } }; userCustomDictonaries.AddNewLanguageDictionary("fr", frenctDictionary); IPostProcessor customDictionaryPostProcessor = new CustomDictionaryPostProcessor(userCustomDictonaries); //attaching user custom dictionary post processor to the list of post processors attachedPostProcessors.Add(customDictionaryPostProcessor); var sentence = "mon nom est etat"; //translating the document var translatedDocuments = await translator.TranslateArrayAsync(new string[] { sentence }, "fr", "en"); Assert.IsNotNull(translatedDocuments); string postProcessedMessage = null; //test the actual use case of the compined post processors together foreach (var postProcessor in attachedPostProcessors) { postProcessedMessage = postProcessor.Process(translatedDocuments[0], "fr").PostProcessedMessage; } Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My name is Eldad", postProcessedMessage); }
public async Task Translator_PatternsAndDictionaryTest() { if (!EnvironmentVariablesDefined()) { Assert.Inconclusive("Missing Translator Environment variables - Skipping test"); return; } //creating the patterns post processor List <IPostProcessor> attachedPostProcessors = new List <IPostProcessor>(); Translator translator = new Translator(translatorKey); Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >(); List <string> frenchPatterns = new List <string> { "mon nom est (.+)" }; patterns.Add("fr", frenchPatterns); IPostProcessor patternsPostProcessor = new PatternsPostProcessor(patterns); //attaching patterns post processor to the list of post processors attachedPostProcessors.Add(patternsPostProcessor); //creating user custom dictionary post processor CustomDictionary userCustomDictonaries = new CustomDictionary(); Dictionary <string, string> frenctDictionary = new Dictionary <string, string> { { "etat", "Eldad" } }; userCustomDictonaries.AddNewLanguageDictionary("fr", frenctDictionary); IPostProcessor customDictionaryPostProcessor = new CustomDictionaryPostProcessor(userCustomDictonaries); //attaching user custom dictionary post processor to the list of post processors attachedPostProcessors.Add(customDictionaryPostProcessor); var sentence = "mon nom est etat"; //translating the document var translatedDocuments = await translator.TranslateArray(new string[] { sentence }, "fr", "en"); Assert.IsNotNull(translatedDocuments); string postProcessedMessage = null; //test the actual use case of the compined post processors together foreach (IPostProcessor postProcessor in attachedPostProcessors) { postProcessedMessage = postProcessor.Process(translatedDocuments[0], "fr").PostProcessedMessage; } Assert.IsNotNull(postProcessedMessage); Assert.AreEqual("My name is Eldad", postProcessedMessage); }
public async Task Translator_LiteralTagTest() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, GetTranslateUri("fr", "en")) .Respond("application/json", GetResponse("Translator_LiteralTagTest.json")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); var sentence = "salut <literal>Jean Bouchier mon ami</literal>"; var translatedSentence = await translator.TranslateArrayAsync(new string[] { sentence }, "fr", "en"); var patterns = new Dictionary <string, List <string> >(); patterns.Add("fr", new List <string>()); var postProcessor = new PatternsPostProcessor(patterns); var postProcessedDocument = postProcessor.Process(translatedSentence[0], "fr"); Assert.IsNotNull(translatedSentence); Assert.AreEqual("Hi Jean Bouchier mon ami", postProcessedDocument.PostProcessedMessage); }
public async Task Translator_LiteralTagTest() { if (!EnvironmentVariablesDefined()) { Assert.Inconclusive("Missing Translator Environment variables - Skipping test"); return; } Translator translator = new Translator(translatorKey); var sentence = "salut <literal>Jean Bouchier mon ami</literal>"; var translatedSentence = await translator.TranslateArray(new string[] { sentence }, "fr", "en"); Dictionary <string, List <string> > patterns = new Dictionary <string, List <string> >(); patterns.Add("fr", new List <string>()); PatternsPostProcessor postProcessor = new PatternsPostProcessor(patterns); PostProcessedDocument postProcessedDocument = postProcessor.Process(translatedSentence[0], "fr"); Assert.IsNotNull(translatedSentence); Assert.AreEqual("Hi Jean Bouchier mon ami", postProcessedDocument.PostProcessedMessage); }
public async Task Translator_LiteralTagTest() { var mockHttp = new MockHttpMessageHandler(); mockHttp.When(HttpMethod.Post, "https://api.cognitive.microsoft.com/sts/v1.0/issueToken") .Respond("application/jwt", "<--valid-bearer-token-->"); mockHttp.When(HttpMethod.Post, @"https://api.microsofttranslator.com/v2/Http.svc/TranslateArray2") .Respond("application/xml", GetResponse("Translator_LiteralTagTest.xml")); var translator = new Translator(_translatorKey, mockHttp.ToHttpClient()); var sentence = "salut <literal>Jean Bouchier mon ami</literal>"; var translatedSentence = await translator.TranslateArrayAsync(new string[] { sentence }, "fr", "en"); var patterns = new Dictionary <string, List <string> >(); patterns.Add("fr", new List <string>()); var postProcessor = new PatternsPostProcessor(patterns); var postProcessedDocument = postProcessor.Process(translatedSentence[0], "fr"); Assert.IsNotNull(translatedSentence); Assert.AreEqual("Hi Jean Bouchier mon ami", postProcessedDocument.PostProcessedMessage); }