示例#1
0
        public void CTOR_ShouldInstaciate_WhenValidInjectionIsProvided()
        {
            var mockILogger = new Mock <ILogger>();
            var mockITRSTranslationService = new Mock <ITRSTranslationService>();

            var sut = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);

            Assert.NotNull(sut);
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Never);
        }
        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);
        }
        public void IsCorrectTranslation_ThrowsIsNullOrWhiteSpaceException_WhenSourceStringToTranslateIsNotProvided()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            LoggedException.Logger = mockILogger.Object;

            var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var MLSToCheck    = new MultiLanguageString("Not a good translation", "Some wrong DutchString", "  ");

            //ACT & ASSERT
            Assert.Throws <IsNullOrWhiteSpaceException>(() => translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.Dutch));
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never);
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Once);
        }
        public void IsCorrectTranslation_ThrowsIsNullOrWhiteSpaceException_WhenMultiLanguageStringIsNULL()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            LoggedException.Logger = mockILogger.Object;

            var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            MultiLanguageString MLSToCheck = null;

            //ACT & ASSERT
            Assert.Throws <LoggedException>(() => translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.Dutch));
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()), Times.Never);
            mockILogger.Verify(x => x.Error(It.IsAny <ArgumentNullException>(), It.IsAny <string>()), Times.Once);
        }
        public void IsCorrectTranslation_CallsOnceTranslator_When2LanguageNOTWellTranslated_PerformanceTest()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var FrenchSource  = "French Source String";
            var MLSToCheck    = new MultiLanguageString("blah blah blah...", FrenchSource, "blah blah blah...");

            //ACT
            var translated = translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.French);

            //ASSERT
            Assert.False(translated);
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()),
                                              Times.Once);
        }
        public void IsCorrectTranslation_ReturnsFalse_When_FRENCH_IsNOT_WellTranslated()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var FrenchSource  = "French Source String";
            var MLSToCheck    = new MultiLanguageString(TestHelper.EnglishTranslated, FrenchSource, "Some wrong DutchString");

            //ACT
            var translated = translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.French);

            //ASSERT
            Assert.False(translated);
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()),
                                              Times.AtMost(Enum.GetNames(typeof(Language)).Count() - 1));
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Never);
        }
        public void IsCorrectTranslation_ReturnsTrue_When_DUTCH_IS_WellTranslated()
        {
            //ARRANGE
            var mockILogger = TestHelper.MakeILogger();
            var mockITRSTranslationService = TestHelper.MakeITRSTranslationService();

            var translationUC = new OnlineServicesRole(mockILogger.Object, mockITRSTranslationService.Object);
            var DutchSource   = "Dutch Source String";
            var MLSToCheck    = new MultiLanguageString(TestHelper.EnglishTranslated, TestHelper.FrenchTranslated, DutchSource);

            //ACT
            var translated = translationUC.IsCorrectTranslation(TestHelper.FakeApiKey, MLSToCheck, Language.Dutch);

            //ASSERT
            Assert.True(translated);
            mockITRSTranslationService.Verify(x => x.TranslateAsync(It.IsAny <Tuple <Language, string> >()),
                                              Times.Once);
            mockILogger.Verify(x => x.Error(It.IsAny <string>()), Times.Never);
        }
        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);
        }
示例#10
0
        protected override void BeginProcessing()
        {
            OSService = new OnlineServicesRole(OnlineServicesLogger.LoggerConfigurator(), new AzureCognitiveAgent(OnlineServicesLogger.LoggerConfigurator(), AzCognitiveArgs));

            base.BeginProcessing();
        }