public void Unapproved_member_sends_approve_member_email() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns(_currentMember.Object); _currentMember.SetupGet(x => x.IsApproved).Returns(false); _tokenReader.Setup(x => x.TokenFor(_currentMember.Object.Id)).Returns((_token, _expiryDate)); _emailFormatter.Setup(x => x.FormatEmailContent(APPROVE_MEMBER_SUBJECT, APPROVE_MEMBER_BODY, It.IsAny <Dictionary <string, string> >())) .Callback <string, string, Dictionary <string, string> >((subject, body, tokens) => { Assert.Equal(_currentMember.Object.Name, tokens["name"]); Assert.Equal(formData.Email, tokens["email"]); Assert.Equal(_token, tokens["token"]); Assert.Equal(REQUEST_URL_AUTHORITY, tokens["domain"]); }) .Returns((APPROVE_MEMBER_SUBJECT, APPROVE_MEMBER_BODY)); controller.RequestPasswordReset(formData); _emailSender.Verify(x => x.SendEmail(formData.Email, APPROVE_MEMBER_SUBJECT, APPROVE_MEMBER_BODY), Times.Once); } }
public void Valid_email_passes_validation() { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; Assert.DoesNotContain(ValidateModel(formData), v => v.MemberNames.Contains(nameof(ResetPasswordRequestFormData.Email)) && v.ErrorMessage.ToUpperInvariant().Contains("EMAIL")); }
public void Invalid_email_address_fails_validation(string email) { var formData = new ResetPasswordRequestFormData { Email = email }; Assert.Contains(ValidateModel(formData), v => v.MemberNames.Contains(nameof(ResetPasswordRequestFormData.Email)) && v.ErrorMessage.ToUpperInvariant().Contains("EMAIL")); }
public void Unapproved_member_request_is_logged() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns(_currentMember.Object); _currentMember.SetupGet(x => x.IsApproved).Returns(false); controller.RequestPasswordReset(formData); _logger.Verify(x => x.Info(typeof(ResetPasswordRequestSurfaceController), LoggingTemplates.MemberPasswordResetRequested, _currentMember.Object.Username, _currentMember.Object.Key, typeof(ResetPasswordRequestSurfaceController), nameof(ResetPasswordRequestSurfaceController.RequestPasswordReset)), Times.Once); } }
public void Member_not_found_does_not_save() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns((IMember)null); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); MemberService.Verify(x => x.Save(_currentMember.Object, true), Times.Never); } }
public void Member_not_found_returns_ResetPasswordRequest_view() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns((IMember)null); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); Assert.Equal("ResetPasswordRequest", ((ViewResult)result).ViewName); } }
public void Member_not_found_returns_ResetPassword_ModelsBuilder_model() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns((IMember)null); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); Assert.IsType <ResetPassword>(((ViewResult)result).Model); } }
public void Member_not_found_sets_email_from_form_data_and_displays_confirmation() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns((IMember)null); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); Assert.True((((ViewResult)result).Model as ResetPassword)?.ShowPasswordResetRequested); Assert.Equal("*****@*****.**", (((ViewResult)result).Model as ResetPassword)?.Email); } }
public void Approved_member_returns_ResetPassword_ModelsBuilder_model() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns(_currentMember.Object); _currentMember.SetupGet(x => x.IsApproved).Returns(true); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); Assert.IsType <ResetPassword>(((ViewResult)result).Model); } }
public void Unapproved_member_returns_ResetPasswordRequest_view() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns(_currentMember.Object); _currentMember.SetupGet(x => x.IsApproved).Returns(false); _tokenReader.Setup(x => x.TokenFor(_currentMember.Object.Id)).Returns((_token, _expiryDate)); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); Assert.Equal("ResetPasswordRequest", ((ViewResult)result).ViewName); } }
public void Unapproved_member_sets_email_from_form_data_and_displays_confirmation() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns(_currentMember.Object); _currentMember.SetupGet(x => x.IsApproved).Returns(false); var result = controller.RequestPasswordReset(new ResetPasswordRequestFormData { Email = "*****@*****.**" }); Assert.True((((ViewResult)result).Model as ResetPassword)?.ShowPasswordResetRequested); Assert.Equal("*****@*****.**", (((ViewResult)result).Model as ResetPassword)?.Email); } }
public void Unapproved_member_saves_approval_token() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns(_currentMember.Object); _currentMember.SetupGet(x => x.IsApproved).Returns(false); _tokenReader.Setup(x => x.TokenFor(_currentMember.Object.Id)).Returns((_token, _expiryDate)); controller.RequestPasswordReset(formData); _currentMember.Verify(x => x.SetValue("approvalToken", _token, null, null), Times.Once); _currentMember.Verify(x => x.SetValue("approvalTokenExpires", _expiryDate, null, null), Times.Once); MemberService.Verify(x => x.Save(_currentMember.Object, true), Times.Once); } }
public void Member_not_found_sends_create_member_email() { using (var controller = CreateController()) { var formData = new ResetPasswordRequestFormData { Email = "*****@*****.**" }; MemberService.Setup(x => x.GetByEmail(formData.Email)).Returns((IMember)null); _emailFormatter.Setup(x => x.FormatEmailContent(CREATE_MEMBER_SUBJECT, CREATE_MEMBER_BODY, It.IsAny <Dictionary <string, string> >())) .Callback <string, string, Dictionary <string, string> >((subject, body, tokens) => { Assert.Equal(formData.Email, tokens["email"]); Assert.Equal(REQUEST_URL_AUTHORITY, tokens["domain"]); }) .Returns((CREATE_MEMBER_SUBJECT, CREATE_MEMBER_BODY)); controller.RequestPasswordReset(formData); _emailSender.Verify(x => x.SendEmail(formData.Email, CREATE_MEMBER_SUBJECT, CREATE_MEMBER_BODY), Times.Once); } }
public override void Execute() { #line 6 "..\..\Views\ResetPasswordRequest.cshtml" Html.EnableClientValidation(); Html.EnableUnobtrusiveJavaScript(); Html.RequiresJs("~/scripts/jquery.validate.min.js"); Html.RequiresJs("~/scripts/jquery.validate.unobtrusive.min.js"); #line default #line hidden WriteLiteral("\r\n<div"); WriteLiteral(" class=\"container-xl\""); WriteLiteral(">\r\n <h1>"); #line 13 "..\..\Views\ResetPasswordRequest.cshtml" Write(Model.Name); #line default #line hidden WriteLiteral("</h1>\r\n\r\n"); #line 15 "..\..\Views\ResetPasswordRequest.cshtml" #line default #line hidden #line 15 "..\..\Views\ResetPasswordRequest.cshtml" if (User.Identity.IsAuthenticated) { #line default #line hidden #line 17 "..\..\Views\ResetPasswordRequest.cshtml" Write(Html.Partial("_Logout")); #line default #line hidden #line 17 "..\..\Views\ResetPasswordRequest.cshtml" } else { if (!Model.ShowPasswordResetRequested) { #line default #line hidden #line 23 "..\..\Views\ResetPasswordRequest.cshtml" using (Html.BeginUmbracoForm <ResetPasswordRequestSurfaceController>("RequestPasswordReset")) { #line default #line hidden #line 26 "..\..\Views\ResetPasswordRequest.cshtml" Write(Html.AntiForgeryToken()); #line default #line hidden #line 26 "..\..\Views\ResetPasswordRequest.cshtml" var resetPasswordRequest = new ResetPasswordRequestFormData(); #line default #line hidden WriteLiteral(" <div"); WriteLiteral(" class=\"form-group\""); WriteLiteral(">\r\n"); WriteLiteral(" "); #line 30 "..\..\Views\ResetPasswordRequest.cshtml" Write(Html.LabelFor(m => resetPasswordRequest.Email, "Email")); #line default #line hidden WriteLiteral("\r\n"); WriteLiteral(" "); #line 31 "..\..\Views\ResetPasswordRequest.cshtml" Write(Html.TextBoxFor(m => resetPasswordRequest.Email, new { @class = "form-control", type = "email", required = "required", aria_describedby = "form-email", autocorrect = "off", autocapitalize = "off" })); #line default #line hidden WriteLiteral("\r\n"); WriteLiteral(" "); #line 32 "..\..\Views\ResetPasswordRequest.cshtml" Write(Html.ValidationMessageFor(m => resetPasswordRequest.Email, null, new { id = "form-email" })); #line default #line hidden WriteLiteral("\r\n </div>\r\n"); WriteLiteral(" <button"); WriteLiteral(" class=\"btn btn-primary\""); WriteLiteral(">"); #line 34 "..\..\Views\ResetPasswordRequest.cshtml" Write(Model.ResetPasswordButton); #line default #line hidden WriteLiteral("</button>\r\n"); #line 35 "..\..\Views\ResetPasswordRequest.cshtml" } } else { #line default #line hidden #line 39 "..\..\Views\ResetPasswordRequest.cshtml" #line default #line hidden #line 40 "..\..\Views\ResetPasswordRequest.cshtml" Write(Html.ProtectEmailAddresses(Model.PasswordResetRequested.ToString(), Model.Email?.ToString())); #line default #line hidden #line 40 "..\..\Views\ResetPasswordRequest.cshtml" } } #line default #line hidden WriteLiteral("</div>"); }