Esempio 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);
        }
Esempio 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);
        }
Esempio n. 3
0
        public async Task Delete_returns_500_on_internal_error()
        {
            var id = Guid.NewGuid();

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

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

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

            Assert.Equal(500, code.StatusCode);
        }
Esempio n. 4
0
        public async Task Create_returns_500_on_internal_error()
        {
            var student = new CreateStudentDTO();

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

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

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

            Assert.Equal(500, code.StatusCode);
        }
Esempio n. 5
0
        public async Task UnSave_returns_500_on_internal_server_error()
        {
            var studentId     = id1;
            var descriptionId = 1;

            repository.Setup(r => r.UnSavePlacementDescription(studentId, descriptionId)).ThrowsAsync(new Exception());
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.UnSave(studentId, descriptionId, true);

            var actionCodeResult = Assert.IsType <ActionResult <bool> >(actual);
            var code             = Assert.IsType <StatusCodeResult>(actionCodeResult.Result);

            Assert.Equal(500, code.StatusCode);
        }
Esempio n. 6
0
        public async Task UnSave_returns_404_on_not_found()
        {
            var studentId     = id1;
            var descriptionId = 100;

            repository.Setup(r => r.UnSavePlacementDescription(studentId, descriptionId)).ThrowsAsync(new ArgumentException());
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.UnSave(studentId, descriptionId, true);

            var actionCodeResult = Assert.IsType <ActionResult <bool> >(actual);
            var code             = Assert.IsType <StatusCodeResult>(actionCodeResult.Result);

            Assert.Equal(404, code.StatusCode);
        }
Esempio n. 7
0
        public async Task Update_returns_404_on_not_found()
        {
            var student = new UpdateStudentDTO {
                Id = Guid.NewGuid()
            };

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

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

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

            Assert.Equal(404, code.StatusCode);
        }
Esempio n. 8
0
        public async Task Delete_returns_200_and_true()
        {
            var id = Guid.NewGuid();

            repository.Setup(r => r.DeleteStudentAsync(id)).ReturnsAsync(true);
            var controller = new StudentRepositoryController(repository.Object);

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

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

            Assert.Equal(200, okResult.StatusCode);
            Assert.True(hasBeenDeleted);
        }
Esempio n. 9
0
        public async Task UnSave_returns_true_on_200()
        {
            var studentId     = id2;
            var descriptionId = 1;

            repository.Setup(r => r.UnSavePlacementDescription(studentId, descriptionId)).ReturnsAsync(true);
            var controller = new StudentRepositoryController(repository.Object);

            var actual = await controller.UnSave(studentId, descriptionId, true);

            var actionCodeResult = Assert.IsType <ActionResult <bool> >(actual);
            var code             = Assert.IsType <OkObjectResult>(actionCodeResult.Result);
            var hasBeenUnSaved   = Assert.IsType <bool>(code.Value);

            Assert.Equal(200, code.StatusCode);
            Assert.True(hasBeenUnSaved);
        }
Esempio n. 10
0
        public async Task Create_returns_200_and_id_of_created_student()
        {
            var nextMockedId = Guid.NewGuid();
            var student      = new CreateStudentDTO();

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

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

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

            Assert.Equal(200, okResult.StatusCode);
            Assert.Equal(nextMockedId, actualId);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public async Task Update_returns_200_and_true()
        {
            var student = new UpdateStudentDTO {
                Degree = Degree.Bachelor
            };

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

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

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

            Assert.Equal(200, okResult.StatusCode);
            Assert.True(hasBeenUpdated);
        }
Esempio n. 13
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());
        }