public void DetailsCanBeUpdatedThroughViewModel()
        {
            DbContextOptions <Lab13StudentEnrollmentDbContext> options =
                new DbContextOptionsBuilder <Lab13StudentEnrollmentDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (Lab13StudentEnrollmentDbContext context = new Lab13StudentEnrollmentDbContext(options))
            {
                Student student = new Student();
                student.Name     = "Bob";
                student.Age      = 24;
                student.CourseID = "cs201";

                StudentsController sc = new StudentsController(context);
                var x        = sc.Create(student);
                var retrieve = context.Students.Where(s => s.Name == "Bob").ToList();

                ViewResult current           = (ViewResult)sc.Details(retrieve[0].ID).Result;
                StudentDetailsViewModel test = (StudentDetailsViewModel)current.Model;

                Assert.Equal("Bob", test.Student.Name);
                student.Name = "Joe";
                x            = sc.Update(1, student);

                retrieve = context.Students.Where(s => s.Name == "Joe").ToList();
                ViewResult update = (ViewResult)sc.Details(retrieve[0].ID).Result;
                test = (StudentDetailsViewModel)update.Model;

                Assert.Equal("Joe", test.Student.Name);
            }
        }
Esempio n. 2
0
        public async Task Details_ReturnsAViewResult_WithStudentModel(int id, string lastName)
        {
            var result = await sut.Details(id);

            var model = (Student)((ViewResult)result).Model;

            Assert.Equal(lastName, model.LastName);
        }
Esempio n. 3
0
        public void DetailsValidStudentId()
        {
            //act
            var actual = (Student)((ViewResult)controller.Details(1)).Model;

            //assert
            Assert.AreEqual(students[0], actual);
        }
Esempio n. 4
0
        public void Students_Controller_Test_On_Details_With_Existent_Id()
        {
            //Arrange
            Guid   id          = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            string firstName   = "TestF";
            string lastName    = "TestL";
            string userName    = "******";
            string password    = "******";
            string emailAdress = "TestE";

            Student expectedStudent = new Student(firstName, lastName, userName, password, emailAdress);

            expectedStudent.Id = id;

            var repo = Substitute.For <IRepository>();
            var sut  = new StudentsController(repo);

            repo.GetById <Student>(id).Returns(expectedStudent);
            //Act
            var actual = sut.Details(id).Result as ViewResult;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
            var viewResult = actual;

            Assert.AreEqual(expectedStudent, viewResult.Model);
        }
        public void TestDetails()
        {
            var obj    = new StudentsController();
            var result = obj.Details(1) as ViewResult;

            Assert.IsNotNull(result);
        }
        public void TestDetailsViewFail()
        {
            var controller = new StudentsController();
            var result     = controller.Details(-1) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsNull(result.Model);
        }
        public void TestDetailsView()
        {
            var controller = new StudentsController();
            var result     = controller.Details(2) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(2, ((Student)result.Model).Id);
        }
        public void Details()
        {
            var student = new Student()
            {
                StudentID = 1, RefNo = "12456343", FirstName = "John", LastName = "Smith", DateOfBirth = DateTime.Now.AddYears(-10), DateCreated = DateTime.Now
            };

            _studentService.Setup(s => s.GetDetail(1)).Returns(student);

            ViewResult vr = _controller.Details(1, "test") as ViewResult;

            Assert.NotNull(vr);

            var model = vr.Model as Student;

            Assert.Equal(1, model.StudentID);
            Assert.Equal("Johntest", model.FirstName);

            _studentService.Verify();
        }
Esempio n. 9
0
        public async Task Details_ReturnsNotFoundWithNullId()
        {
            //Arrange
            var studentsRepositoryMock = new Mock <IStudentsRepository>();
            var controller             = new StudentsController(studentsRepositoryMock.Object);

            // Act
            IActionResult actionResult = await controller.Details(null);

            //assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
Esempio n. 10
0
        public void Details()
        {
            // Arrange
            var context                = new SkolaDBContext();
            var controller             = new StudentsController(context);
            var expectedBadRequestCode = 400;
            int?idNull = null;
            var expectedNotFoundCode = 404;
            int?idWrong = -1;

            // Act
            var resultResponseBadRequest = controller.Details(idNull) as HttpStatusCodeResult;
            var resultResponseNotFound   = controller.Details(idWrong) as HttpStatusCodeResult;
            var actualBadRequestCode     = (resultResponseBadRequest == null)? -1: resultResponseBadRequest.StatusCode;
            var actualNotFoundCode       = (resultResponseNotFound == null) ? -1 : resultResponseNotFound.StatusCode;

            // Assert
            Assert.AreEqual(expectedBadRequestCode, actualBadRequestCode);

            Assert.AreEqual(expectedNotFoundCode, actualNotFoundCode);
        }
Esempio n. 11
0
        public async Task Details_ReturnsNotFoundWithId()
        {
            //Arrange
            var studentsRepositoryMock = new Mock <IStudentsRepository>();

            studentsRepositoryMock.Setup(repo => repo.Find(2)).Returns(Task.FromResult <Student>(null));
            var controller = new StudentsController(studentsRepositoryMock.Object);

            // Act
            IActionResult actionResult = await controller.Details(2);


            //assert
            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
        public async Task Details_ReturnsStudentIn()
        {
            //Arrange
            var controller = new StudentsController(_studentRepository);

            // Act
            var viewResult = await controller.Details(2) as ViewResult;


            //assert
            Assert.IsNotNull(viewResult);
            var student = viewResult.ViewData.Model as Student;

            Assert.AreEqual("Garden", student.FristName);
        }
Esempio n. 13
0
        public void Students_Controller_Test_On_Details_With_NonExistent_Id()
        {
            //Arrange
            Guid id   = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            var  repo = Substitute.For <IRepository>();
            var  sut  = new StudentsController(repo);

            repo.GetById <Student>(id);

            //Act
            var actual = sut.Details(id).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(NotFoundResult));
        }
Esempio n. 14
0
        public async Task Details_ReturnsStudent()
        {
            //Arrange
            var studentsRepositoryMock = new Mock <IStudentsRepository>();

            studentsRepositoryMock.Setup(repo => repo.Find(2)).Returns(Task.FromResult(GetTestStudents().ElementAt(1)));
            var controller = new StudentsController(studentsRepositoryMock.Object);

            // Act
            var viewResult = await controller.Details(2) as ViewResult;


            //assert
            Assert.IsNotNull(viewResult);
            var student = viewResult.ViewData.Model as Student;

            Assert.AreEqual("Garden", student.FristName);
        }