Esempio n. 1
0
        public async void Words_Should_Be_Ordered_Decreasing_By_Count()
        {
            {
                //Arrange
                const string sampleUrl  = "https://www.google.com";
                const string sampleText = "One occurance of This, but Three occurances of occurance, yes, occurance.";
                textReaderServiceMock.Setup(service => service.GetTextFromSource(sampleUrl)).ReturnsAsync(sampleText);

                //Act
                var countedWords = await textSplitterService.GetWordsFromUrlAsync(sampleUrl, 2);

                //Assert
                Assert.AreEqual("occurance", countedWords[0].Key);
                Assert.AreEqual("of", countedWords[1].Key);
            }
        }
Esempio n. 2
0
        public async Task <JsonResult> GetTextFromUrlAsync(string urlToSearch)
        {
            var wordCounts = await _textSplitterService.GetWordsFromUrlAsync(urlToSearch, 100);

            _wordCounterService.StoreWordCounts(wordCounts, 100);

            return(new JsonResult(wordCounts));
        }
        public async Task <IActionResult> Index(string urlToSearch)
        {
            try
            {
                var wordCounts = await _textSplitterService.GetWordsFromUrlAsync(urlToSearch, 100);

                _wordCounterService.StoreWordCounts(wordCounts, 100);

                var viewModel = new WordCounterViewModel
                {
                    Url              = urlToSearch,
                    CountedWords     = wordCounts,
                    CountedWordsJson = Json(wordCounts)
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                ViewData["ErrorMessage"] = e.Message;
                ViewData["ErrorStack"]   = e.StackTrace;
                ViewData["ErrorInner"]   = e.InnerException?.Message;
                return(View("Error"));
            }
        }