public void ShouldCreateCorrectly()
        {
            Mock <IGenericService <Exam> > examServiceMock = new Mock <IGenericService <Exam> >();

            Exam exam = new Exam()
            {
                Id                 = 100,
                AttemptOne         = DateTime.Now.Date,
                AttemptTwo         = DateTime.Now.Date.AddDays(14),
                EC                 = 3,
                Duration           = TimeSpan.FromMinutes(30),
                Compensatable      = true,
                ExamType           = "Vh:essaytoets + vh+att:gedragsassessment + vh:portfolio-assessment + vh:vaardigheidstoets(R)",
                Language           = "NL",
                ResponsibleTeacher = new Teacher()
                {
                    FirstName = "Robin",
                    LastName  = "Schellius"
                },
                Module = new Module()
                {
                    Name = "Client-side web frameworks",
                }
            };

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

            examServiceMock.Setup(m => m.Insert(It.IsAny <Exam>())).Returns((Exam model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.Name) && !string.IsNullOrWhiteSpace(model.Language) && !string.IsNullOrWhiteSpace(model.ResponsibleTeacher?.FullName) && !string.IsNullOrWhiteSpace(model.ExamType) && !string.IsNullOrWhiteSpace(model.Module?.Name))
                {
                    return(1);
                }

                return(0);
            });

            ExamController controller = new ExamController(examServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            RedirectToActionResult result = controller.Create(exam) as RedirectToActionResult;

            Assert.Equal("Index", result?.ActionName);
        }
        public void CannotCreateWithMissingValues()
        {
            Mock <IGenericService <Exam> > examServiceMock = new Mock <IGenericService <Exam> >();

            Exam exam = new Exam()
            {
                Id                 = 100,
                AttemptOne         = DateTime.Now.Date,
                AttemptTwo         = DateTime.Now.Date.AddDays(14),
                EC                 = 3,
                Duration           = TimeSpan.FromMinutes(30),
                Compensatable      = true,
                ExamType           = "Vh:essaytoets + vh+att:gedragsassessment + vh:portfolio-assessment + vh:vaardigheidstoets(R)",
                Language           = "NL",
                ResponsibleTeacher = null,
                Module             = new Module()
                {
                    Name = "Client-side web frameworks",
                }
            };

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

            examServiceMock.Setup(m => m.Insert(It.IsAny <Exam>())).Returns((Exam model) =>
            {
                if (!string.IsNullOrWhiteSpace(model.Name) && !string.IsNullOrWhiteSpace(model.Language) && !string.IsNullOrWhiteSpace(model.ResponsibleTeacher?.FullName) && !string.IsNullOrWhiteSpace(model.ExamType) && !string.IsNullOrWhiteSpace(model.Module?.Name))
                {
                    return(1);
                }

                return(0);
            });

            ExamController controller = new ExamController(examServiceMock.Object)
            {
                ControllerContext = new ControllerContext()
                {
                    HttpContext = new DefaultHttpContext()
                    {
                        User = identity
                    }
                }
            };

            ViewResult result = controller.Create(exam) as ViewResult;

            Assert.NotNull(result);
            Assert.NotNull(result.Model);
            Assert.True(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Edit");
        }
Exemplo n.º 3
0
        public void TestFactory()
        {
            FactoryControllers fc = new FactoryControllers();

            ExamController ExamC = (ExamController)fc.CreateController(ControllersFormat.Exam);

            int count = ExamC.Create(new Exam("History", 0));

            bool actual = false, expected = true;

            if (count > 0)
            {
                actual = true;
            }

            Assert.AreEqual(actual, expected);
        }