コード例 #1
0
        public void DetectRequest_DetectEnglish()
        {
            IResponseGenerator responseGenerator = new TranslatorResponseGenerator();
            var requestModels = new List <TranslatorRequestModel>
            {
                new TranslatorRequestModel()
                {
                    Text = "This is an English example."
                }
            };
            var detectRequest = GetDetectRequestMessage(requestModels);
            var response      = responseGenerator.GenerateDetectResponseAsync(detectRequest).GetAwaiter().GetResult();
            var lang          = response.FirstOrDefault().Language;

            Assert.AreEqual("en", lang);
        }
コード例 #2
0
        public void DetectRequest_DetectFrench()
        {
            IResponseGenerator responseGenerator = new TranslatorResponseGenerator();
            var requestModels = new List <TranslatorRequestModel>
            {
                new TranslatorRequestModel()
                {
                    Text = "C'est un exemple français."
                }
            };
            var detectRequest = GetDetectRequestMessage(requestModels);
            var response      = responseGenerator.GenerateDetectResponseAsync(detectRequest).GetAwaiter().GetResult();
            var lang          = response.FirstOrDefault().Language;

            Assert.AreEqual("fr", lang);
        }
コード例 #3
0
        public void TranslateRequest_TranslateEnglishToFrench()
        {
            IResponseGenerator            responseGenerator = new TranslatorResponseGenerator();
            List <TranslatorRequestModel> requestModels     = new List <TranslatorRequestModel>
            {
                new TranslatorRequestModel()
                {
                    Text = "This is an English example."
                }
            };
            string from = "en", to = "fr";
            var    detectRequest = GetTranslateRequestMessage(from, to, requestModels);
            var    response      = responseGenerator.GenerateTranslateResponseAsync(detectRequest).GetAwaiter().GetResult();
            var    lang          = response.FirstOrDefault();

            Assert.AreEqual("C'est un exemple anglais.", lang.Translations.FirstOrDefault().Text);
        }