コード例 #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>());
        }