There is an action method that registers the user. In order not to clutter up the model, the password confirmation was issued as a separate field in the view. As a result, I get this value through Request.Form["Повторите пароль"]
Part of the action method:
if (user.Password == Request.Form["Повторите пароль"] && ModelState.IsValid) { TempData["Message"] = "Регистрация прошла успешно! Можете логиниться"; repository.Add_New_User(user); return Redirect("/Account/Login"); } And so I began to write a test and how do I set this Request.Form :
[TestMethod] public void Registr_Error( { User testUser = new User() { LoginUser = "IlyaLogin", Password = "IlyaPassword" }; Mock<IUsersRepository> mock = new Mock<IUsersRepository>(); mock.Setup(m => m.Users).Returns(new User[] { new User { LoginUser = "Vova", Password="123123"}, testUser }.AsQueryable()); AccountController target = new AccountController(mock.Object, null); ViewResult result = (ViewResult)target.Registr(testUser, null); Assert.AreEqual("Registr", result.ViewName); Assert.IsFalse(result.ViewData.ModelState.IsValid); }