Exemple #1
0
        public void DetectRequest_EmptyTranslatorModel()
        {
            IRequestBuilder requestBuilder = new TranslatorRequestBuilder(_apiKey);
            var             requestModels  = new List <TranslatorRequestModel>();

            Assert.ThrowsException <ArgumentNullException>(() => requestBuilder.BuildDetectRequest(requestModels));
        }
Exemple #2
0
        public void TranslateRequest_NullTranslatorModel()
        {
            IRequestBuilder requestBuilder = new TranslatorRequestBuilder(_apiKey);
            List <TranslatorRequestModel> requestModels = null;

            Assert.ThrowsException <ArgumentNullException>(() => requestBuilder.BuildTranslateRequest("en", "fr", requestModels));
        }
Exemple #3
0
        public void DetectRequest_ValidRequest()
        {
            IRequestBuilder requestBuilder = new TranslatorRequestBuilder(_apiKey);
            var             requestModels  = new List <TranslatorRequestModel>();

            requestModels.Add(new TranslatorRequestModel()
            {
                Text = "C'est un exemple français."
            });
            var request = requestBuilder.BuildDetectRequest(requestModels);

            Assert.IsTrue(request.Headers.Contains("Ocp-Apim-Subscription-Key"));
            Assert.AreEqual(_apiKey, request.Headers.GetValues("Ocp-Apim-Subscription-Key").FirstOrDefault());

            Assert.AreEqual(DetectUrl, request.RequestUri.ToString());
            Assert.AreEqual(request.Content.ToString(), new StringContent(JsonConvert.SerializeObject(requestModels), Encoding.UTF8, "application/json").ToString());
        }