示例#1
0
        public void Save_InvalidUser_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;
            })
                                      );

            _createUserCommand.When(x => x.Execute(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())).Throw(new ValidationException("test"));

            // execute
            var response = browser.Post(Actions.User.Save, (with) =>
            {
                with.HttpRequest();
                with.FormsAuth(currentUser.Id, new Nancy.Authentication.Forms.FormsAuthenticationConfiguration());
                with.FormValue("Password", "password");
                with.FormValue("ConfirmPassword", "password");
            });

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            // check the result
            BasicResult result = JsonConvert.DeserializeObject <BasicResult>(response.Body.AsString());

            Assert.IsFalse(result.Success);
            Assert.AreEqual(1, result.Messages.Length);
            _createUserCommand.Received(1).Execute(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>());
        }
        public void InitialiseAdminUser_AdminUserDoesNotExist_ReturnsNewUser()
        {
            UserModel user = new UserModel();

            user.UserName = UserService.AdminUserName;
            user.Password = UserService.AdminDefaultPassword;
            user.Role     = Roles.Admin;

            _createUserCommand.Execute(user.UserName, user.Password, user.Role).Returns(user);

            // execute
            UserModel result = _userService.InitialiseAdminUser();

            Assert.IsNotNull(result);

            _userRepo.Received(1).GetByUserName(user.UserName);
            _createUserCommand.Received(1).Execute(user.UserName, user.Password, user.Role);
        }