public void FlashesNoChangesMessage_WhenCommand_ChangedState() { const string principalIdentityName = "*****@*****.**"; const int establishmentId = 8; const string jobTitles = "job titles"; const EmployeeOrStudentAffiliate employeeOrStudentAffiliation = EmployeeOrStudentAffiliate.StudentOnly; const string returnUrl = "http://www.site.tld"; var scenarioOptions = new ScenarioOptions { PrincipalIdentityName = principalIdentityName, }; var model = new UpdateAffiliationForm { JobTitles = jobTitles, EstablishmentId = establishmentId, EmployeeOrStudentAffiliation = employeeOrStudentAffiliation, IsClaimingFaculty = true, ReturnUrl = returnUrl, }; var controller = CreateController(scenarioOptions); scenarioOptions.MockCommandHandler.Setup(m => m.Handle( It.Is(CommandBasedOn(model, principalIdentityName)))); controller.Put(model); controller.TempData.ShouldNotBeNull(); var message = controller.TempData.FeedbackMessage(); message.ShouldNotBeNull(); message.ShouldEqual(UpdateAffiliationController.NoChangesMessage); }
public void ExecutesCommand_WhenAction_IsValid() { const string principalIdentityName = "*****@*****.**"; const int establishmentId = 8; const string jobTitles = "job titles"; const EmployeeOrStudentAffiliate employeeOrStudentAffiliation = EmployeeOrStudentAffiliate.StudentOnly; const string returnUrl = "http://www.site.tld"; var scenarioOptions = new ScenarioOptions { PrincipalIdentityName = principalIdentityName, }; var model = new UpdateAffiliationForm { JobTitles = jobTitles, EstablishmentId = establishmentId, EmployeeOrStudentAffiliation = employeeOrStudentAffiliation, IsClaimingInternationalOffice = true, ReturnUrl = returnUrl, }; var controller = CreateController(scenarioOptions); scenarioOptions.MockCommandHandler.Setup(m => m.Handle( It.Is(CommandBasedOn(model, principalIdentityName)))); controller.Put(model); scenarioOptions.MockCommandHandler.Verify(m => m.Handle(It.Is(CommandBasedOn(model, principalIdentityName))), Times.Once()); }
public void ReturnsRedirect_ToModelReturnUrl_AfterCommandIsExecuted() { const string principalIdentityName = "*****@*****.**"; const int establishmentId = 8; const string jobTitles = "job titles"; const EmployeeOrStudentAffiliate employeeOrStudentAffiliation = EmployeeOrStudentAffiliate.StudentOnly; const string returnUrl = "http://www.site.tld"; var scenarioOptions = new ScenarioOptions { PrincipalIdentityName = principalIdentityName, }; var model = new UpdateAffiliationForm { JobTitles = jobTitles, EstablishmentId = establishmentId, EmployeeOrStudentAffiliation = employeeOrStudentAffiliation, IsClaimingStaff = true, ReturnUrl = returnUrl, }; var controller = CreateController(scenarioOptions); scenarioOptions.MockCommandHandler.Setup(m => m.Handle( It.Is(CommandBasedOn(model, principalIdentityName)))); var result = controller.Put(model); result.ShouldNotBeNull(); result.ShouldBeType <RedirectResult>(); var redirectResult = (RedirectResult)result; redirectResult.Url.ShouldEqual(model.ReturnUrl); redirectResult.Permanent.ShouldBeFalse(); }
public virtual ActionResult Put(UpdateAffiliationForm model) { // make sure model is not null if (model == null) { return(HttpNotFound()); } // make sure model state is valid if (!ModelState.IsValid) { return(View(model)); } // execute command, set feedback message, and redirect var command = Mapper.Map <UpdateMyAffiliationCommand>(model); command.Principal = User; _services.CommandHandler.Handle(command); SetFeedbackMessage(command.ChangedState ? SuccessMessage : NoChangesMessage ); return(Redirect(model.ReturnUrl)); }
public void IsValidWhen_EmployeeOrStudentAffiliation_IsNotEmpty() { var validator = new UpdateAffiliationValidator(); var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = EmployeeOrStudentAffiliate.Neither }; var results = validator.Validate(model); var error = results.Errors.SingleOrDefault(e => e.PropertyName == UpdateAffiliationForm.EmployeeOrStudentAffiliationPropertyName); error.ShouldBeNull(); }
public void IsInvalidWhen_EmployeeOrStudentAffiliation_IsNull() { var validator = new UpdateAffiliationValidator(); var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = null }; var results = validator.Validate(model); results.IsValid.ShouldBeFalse(); results.Errors.Count.ShouldBeInRange(1, int.MaxValue); var error = results.Errors.SingleOrDefault(e => e.PropertyName == UpdateAffiliationForm.EmployeeOrStudentAffiliationPropertyName); error.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException error.ErrorMessage.ShouldEqual( UpdateAffiliationValidator.FailedBecauseEmployeeOrStudentAffiliationWasEmpty); // ReSharper restore PossibleNullReferenceException }
public void ReturnsView_WhenModelState_IsInvalid() { var scenarioOptions = new ScenarioOptions(); var model = new UpdateAffiliationForm(); var controller = CreateController(scenarioOptions); controller.ModelState.AddModelError("error", "message"); var result = controller.Put(model); result.ShouldNotBeNull(); result.ShouldBeType <ViewResult>(); var viewResult = (ViewResult)result; viewResult.Model.ShouldNotBeNull(); viewResult.Model.ShouldBeType <UpdateAffiliationForm>(); viewResult.Model.ShouldEqual(model); }
//[OpenTopTab(TopTabName.Home)] //[ActionName("update-affiliation")] public virtual ActionResult Put(UpdateAffiliationForm model) { // make sure model is not null if (model == null) return HttpNotFound(); // make sure model state is valid if (!ModelState.IsValid) return View(MVC.IdentityDeprecated.Shared.Views.update_affiliation, model); // execute command, set feedback message, and redirect var command = Mapper.Map<UpdateMyAffiliation>(model); command.Principal = User; _services.CommandHandler.Handle(command); //SetFeedbackMessage(command.ChangedState // ? SuccessMessage // : NoChangesMessage //); return Redirect(model.ReturnUrl); }
public void MapsIsClaimingEmployee_ToFalse_WhenEmployeeOrStudentAffiliation_IsNeither() { var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = EmployeeOrStudentAffiliate.Neither }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.IsClaimingEmployee.ShouldBeFalse(); }
public void IgnoresChangeCount() { var model = new UpdateAffiliationForm(); var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.ChangeCount.ShouldEqual(0); }
public void MapsIsClaimingStaff() { var model = new UpdateAffiliationForm { IsClaimingStaff = true }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.IsClaimingStaff.ShouldEqual(model.IsClaimingStaff); }
public void IsTrue_WhenEmployeeOrStudentAffiliation_IsEmployeeOnly() { var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = EmployeeOrStudentAffiliate.StudentOnly }; model.IsClaimingStudent.ShouldBeTrue(); }
public void IsFalse_WhenEmployeeOrStudentAffiliation_IsNeither() { var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = EmployeeOrStudentAffiliate.Neither }; model.IsClaimingEmployee.ShouldBeFalse(); }
private static Expression<Func<UpdateMyAffiliationCommand, bool>> CommandBasedOn(UpdateAffiliationForm model, string principalIdentityName) { Expression<Func<UpdateMyAffiliationCommand, bool>> commandBasedOn = command => command.Principal.Identity.Name == principalIdentityName && command.EstablishmentId == model.EstablishmentId && command.JobTitles == model.JobTitles && command.IsClaimingStudent == model.IsClaimingStudent && command.IsClaimingEmployee == model.IsClaimingEmployee && command.IsClaimingInternationalOffice == model.IsClaimingInternationalOffice && command.IsClaimingAdministrator == model.IsClaimingAdministrator && command.IsClaimingFaculty == model.IsClaimingFaculty && command.IsClaimingStaff == model.IsClaimingStaff ; return commandBasedOn; }
public void ReturnsView_WhenModelState_IsInvalid() { var scenarioOptions = new ScenarioOptions(); var model = new UpdateAffiliationForm(); var controller = CreateController(scenarioOptions); controller.ModelState.AddModelError("error", "message"); var result = controller.Put(model); result.ShouldNotBeNull(); result.ShouldBeType<ViewResult>(); var viewResult = (ViewResult)result; viewResult.Model.ShouldNotBeNull(); viewResult.Model.ShouldBeType<UpdateAffiliationForm>(); viewResult.Model.ShouldEqual(model); }
private static Expression <Func <UpdateMyAffiliationCommand, bool> > CommandBasedOn(UpdateAffiliationForm model, string principalIdentityName) { Expression <Func <UpdateMyAffiliationCommand, bool> > commandBasedOn = command => command.Principal.Identity.Name == principalIdentityName && command.EstablishmentId == model.EstablishmentId && command.JobTitles == model.JobTitles && command.IsClaimingStudent == model.IsClaimingStudent && command.IsClaimingEmployee == model.IsClaimingEmployee && command.IsClaimingInternationalOffice == model.IsClaimingInternationalOffice && command.IsClaimingAdministrator == model.IsClaimingAdministrator && command.IsClaimingFaculty == model.IsClaimingFaculty && command.IsClaimingStaff == model.IsClaimingStaff ; return(commandBasedOn); }
public void MapsIsClaimingEmployee_ToTrue_WhenEmployeeOrStudentAffiliation_IsBoth() { var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = EmployeeOrStudentAffiliate.Both }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.IsClaimingEmployee.ShouldBeTrue(); }
public void ReturnsRedirect_ToModelReturnUrl_AfterCommandIsExecuted() { const string principalIdentityName = "*****@*****.**"; const int establishmentId = 8; const string jobTitles = "job titles"; const EmployeeOrStudentAffiliate employeeOrStudentAffiliation = EmployeeOrStudentAffiliate.StudentOnly; const string returnUrl = "http://www.site.tld"; var scenarioOptions = new ScenarioOptions { PrincipalIdentityName = principalIdentityName, }; var model = new UpdateAffiliationForm { JobTitles = jobTitles, EstablishmentId = establishmentId, EmployeeOrStudentAffiliation = employeeOrStudentAffiliation, IsClaimingStaff = true, ReturnUrl = returnUrl, }; var controller = CreateController(scenarioOptions); scenarioOptions.MockCommandHandler.Setup(m => m.Handle( It.Is(CommandBasedOn(model, principalIdentityName)))); var result = controller.Put(model); result.ShouldNotBeNull(); result.ShouldBeType<RedirectResult>(); var redirectResult = (RedirectResult)result; redirectResult.Url.ShouldEqual(model.ReturnUrl); redirectResult.Permanent.ShouldBeFalse(); }
public void MapsEstablishmentId() { var model = new UpdateAffiliationForm { EstablishmentId = 96 }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.EstablishmentId.ShouldEqual(model.EstablishmentId); }
public void IsTrue_WhenEmployeeOrStudentAffiliation_IsBoth() { var model = new UpdateAffiliationForm {EmployeeOrStudentAffiliation = EmployeeOrStudentAffiliate.Both}; model.IsClaimingEmployee.ShouldBeTrue(); }
public void MapsJobTitles() { var model = new UpdateAffiliationForm { JobTitles = "test" }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.JobTitles.ShouldEqual(model.JobTitles); }
public void Implements_IReturnUrl() { var model = new UpdateAffiliationForm(); model.ShouldImplement<IReturnUrl>(); }
public void MapsIsClaimingInternationalOffice() { var model = new UpdateAffiliationForm { IsClaimingInternationalOffice = true }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.IsClaimingInternationalOffice.ShouldEqual(model.IsClaimingInternationalOffice); }
public void IsFalse_WhenEmployeeOrStudentAffiliation_IsNull() { var model = new UpdateAffiliationForm { EmployeeOrStudentAffiliation = null }; model.IsClaimingStudent.ShouldBeFalse(); }
public void MapsIsClaimingAdministrator() { var model = new UpdateAffiliationForm { IsClaimingAdministrator = true }; var command = Mapper.Map<UpdateMyAffiliationCommand>(model); command.ShouldNotBeNull(); command.IsClaimingAdministrator.ShouldEqual(model.IsClaimingAdministrator); }