Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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"));
        }