public IActionResult Index(PracticeOptionsModel practiceOptionsModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(practiceOptionsModel));
            }

            switch (practiceOptionsModel.SelectedPracticeOption)
            {
            case "sell_a_practice":
                return(RedirectToAction("Sell", "Practice"));

            case "buy_a_practice":
                return(RedirectToAction("Buy", "Practice"));

            case "post_job_opening":
                return(RedirectToAction("Create", "JobListing"));

            case "look_for_job":
                return(RedirectToAction("Inquire", "JobListing"));

            default:
                return(View(practiceOptionsModel));
            }
        }
        public IActionResult Index(PracticeOptionsModel practiceOptionsModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(Index), practiceOptionsModel));
            }

            switch (practiceOptionsModel.SelectedPracticeOption)
            {
            case "post_job_opening":
                return(RedirectToAction(nameof(Create), "JobListing"));

            case "look_for_job":
                return(RedirectToAction(nameof(Inquire), "JobListing"));

            default: return(View(nameof(Index), practiceOptionsModel));
            }
        }
        public void Index_WhenDoingHttpPostForInvalidAction_ReturnsExpectedView(string action)
        {
            var model = new PracticeOptionsModel
            {
                SelectedPracticeOption = action
            };

            var emailSender = new Mock <ISendEmail>().Object;
            var reCaptcha   = new Mock <IRecaptchaService>().Object;
            var sut         = new HomeController(Enumerable.Empty <IGenerateEmail>(), emailSender, reCaptcha);

            var result = sut.Index(model);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.ViewName);
        }
Ejemplo n.º 4
0
        public IActionResult Index(PracticeOptionsModel practiceOptionsModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(nameof(Index), practiceOptionsModel));
            }

            switch (practiceOptionsModel.SelectedPracticeOption)
            {
            case "sell_a_practice":
                return(RedirectToAction(nameof(Sell), "Practice"));

            case "buy_a_practice":
                return(RedirectToAction(nameof(Buy), "Practice"));

            default: return(View(nameof(Index), practiceOptionsModel));
            }
        }
Ejemplo n.º 5
0
        public void Index_WhenDoingHttpPostForValidActionNotOnIndexController_RedirectsToTheExpectedControllerAndView(string action, string expectedControllerName, string expectedViewName)
        {
            var model = new PracticeOptionsModel
            {
                SelectedPracticeOption = action
            };

            var emailSender = new Mock <ISendEmail>().Object;
            var reCaptcha   = new Mock <IRecaptchaService>().Object;
            var sut         = new PracticeController(Enumerable.Empty <IGenerateEmail>(), emailSender, reCaptcha);

            var result = sut.Index(model);

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

            Assert.Equal(expectedControllerName, redirectToActionResult.ControllerName);
            Assert.Equal(expectedViewName, redirectToActionResult.ActionName);
        }
        public void Index_WhenModelStateIsInvalid_ReturnsExpectedView()
        {
            var model = new PracticeOptionsModel
            {
                SelectedPracticeOption = null
            };

            var emailSender = new Mock <ISendEmail>().Object;
            var reCaptcha   = new Mock <IRecaptchaService>().Object;
            var sut         = new HomeController(Enumerable.Empty <IGenerateEmail>(), emailSender, reCaptcha);

            sut.ModelState.AddModelError("Test", "Model state is invalid.");

            var result = sut.Index(model);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Null(viewResult.ViewName);
        }
        public IActionResult Index()
        {
            var model = new PracticeOptionsModel();

            return(View(nameof(Index), model));
        }