public void CannotEditWithMissingValues()
        {
            Mock <IGenericService <ExamProgram> > examProgramServiceMock = new Mock <IGenericService <ExamProgram> >();

            ExamProgram examProgram = new ExamProgram()
            {
                Id      = 100,
                Courses = null
            };

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

            examProgramServiceMock.Setup(m => m.Update(It.IsAny <ExamProgram>())).Returns((ExamProgram model) =>
            {
                if (model.StartDate != null && model.EndDate != null && model.Courses != null && !string.IsNullOrWhiteSpace(model.Name))
                {
                    return(1);
                }

                return(0);
            });

            ExamProgramController controller = new ExamProgramController(examProgramServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

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

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

            ExamProgram examProgram = new ExamProgram()
            {
                Id        = 100,
                StartDate = DateTime.Now.Date,
                EndDate   = DateTime.Now.Date.AddDays(30)
            };

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

            examProgramServiceMock.Setup(m => m.Update(It.IsAny <ExamProgram>())).Returns((ExamProgram model) =>
            {
                if (model.StartDate != null && model.EndDate != null && model.Courses != null && !string.IsNullOrWhiteSpace(model.Name))
                {
                    return(1);
                }

                return(0);
            });

            ExamProgramController controller = new ExamProgramController(examProgramServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

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

            Assert.Equal("Index", result?.ActionName);
        }