public void IndexGetSessionTests(ContactOption contactOption, ContactOption contactOptionProperty, bool redirectExpected) { // Assign var controller = new YourDetailsController(fakeApplicationLogger, fakeSendEmailService, fakeAsyncHelper, fakeContext, fakeSessionStorage) { ContactOption = contactOptionProperty, PageTitle = nameof(YourDetailsController.PageTitle), AdviserIntroductionTwo = nameof(YourDetailsController.AdviserIntroductionTwo), AdviserIntroduction = nameof(YourDetailsController.AdviserIntroduction), NonAdviserIntroduction = nameof(YourDetailsController.NonAdviserIntroduction), DateOfBirthHint = nameof(YourDetailsController.DateOfBirthHint), PostcodeHint = nameof(YourDetailsController.PostcodeHint), SuccessPage = nameof(YourDetailsController.SuccessPage), DoYouWantUsToContactUsText = nameof(YourDetailsController.DoYouWantUsToContactUsText), TermsAndConditionsText = nameof(YourDetailsController.TermsAndConditionsText), TemplateName = nameof(YourDetailsController.TemplateName) }; var sessionObject = GetSessionObject(contactOption); A.CallTo(() => fakeSessionStorage.Get()).Returns(sessionObject); // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index()); // Assert if (redirectExpected) { controllerResult.ShouldRedirectTo(controller.ContactOptionPage); } else { AssertIndexGetViews(contactOption, controllerResult, controller); } }
private static void AssertIndexGetViews(ContactOption contactOption, ControllerResultTest <YourDetailsController> controllerResult, YourDetailsController controller) { if (contactOption == ContactOption.ContactAdviser) { controllerResult.ShouldRenderView("ContactAdvisor") .WithModel <ContactUsWithDobPostcodeViewModel>(vm => { vm.PageTitle.Should().BeEquivalentTo(controller.PageTitle); vm.PageIntroduction.Should().BeEquivalentTo(controller.AdviserIntroduction); vm.PageIntroductionTwo.Should().BeEquivalentTo(controller.AdviserIntroductionTwo); vm.PostcodeHint.Should().BeEquivalentTo(controller.PostcodeHint); vm.DateOfBirthHint.Should().BeEquivalentTo(controller.DateOfBirthHint); vm.TermsAndConditionsText.Should().BeEquivalentTo(controller.TermsAndConditionsText); }); } else { controllerResult.ShouldRenderView("Feedback") .WithModel <ContactUsWithConsentViewModel>(vm => { vm.PageTitle.Should().BeEquivalentTo(controller.PageTitle); vm.DoYouWantUsToContactUsText.Should().BeEquivalentTo(controller.DoYouWantUsToContactUsText); vm.PageIntroduction.Should().BeEquivalentTo(controller.NonAdviserIntroduction); vm.TermsAndConditionsText.Should().BeEquivalentTo(controller.TermsAndConditionsText); }); } }
public void IndexGetTest(ContactOption contactOption, bool validSessionVm) { var controller = new YourDetailsController(fakeApplicationLogger, fakeSendEmailService, fakeAsyncHelper, fakeContext, fakeSessionStorage) { ContactOption = contactOption, PageTitle = nameof(YourDetailsController.PageTitle), AdviserIntroductionTwo = nameof(YourDetailsController.AdviserIntroductionTwo), AdviserIntroduction = nameof(YourDetailsController.AdviserIntroduction), NonAdviserIntroduction = nameof(YourDetailsController.NonAdviserIntroduction), DateOfBirthHint = nameof(YourDetailsController.DateOfBirthHint), PostcodeHint = nameof(YourDetailsController.PostcodeHint), SuccessPage = nameof(YourDetailsController.SuccessPage), DoYouWantUsToContactUsText = nameof(YourDetailsController.DoYouWantUsToContactUsText), TermsAndConditionsText = nameof(YourDetailsController.TermsAndConditionsText), TemplateName = nameof(YourDetailsController.TemplateName) }; if (!validSessionVm) { A.CallTo(() => fakeSessionStorage.Get()).Returns(null); } else { A.CallTo(() => fakeSessionStorage.Get()).Returns(new ContactUs { ContactUsOption = new ContactUsOption { ContactOptionType = contactOption }, ContactAnAdviserFeedback = new ContactAnAdviserFeedback(), GeneralFeedback = new GeneralFeedback(), TechnicalFeedback = new TechnicalFeedback() }); } //Act var controllerResult = controller.WithCallTo(contrl => contrl.Index()); //Assert if (validSessionVm) { AssertIndexGetViews(contactOption, controllerResult, controller); } else { controllerResult.ShouldRedirectTo(controller.ContactOptionPage); } }
private static ContactUs GetSessionObject(ContactOption contactOption) { var sessionObject = new ContactUs { ContactUsOption = new ContactUsOption { ContactOptionType = contactOption }, ContactAnAdviserFeedback = contactOption == ContactOption.ContactAdviser ? new ContactAnAdviserFeedback { Message = nameof(ContactAnAdviserFeedback.Message) } : null, GeneralFeedback = contactOption == ContactOption.Feedback ? new GeneralFeedback { Feedback = nameof(GeneralFeedback.Feedback) } : null, TechnicalFeedback = contactOption == ContactOption.Technical ? new TechnicalFeedback { Message = nameof(TechnicalFeedback.Message) } : null }; return(sessionObject); }
public void SubmitTests(bool modelStateValid, bool validSubmission, bool validSession, ContactOption contactOption) { //Assign var postModel = new ContactUsWithConsentViewModel(); A.CallTo(() => fakeSendEmailService.SendEmailAsync(A <ContactUsRequest> ._)).Returns(validSubmission); A.CallTo(() => fakeSessionStorage.Get()).Returns(validSession ? GetSessionObject(contactOption) : null); A.CallTo(() => fakeSessionStorage.Remove()).DoesNothing(); var controller = new YourDetailsController(fakeApplicationLogger, fakeSendEmailService, fakeAsyncHelper, fakeContext, fakeSessionStorage) { SuccessPage = nameof(YourDetailsController.SuccessPage), FailurePage = nameof(YourDetailsController.FailurePage), ContactOption = contactOption }; if (!modelStateValid) { controller.ModelState.AddModelError(nameof(ContactUsWithDobPostcodeViewModel.Firstname), nameof(ContactUsWithDobPostcodeViewModel.Firstname)); } //Act var controllerResult = controller.WithCallTo(contrl => contrl.Submit(postModel)); //Assert if (modelStateValid) { if (validSession) { A.CallTo(() => fakeSessionStorage.Get()).MustHaveHappened(2, Times.Exactly); A.CallTo(() => fakeSessionStorage.Remove()).MustHaveHappened(); A.CallTo(() => fakeSendEmailService.SendEmailAsync(A <ContactUsRequest> ._)).MustHaveHappened(); if (validSubmission) { controllerResult.ShouldRedirectTo(controller.SuccessPage); } else { controllerResult.ShouldRedirectTo(controller.FailurePage); } } else { A.CallTo(() => fakeSessionStorage.Get()).MustHaveHappened(1, Times.Exactly); controllerResult.ShouldRedirectTo(controller.ContactOptionPage); } } else { controllerResult.ShouldRenderView("Feedback") .WithModel <ContactUsWithConsentViewModel>() .AndModelErrorFor(model => model.Firstname); } }
/// <summary> /// Initializes a new instance of the <see cref="InviteSupportModel" /> class. /// </summary> /// <param name="services">services.</param> /// <param name="issueType">issueType.</param> /// <param name="severity">severity.</param> /// <param name="detail">detail.</param> /// <param name="relatedServiceName">relatedServiceName.</param> /// <param name="fileName">fileName.</param> /// <param name="contactName">contactName.</param> /// <param name="contactOption">contactOption.</param> /// <param name="contactDetail">contactDetail.</param> /// <param name="contactCC">contactCC.</param> public InviteSupportModel(List <ApiFeedbackServiceType> services = default(List <ApiFeedbackServiceType>), IssueType issueType = default(IssueType), Severity severity = default(Severity), string detail = default(string), string relatedServiceName = default(string), string fileName = default(string), string contactName = default(string), ContactOption contactOption = default(ContactOption), string contactDetail = default(string), string contactCC = default(string)) { this.Services = services; this.IssueType = issueType; this.Severity = severity; this.Detail = detail; this.RelatedServiceName = relatedServiceName; this.FileName = fileName; this.ContactName = contactName; this.ContactOption = contactOption; this.ContactDetail = contactDetail; this.ContactCC = contactCC; }