public void IndexGetTest(string title, string generalFeedbackPage, string technicalFeedbackPage, string contactAdviserPage) { var mapperCfg = new MapperConfiguration(cfg => { cfg.AddProfile <ContactUsAutomapperProfile>(); }); //Assign var controller = new SelectOptionController(fakeApplicationLogger, mapperCfg.CreateMapper(), fakeSessionStorage) { Title = title, ContactAdviserPage = contactAdviserPage, TechnicalFeedbackPage = technicalFeedbackPage, GeneralFeedbackPage = generalFeedbackPage }; //Act var controllerResult = controller.WithCallTo(contrl => contrl.Index()); //Assert controllerResult.ShouldRenderDefaultView().WithModel <ContactOptionsViewModel>( vm => { vm.Title.Should().BeEquivalentTo(controller.Title); }); }
public void SubmitTests(bool modelStateValid, ContactOption?contactOption) { //Assign var postModel = new ContactOptionsViewModel(); //Setup and configure fake mapper var mapperCfg = new MapperConfiguration(cfg => { cfg.AddProfile <ContactUsAutomapperProfile>(); }); var controller = new SelectOptionController(fakeApplicationLogger, mapperCfg.CreateMapper(), fakeSessionStorage); A.CallTo(() => fakeSessionStorage.Save(A <ContactUs> ._)).DoesNothing(); if (!modelStateValid) { controller.ModelState.AddModelError(nameof(ContactOptionsViewModel.ContactOptionType), nameof(ContactOptionsViewModel.ContactOptionType)); } if (contactOption != null) { postModel.ContactOptionType = contactOption.GetValueOrDefault(); } //Act var controllerResult = controller.WithCallTo(contrl => contrl.Index(postModel)); //Assert if (modelStateValid && contactOption == ContactOption.ContactAdviser) { controllerResult.ShouldRedirectTo(controller.ContactAdviserPage); } else if (modelStateValid && contactOption == ContactOption.Technical) { controllerResult.ShouldRedirectTo(controller.TechnicalFeedbackPage); } else if (modelStateValid && contactOption == ContactOption.Feedback) { controllerResult.ShouldRedirectTo(controller.GeneralFeedbackPage); } else if (modelStateValid && contactOption == null) { controllerResult.ShouldRenderDefaultView().WithModel <ContactOptionsViewModel>(); } else { controllerResult.ShouldRenderDefaultView() .WithModel <ContactOptionsViewModel>() .AndModelError(nameof(ContactOptionsViewModel.ContactOptionType)); } }