public void CannotEditWithMissingValues()
        {
            Mock <IGenericService <Teacher> > teacherServiceMock = new Mock <IGenericService <Teacher> >();

            Teacher teacher = new Teacher()
            {
                Id                    = 100,
                FirstName             = "Robin",
                LastName              = "Schellius",
                ResponsibleForCourses = null
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            teacherServiceMock.Setup(m => m.Update(It.IsAny <Teacher>())).Returns((Teacher model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.FullName) && model.ResponsibleForCourses != null)
                {
                    return(1);
                }

                return(0);
            });

            TeacherController controller = new TeacherController(teacherServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            ViewResult result = controller.Edit(teacher) as ViewResult;

            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.True(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Edit");
        }
        public void ShouldEditCorrectly()
        {
            Mock <IGenericService <Teacher> > teacherServiceMock = new Mock <IGenericService <Teacher> >();

            Teacher teacher = new Teacher()
            {
                Id        = 100,
                FirstName = "Robin",
                LastName  = "Schellius"
            };

            ClaimsPrincipal identity = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, "123")
            }));

            teacherServiceMock.Setup(m => m.Update(It.IsAny <Teacher>())).Returns((Teacher model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.FullName))
                {
                    return(1);
                }

                return(0);
            });

            TeacherController controller = new TeacherController(teacherServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            RedirectToActionResult result = controller.Edit(teacher) as RedirectToActionResult;

            Assert.Equal("Index", result?.ActionName);
        }
        public async void EditWhenIdIsNull_ReturnsNotFound()
        {
            var result = await systemUnderTest.Edit(null);

            Assert.IsType <NotFoundResult>(result);
        }