public void Register() { var modelSuccess = new RegisterModel() { DisplayName = "displayname", ConfirmPassword = "******", Password = "******", UserName = "******" }; var modelExists = new RegisterModel() { DisplayName = "displayname_exists", ConfirmPassword = "******", Password = "******", UserName = "******" }; var modelUserNameError = new RegisterModel() { DisplayName = "123", UserName = "******", Password = "******", ConfirmPassword = "******" }; var accountSuccess = new Account() { DisplayName = modelSuccess.DisplayName, Password = modelSuccess.Password, UserName = modelSuccess.UserName }; var accountExists = new Account() { DisplayName = modelExists.DisplayName, Password = modelExists.Password, UserName = modelExists.UserName }; this._usersManageService.Register( Arg.Is<Account>( a => a.DisplayName == accountSuccess.DisplayName && a.Password == accountSuccess.Password && a.UserName == accountSuccess.UserName && a.Id == accountSuccess.Id)) .Returns(EmRegisterStatus.Success); this._usersManageService.Register(Arg.Is<Account>( a => a.DisplayName == accountExists.DisplayName && a.Password == accountExists.Password && a.UserName == accountExists.UserName && a.Id == accountExists.Id)).Returns(EmRegisterStatus.AccountExist); this._controller.WithCallTo(c => c.Register(modelSuccess, "/")).ShouldRedirectTo("/"); this._controller.WithCallTo(c => c.Register(modelExists, "/")).ShouldRenderView("Register"); this._controller.WithModelErrors().WithCallTo(c => c.Register(modelUserNameError, "/")) .ShouldRenderView("Register"); }
public ActionResult Register(RegisterModel model, string next) { if (!ModelState.IsValid) { this.FlashModelStatusError(); return View(); } var status = this.UserService.Register(new Account() { Password = model.Password, UserName = model.UserName, DisplayName = model.DisplayName }); switch (status) { case EmRegisterStatus.AccountExist: { this.Flash(new FlashMsg() { Text = " account existed", Type = emMessageType.Error }); break; } case EmRegisterStatus.SysError: { this.Flash(new FlashMsg() { Text = " system error", Type = emMessageType.Error }); break; } case EmRegisterStatus.Success: { this.Flash(new FlashMsg() { Text = "success, please <a href='" + Url.Action("Login") + "' target='self'>login</a>", Type = emMessageType.Success }); break; } } if (status == EmRegisterStatus.Success) return this.RedirectNext(next); else return View(); }