public async Task Translator_Translate_Post_ReturnsView_WhenModelStateIsInvalid() { //Arrange var mockRepo = new Mock <ITranslatorRepository>(); mockRepo.Setup(repo => repo.GetQueriesAsync()) .ReturnsAsync(GetTestQueries()); var mockRepo2 = new Mock <ITranslationRepository>(); mockRepo2.Setup(repo => repo.GetTranslationsAsync()) .ReturnsAsync(GetTestTranslations()); var mockService = new Mock <IApiHttpClientService>(); mockService.Setup(service => service.GetResponseAsync("", "")) .ReturnsAsync(GetTestResponse()); var controller = new TranslatorController(mockService.Object, mockRepo.Object, mockRepo2.Object); controller.ModelState.AddModelError("Text", "Required"); controller.ModelState.AddModelError("Id", "Required"); var viewModel = new TranslatorViewModel(); //Act var result = await controller.Translate(viewModel); //Assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <TranslatorViewModel>( viewResult.ViewData.Model); }
public async Task Translator_Translate_Post_ReturnsRedirectToAction_WhereModelStateIsValid() { //Arrange var mockRepo = new Mock <ITranslatorRepository>(); mockRepo.Setup(repo => repo.AddResponseAsync(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <SuccessResponse>(), It.IsAny <ErrorResponse>())) .Returns(Task.CompletedTask) .Verifiable(); var mockRepo2 = new Mock <ITranslationRepository>(); mockRepo2.Setup(repo => repo.GetTranslationsAsync()) .ReturnsAsync(GetTestTranslations()); var mockService = new Mock <IApiHttpClientService>(); mockService.Setup(service => service.GetResponseAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(It.IsAny <HttpResponseMessage>()); var controller = new TranslatorController(mockService.Object, mockRepo.Object, mockRepo2.Object); var viewModel = new TranslatorViewModel { Id = 1, Text = "test" }; //Act var result = await controller.Translate(viewModel); //Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Null(redirectToActionResult.ControllerName); Assert.Equal("Details", redirectToActionResult.ActionName); mockRepo.Verify(); }
public async Task TranslateText() { var textToTranslate = @"ἁμαρτία, (ας, ἡ (from 2 aorist ἁμαρτεῖν, as ἀποτυχία from ἀποτύχειν), a failing to hit the mark (see ἁμαρτάνω. In Greek writings (from Aeschylus and Thucydides down). 1st, an error of the understanding (cf. Ackermann, Das Christl. im Plato, p. 59 Anm. 3 (English translation (S. R. Asbury, 1861), p. 57 n. 99)). 2nd, a bad action, evil deed. In the N. T. always in an ethical sense, and"; var controller = new TranslatorController(); var result = await controller.Translate(textToTranslate); if (result != null) { } }
private void Translate() { _translatorController.UpdateCurrentTranslator(_currentOption); var response = _translatorController.Translate(tboxInput.Text); pboxValidationIcon.Visible = response.MessageType != TranslationResponseObject.Severity.Formatted; if (response.MessageType == TranslationResponseObject.Severity.Error) { pboxValidationIcon.Image = new Bitmap(Path.GetFullPath(Path.Combine(Application.StartupPath, @"..\..\Images\invalid.png"))); } tboxOutput.Text = response.Output; }
private async Task <string> GetTranslation(TranslatorController controller, string text) { var _translation = await controller.Translate(text); if (_translation.IsNotNull()) { if (_translation.Length > 0) { if (_translation.First().Translations.Length > 0) { return(_translation.First().Translations.First().Text); } } } return(String.Empty); }
public async Task Translator_Translate_Get_ReturnsAView() { //Arrange var mockRepo = new Mock <ITranslatorRepository>(); mockRepo.Setup(repo => repo.GetQueriesAsync()) .ReturnsAsync(GetTestQueries()); var mockRepo2 = new Mock <ITranslationRepository>(); mockRepo2.Setup(repo => repo.GetTranslationsAsync()) .ReturnsAsync(GetTestTranslations()); var mockService = new Mock <IApiHttpClientService>(); mockService.Setup(service => service.GetResponseAsync("", "")) .ReturnsAsync(GetTestResponse()); var controller = new TranslatorController(mockService.Object, mockRepo.Object, mockRepo2.Object); //Act var result = await controller.Translate(); //Assert var viewResult = Assert.IsType <ViewResult>(result); }