Exemplo n.º 1
0
        public async Task Get_returns_500_on_internal_error()
        {
            repository.Setup(r => r.GetStudentsAsync()).ThrowsAsync(new Exception());
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.Get(true);

            var actionResult = Assert.IsType <ActionResult <IEnumerable <StudentDetailsDTO> > >(actual);
            var code         = Assert.IsType <StatusCodeResult>(actionResult.Result);

            Assert.Equal(500, code.StatusCode);
        }
Exemplo n.º 2
0
        public async Task Get_given_id_that_does_not_exist_returns_404()
        {
            var id = Guid.NewGuid();

            repository.Setup(r => r.GetStudentAsync(id)).ThrowsAsync(new ArgumentException());
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.Get(id, true);

            var actionResult = Assert.IsType <ActionResult <StudentDetailsDTO> >(actual);
            var code         = Assert.IsType <StatusCodeResult>(actionResult.Result);

            Assert.Equal(404, code.StatusCode);
        }
Exemplo n.º 3
0
        public async Task Get_given_id_returns_500_on_internal_error()
        {
            var id = Guid.NewGuid();

            repository.Setup(r => r.GetStudentAsync(id)).ThrowsAsync(new Exception());
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.Get(id, true);

            var actionResult = Assert.IsType <ActionResult <StudentDetailsDTO> >(actual);
            var code         = Assert.IsType <StatusCodeResult>(actionResult.Result);

            Assert.Equal(500, code.StatusCode);
        }
Exemplo n.º 4
0
        public async Task Get_given_id_returns_200_and_student()
        {
            var student = new StudentDetailsDTO {
                Id = Guid.NewGuid(), Degree = Degree.Bachelor, MinSalary = 100, MinWorkingHours = 5, MaxWorkingHours = 20, Agreement = false, Location = "Nowhere"
            };

            repository.Setup(r => r.GetStudentAsync(student.Id)).ReturnsAsync(student);
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.Get(student.Id, true);

            var actionResult  = Assert.IsType <ActionResult <StudentDetailsDTO> >(actual);
            var okResult      = Assert.IsType <OkObjectResult>(actionResult.Result);
            var actualStudent = Assert.IsType <StudentDetailsDTO>(okResult.Value);

            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal(student, actualStudent);
        }
Exemplo n.º 5
0
        public async Task Get_returns_200_and_students()
        {
            var students = new []
            {
                new StudentDetailsDTO {
                    Id = Guid.NewGuid(), KeywordNames = new [] { "Testing" }
                },
                new StudentDetailsDTO {
                    Id = Guid.NewGuid(), KeywordNames = new [] { "C#" }
                }
            };

            repository.Setup(r => r.GetStudentsAsync()).ReturnsAsync(students);
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.Get(true);

            var actionResult   = Assert.IsType <ActionResult <IEnumerable <StudentDetailsDTO> > >(actual);
            var okResult       = Assert.IsType <OkObjectResult>(actionResult.Result);
            var actualStudents = Assert.IsType <List <StudentDetailsDTO> >(okResult.Value);

            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal(students.Length, actualStudents.Count());
        }