public void DetectionValid()
        {
            var service  = new FakeTranslateService();
            var client   = new AdvancedTranslationClientImpl(service);
            var inputs   = new string[] { "a", "b" };
            var request  = service.Detections.List(new Repeatable <string>(inputs));
            var response = new DetectionsListResponse
            {
                Detections = new List <IList <DetectionsResourceItems> >
                {
                    new List <DetectionsResourceItems> {
                        new DetectionsResourceItems {
                            Language = "en", Confidence = 0.5f, IsReliable = true
                        }
                    },
                    new List <DetectionsResourceItems> {
                        new DetectionsResourceItems {
                            Language = "fr", Confidence = 0.8f, IsReliable = true
                        }
                    },
                }
            };

            service.ExpectRequest(request, response);
            var result = client.DetectLanguages(inputs);

            // Just check the original text and language.
            Assert.Equal("a", result[0].Text);
            Assert.Equal("en", result[0].Language);

            Assert.Equal("b", result[1].Text);
            Assert.Equal("fr", result[1].Language);
        }
        public void DetectionResultHasNonSingleList(int count)
        {
            var service  = new FakeTranslateService();
            var client   = new AdvancedTranslationClientImpl(service);
            var inputs   = new string[] { "a", "b" };
            var request  = service.Detections.List(new Repeatable <string>(inputs));
            var response = new DetectionsListResponse
            {
                // This time we have the right number of top-level results, but the second
                // result doesn't have a single entry
                Detections = new List <IList <DetectionsResourceItems> >
                {
                    new List <DetectionsResourceItems> {
                        new DetectionsResourceItems {
                            Language = "en"
                        }
                    },
                    Enumerable.Repeat(new DetectionsResourceItems {
                        Language = "en"
                    }, count).ToList()
                }
            };

            service.ExpectRequest(request, response);
            Assert.Throws <InvalidOperationException>(() => client.DetectLanguages(inputs));
        }
        public void NonMatchingTranslateResultCount()
        {
            var service = new FakeTranslateService();
            var client  = new AdvancedTranslationClientImpl(service);
            var inputs  = new string[] { "a", "b" };
            var request = service.Translations.List(new Repeatable <string>(inputs), "en");

            request.Format = FormatEnum.Text;
            var response = new TranslationsListResponse
            {
                // Content is irrelevant; we shouldn't get that far
                Translations = new List <TranslationsResource> {
                    new TranslationsResource()
                }
            };

            service.ExpectRequest(request, response);
            Assert.Throws <InvalidOperationException>(() => client.TranslateText(inputs, "en"));
        }
        public void NonMatchingDetectionResultCount()
        {
            var service  = new FakeTranslateService();
            var client   = new AdvancedTranslationClientImpl(service);
            var inputs   = new string[] { "a", "b" };
            var request  = service.Detections.List(new Repeatable <string>(inputs));
            var response = new DetectionsListResponse
            {
                // Content is irrelevant; we shouldn't get that far
                Detections = new List <IList <DetectionsResourceItems> >
                {
                    new List <DetectionsResourceItems> {
                        new DetectionsResourceItems {
                            Language = "en"
                        }
                    }
                }
            };

            service.ExpectRequest(request, response);
            Assert.Throws <InvalidOperationException>(() => client.DetectLanguages(inputs));
        }