Esempio n. 1
0
        public async Task Create_Returns_RedirectToActionResult_WhenModelStateValid()
        {
            // Arrange
            JobPosting tempjob = new JobPosting
            {
                Title         = "Full Stack Developer",
                Company       = "Walmart",
                Description   = "Yolo Lyfe",
                NumberOfViews = 1
            };

            tempjob = CreateJobPostingAsync(tempjob);


            Mock <IJobPostingRepository> mockRepoJob = new Mock <IJobPostingRepository>();

            mockRepoJob.Setup(repo => repo.Create(tempjob))
            .ReturnsAsync(tempjob);

            mockRepoJob.Setup(repo => repo.Put(tempjob.Id, tempjob))
            .ReturnsAsync(tempjob);

            KeyPhrasesWrapperDTO temKeyPharse = GetNLTKKeyPhrases(tempjob.Description);

            tempjob.KeyPhrases = new List <KeyPhrase>();
            foreach (KeyPhraseDTO item in temKeyPharse.rank_list)
            {
                tempjob.KeyPhrases.Add(new KeyPhrase
                {
                    Affinty = item.Affinty,
                    Text    = item.Text
                });
            }
            SummaryDTO tempValDTO = GetNLTKSummary(tempjob.Description);

            tempjob.Summary = tempValDTO.SummaryText;

            Mock <IKeyPharseRepository> mockRepoKeyPharse = new Mock <IKeyPharseRepository>();

            Mock <INLTKService> mockNLTKService = new Mock <INLTKService>();

            mockNLTKService.Setup(service => service.GetNLTKKeyPhrases(tempjob.Description))
            .ReturnsAsync(temKeyPharse);

            mockNLTKService.Setup(service => service.GetNLTKSummary(tempjob.Description))
            .ReturnsAsync(tempValDTO);

            JobPostingsController controller = new JobPostingsController(mockRepoJob.Object,
                                                                         mockNLTKService.Object, mockRepoKeyPharse.Object);


            // Act
            IActionResult result = await controller.Create(tempjob);

            // Assert
            RedirectToActionResult redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
Esempio n. 2
0
        public async Task Create_Returns_ValidViewResult_WhenModelStateInvalid()
        {
            // Arrange
            JobPosting tempjob = new JobPosting
            {
                Title         = "Full Stack Developer",
                Company       = "Walmart",
                Description   = "Yolo Lyfe",
                NumberOfViews = 1
            };

            tempjob = CreateJobPostingAsync(tempjob);


            Mock <IJobPostingRepository> mockRepoJob = new Mock <IJobPostingRepository>();

            mockRepoJob.Setup(repo => repo.Create(tempjob))
            .ReturnsAsync(tempjob);

            mockRepoJob.Setup(repo => repo.Put(tempjob.Id, tempjob))
            .ReturnsAsync(tempjob);

            KeyPhrasesWrapperDTO temKeyPharse = GetNLTKKeyPhrases(tempjob.Description);

            tempjob.KeyPhrases = new List <KeyPhrase>();
            foreach (KeyPhraseDTO item in temKeyPharse.rank_list)
            {
                tempjob.KeyPhrases.Add(new KeyPhrase
                {
                    Affinty = item.Affinty,
                    Text    = item.Text
                });
            }
            SummaryDTO tempValDTO = GetNLTKSummary(tempjob.Description);

            tempjob.Summary = tempValDTO.SummaryText;

            Mock <IKeyPharseRepository> mockRepoKeyPharse = new Mock <IKeyPharseRepository>();

            Mock <INLTKService> mockNLTKService = new Mock <INLTKService>();

            mockNLTKService.Setup(service => service.GetNLTKKeyPhrases(tempjob.Description))
            .ReturnsAsync(temKeyPharse);

            mockNLTKService.Setup(service => service.GetNLTKSummary(tempjob.Description))
            .ReturnsAsync(tempValDTO);

            JobPostingsController controller = new JobPostingsController(mockRepoJob.Object,
                                                                         mockNLTKService.Object, mockRepoKeyPharse.Object);

            controller.ModelState.AddModelError("Salary", "no Salary found");

            // Act
            IActionResult result = await controller.Create(tempjob);

            // Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            JobPosting model      = Assert.IsAssignableFrom <JobPosting>(
                viewResult.ViewData.Model);
        }
Esempio n. 3
0
        public async Task Details_Returns_NotFoundResult_WhenOutOfRangeId()
        {
            // Arrange
            int jobId = 1000;
            Mock <IJobPostingRepository> mockRepoJob = new Mock <IJobPostingRepository>();

            mockRepoJob.Setup(repo => repo.GetById(jobId))
            .ReturnsAsync(GetJobPostingById(jobId));

            Mock <IKeyPharseRepository> mockRepoKeyPharse = new Mock <IKeyPharseRepository>();

            Mock <INLTKService> mockNLTKService = new Mock <INLTKService>();

            JobPostingsController controller = new JobPostingsController(mockRepoJob.Object,
                                                                         mockNLTKService.Object, mockRepoKeyPharse.Object);

            // Act
            IActionResult result = await controller.Details(jobId);

            // Assert

            NotFoundResult viewResult = Assert.IsType <NotFoundResult>(result);
        }
Esempio n. 4
0
        public async Task Details_ReturnsAValid_ViewResult_WhenInRangeId()
        {
            // Arrange
            int        jobId   = 1;
            JobPosting tempjob = new JobPosting
            {
                Id            = jobId,
                Title         = "Full Stack Developer",
                Company       = "Walmart",
                NumberOfViews = 1
            };
            Mock <IJobPostingRepository> mockRepoJob = new Mock <IJobPostingRepository>();

            mockRepoJob.Setup(repo => repo.GetById(jobId))
            .ReturnsAsync(tempjob);

            mockRepoJob.Setup(repo => repo.AddView(tempjob))
            .ReturnsAsync(TickNumberOfViewAsync(tempjob));

            Mock <IKeyPharseRepository> mockRepoKeyPharse = new Mock <IKeyPharseRepository>();

            Mock <INLTKService> mockNLTKService = new Mock <INLTKService>();

            JobPostingsController controller = new JobPostingsController(mockRepoJob.Object,
                                                                         mockNLTKService.Object, mockRepoKeyPharse.Object);

            // Act
            IActionResult result = await controller.Details(jobId);

            // Assert
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            JobPosting model      = Assert.IsAssignableFrom <JobPosting>(
                viewResult.ViewData.Model);

            Assert.Equal(2, model.NumberOfViews);
        }