public void InitialiseAdminUser_AdminUserExists_ReturnsExistingUser() { UserModel user = DataHelper.CreateUserModel(); user.UserName = UserService.AdminUserName; _userRepo.GetByUserName(UserService.AdminUserName).Returns(user); // execute UserModel result = _userService.InitialiseAdminUser(); Assert.IsNotNull(result); _userRepo.Received(1).GetByUserName(user.UserName); _createUserCommand.DidNotReceive().Execute(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }
public void Save_PasswordsDoNotMatch_ReturnsFailure() { // setup var currentUser = new UserIdentity() { Id = Guid.NewGuid(), UserName = "******" }; currentUser.Claims = new string[] { Claims.UserAdd }; var browser = new Browser((bootstrapper) => bootstrapper.Module(new UserModule(_userRepo, _createUserCommand, _updateUserPasswordCommand, _deleteUserCommand)) .RequestStartup((container, pipelines, context) => { context.CurrentUser = currentUser; }) ); _userValidator.Validate(Arg.Any <UserModel>()).Returns(new ValidationResult()); // execute var response = browser.Post(Actions.User.Save, (with) => { with.HttpRequest(); with.FormsAuth(currentUser.Id, new Nancy.Authentication.Forms.FormsAuthenticationConfiguration()); with.FormValue("ConfirmPassword", Guid.NewGuid().ToString()); }); // assert Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); // check the result BasicResult result = JsonConvert.DeserializeObject <BasicResult>(response.Body.AsString()); Assert.IsFalse(result.Success); Assert.IsTrue(result.Messages[0].Contains("does not match")); _createUserCommand.DidNotReceive().Execute(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()); }