public void GetTranslation_ThrowsIsNullOrWhiteSpaceException_WhenAPIKeyIsNotProvided()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            LoggedException.Logger = mockILogger.Object;

            var translationUC         = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var DutchTupleToTranslate = new Tuple <Language, string>(Language.Dutch, "Dutch Source String");

            //ACT & ASSERT
            Assert.Throws <NecessaryDataException>(() => translationUC.GetTranslations(null, DutchTupleToTranslate));
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never);
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Once);
        }
        public void GetTranslation_ThrowsIsNullOrWhiteSpaceException_WhenMultiLanguageStringIsNULL()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            LoggedException.Logger = mockILogger.Object;

            var translationUC    = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var TupleToTranslate = new Tuple <Language, string>(Language.French, null);

            //ACT & ASSERT
            Assert.Throws <IsNullOrWhiteSpaceException>(() => translationUC.GetTranslations(TestHelper.FakeApiKey, TupleToTranslate));
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never);
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Once);
        }
Exemple #3
0
        protected override void ProcessRecord()
        {
            if (string.IsNullOrWhiteSpace(Source))
            {
                WriteObject("");
            }

            var translations =
                OSService.GetTranslations(new ServiceAuthorization(), new Tuple <Language, string>(LanguageName, Source));

            foreach (var t in translations.ToTuplesLanguage())
            {
                WriteObject($"{Enum.GetName(typeof(Language), t.Item1)} - {t.Item2}");
            }

            base.ProcessRecord();
        }
        public void GetTranslation_ShouldNotTranslateDutch_WhenValidParamIsProvided()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            LoggedException.Logger = mockILogger.Object;

            var translationUC         = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var DutchTupleToTranslate = new Tuple <Language, string>(Language.Dutch, "Dutch Source String");

            //ACT
            var translated = translationUC.GetTranslations(TestHelper.FakeApiKey, DutchTupleToTranslate);

            //ASSERT
            Assert.NotNull(translated);
            Assert.Equal(TestHelper.EnglishTranslated, translated.ToString(Language.English));
            Assert.Equal(TestHelper.FrenchTranslated, translated.ToString(Language.French));
            Assert.Equal(DutchTupleToTranslate.Item2, translated.ToString(Language.Dutch));
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()),
                                              Times.Once);
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Never);
        }