示例#1
0
        public void LoginPost_NoUserName_LoginFailsWithoutCheck()
        {
            // setup
            var browser = CreateBrowser(null);

            //var browser = new Browser(with => with.Module(new LoginModule(_userStore, _passwordProvider)));

            // execute
            var response = browser.Post(Actions.Login.Default, (with) =>
            {
                with.HttpRequest();
                with.FormValue("Password", "password");
            });

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            _passwordProvider.DidNotReceive().CheckPassword(Arg.Any <string>(), Arg.Any <string>());

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

            Assert.IsFalse(result.Success);
        }
        public void Execute_ValidationFails_ThrowsException()
        {
            UserModel model = DataHelper.CreateUserModel();

            _userValidator.Validate(Arg.Any <UserModel>()).Returns(new ValidationResult("error"));

            // execute
            TestDelegate del = () => _createUserCommand.Execute(model.UserName, model.Password, model.Role);

            // assert
            Assert.Throws <ValidationException>(del);

            // we shouldn't have even tried to do the insert
            _dbContext.DidNotReceive().ExecuteNonQuery(Arg.Any <string>(), Arg.Any <object>());
            _passwordProvider.DidNotReceive().HashPassword(Arg.Any <string>(), Arg.Any <string>());
        }