예제 #1
0
        public void Analysis_NotResponseUrl_ReturnViewModelWithErrorMessage()
        {
            // Arrange
            SeoAnalyserMainModel seoAnalyserMainModel = new SeoAnalyserMainModel();

            seoAnalyserMainModel.InputViewModel = new InputViewModel
            {
                Input                         = "https://www.youtube.com",
                IsFilterStopWords             = true,
                IsCalculateNoOfWordInPage     = true,
                IsCalculateNoOfWordInMetaTags = true,
                IsCalculateNoOfExternalLinks  = true
            };

            _validateServiceMock.Setup(x => x.ValidUrl(It.IsAny <string>())).Returns(true);
            _validateServiceMock.Setup(x => x.ValidateWebsite(It.IsAny <string>())).Returns(false);

            // Act
            var result = _target.Analysis(seoAnalyserMainModel) as ViewResult;

            // Assert
            Assert.AreEqual(typeof(ViewResult), result.GetType());
            var viewResult = (ViewResult)result;

            Assert.AreEqual(typeof(SeoAnalyserMainModel), viewResult.Model.GetType());
            _validateServiceMock.Verify(m => m.ValidUrl(It.IsAny <string>()), Times.Once);
            _validateServiceMock.Verify(m => m.ValidateWebsite(It.IsAny <string>()), Times.Once);
            _analysisServiceMock.Verify(m => m.CalculateNoOfWordInPage(It.IsAny <string>(), true, true), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfWordsInMetaTags(It.IsAny <string>()), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfExternalLinks(It.IsAny <string>()), Times.Never);
        }
예제 #2
0
        public void Analysis_ValidInutText_ReturnViewModel()
        {
            // Arrange
            SeoAnalyserMainModel seoAnalyserMainModel = new SeoAnalyserMainModel();

            seoAnalyserMainModel.InputViewModel = new InputViewModel
            {
                Input                         = "Hello the world!",
                IsFilterStopWords             = true,
                IsCalculateNoOfWordInPage     = true,
                IsCalculateNoOfWordInMetaTags = true,
                IsCalculateNoOfExternalLinks  = true
            };

            _validateServiceMock.Setup(x => x.ValidUrl(It.IsAny <string>())).Returns(false);
            _mapperMock.Setup(x => x.Map <IEnumerable <WordsInPageViewModel> >(It.IsAny <IEnumerable <WordsInPage> >()))
            .Returns(GetWordsInPageViewModelViewModelList());

            // Act
            var result = _target.Analysis(seoAnalyserMainModel) as ViewResult;

            // Assert
            var viewResult = (ViewResult)result;
            var model      = (SeoAnalyserMainModel)viewResult.Model;

            Assert.IsNotNull(model.OutputViewModel.WordsInPages);
            Assert.IsNull(model.OutputViewModel.WordsInMetaTags);
            Assert.IsNull(model.OutputViewModel.ExternalLinks);
            _validateServiceMock.Verify(m => m.ValidateWebsite(It.IsAny <string>()), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfWordInPage(It.IsAny <string>(), true, false), Times.Once);
            _analysisServiceMock.Verify(m => m.CalculateNoOfWordsInMetaTags(It.IsAny <string>()), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfExternalLinks(It.IsAny <string>()), Times.Never);
        }
예제 #3
0
        public void Analysis_WithModelStateError_ReturnViewModelWithErrorMessage()
        {
            // Arrange
            _target.ModelState.AddModelError("Input", "Required");
            SeoAnalyserMainModel seoAnalyserMainModel = new SeoAnalyserMainModel();

            // Act
            var result = _target.Analysis(seoAnalyserMainModel) as ViewResult;

            // Assert
            Assert.AreEqual(typeof(ViewResult), result.GetType());
            var viewResult = (ViewResult)result;

            Assert.AreEqual(typeof(SeoAnalyserMainModel), viewResult.Model.GetType());
            _validateServiceMock.Verify(m => m.ValidUrl(It.IsAny <string>()), Times.Never);
            _validateServiceMock.Verify(m => m.ValidateWebsite(It.IsAny <string>()), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfWordInPage(It.IsAny <string>(), true, true), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfWordsInMetaTags(It.IsAny <string>()), Times.Never);
            _analysisServiceMock.Verify(m => m.CalculateNoOfExternalLinks(It.IsAny <string>()), Times.Never);
        }
예제 #4
0
        public ActionResult Analysis(SeoAnalyserMainModel model)
        {
            if (ModelState.IsValid)
            {
                bool isUrL = _validateService.ValidUrl(model.InputViewModel.Input);

                if (isUrL)
                {
                    if (!_validateService.ValidateWebsite(model.InputViewModel.Input))
                    {
                        ModelState.AddModelError("Input", "Not a responding website");
                        return(View("Index", model));
                    }
                    model.OutputViewModel = AnalysisURL(model.InputViewModel);
                }
                else
                {
                    model.OutputViewModel = AnalysisText(model.InputViewModel);
                }
            }
            return(View("Index", model));
        }
예제 #5
0
        public ActionResult Index()
        {
            var model = new SeoAnalyserMainModel();

            return(View(model));
        }