public void ExpenseGroupCreate() { var user = new ExpenseUserVM() { Name = "Test", Email = "*****@*****.**" }; var result = (RedirectToRouteResult)_SystemUnderTest.CreateUser(user); Assert.AreEqual(true, _SystemUnderTest.ModelState.IsValid); _userServiceMock.Verify(m => m.Create(It.IsAny <ExpenseUser>()), Times.Once); }
public void ValidateUserCreate() { var user = new ExpenseUserVM() { Name = "Test" }; _SystemUnderTest.ModelState.AddModelError("Error", "Email is required"); var result = (ViewResult)_SystemUnderTest.CreateUser(user); Assert.AreEqual(false, _SystemUnderTest.ModelState.IsValid); _userServiceMock.Verify(m => m.Create(It.IsAny <ExpenseUser>()), Times.Never); Assert.AreEqual("AddUser", result.ViewName); }
public void InvalidUserCreate() { var user = new ExpenseUserVM() { Name = "Test", Email = "*****@*****.**" }; _SystemUnderTest.ModelState.AddModelError("Error", "Something went wrong"); var result = (ViewResult)_SystemUnderTest.CreateUser(user); Assert.AreEqual(false, _SystemUnderTest.ModelState.IsValid); _userServiceMock.Verify(m => m.Create(It.IsAny <ExpenseUser>()), Times.Never); Assert.AreEqual("AddUser", result.ViewName); }
public ActionResult CreateUser(ExpenseUserVM data) { if (!ModelState.IsValid) { return(View("AddUser", data)); } var userItem = new ExpenseUser { DisplayName = data.Name, Email = data.Email }; _userService.Create(userItem); return(RedirectToAction("Index")); }