//[Fact]
        public void AssignLecturers_Post_ReturnsNotFound_WhenNonExistingCourseInModel()
        {
            // Arrange
            int    nonExistingCourseId = 0;
            Course nonExistingCourse   = new Course()
            {
                Id = nonExistingCourseId
            };
            CourseLecturersAssignmentViewModel model = new CourseLecturersAssignmentViewModel()
            {
                Course = nonExistingCourse,
                LecturersAssignmentsList = new List <LecturerAssignment>()
            };

            var courseServiceMock = Substitute.For <CourseService>();

            courseServiceMock.IsCourseExisted(nonExistingCourse).Returns(false);
            var controller = new CourseController(courseServiceMock, null, null, null, null);

            // Act
            var result = controller.AssignLecturers(model);

            // Assert
            var viewResult = Assert.IsType <NotFoundResult>(result);
        }
        public void AssignLecturers_Post_RedirectToCourses()
        {
            // Arrange
            int       courseId               = 1;
            const int assignedLecturerId     = 2;
            const int nonAssignedLecturertId = 3;
            Course    course = new Course()
            {
                Id = courseId
            };
            CourseLecturersAssignmentViewModel model = new CourseLecturersAssignmentViewModel()
            {
                Course = course,
                LecturersAssignmentsList = new List <LecturerAssignment>()
                {
                    new LecturerAssignment()
                    {
                        Lecturer = new Lecturer()
                        {
                            Id = assignedLecturerId
                        },
                        IsAssigned = true
                    },
                    new LecturerAssignment()
                    {
                        Lecturer = new Lecturer()
                        {
                            Id = nonAssignedLecturertId
                        },
                        IsAssigned = false
                    }
                }
            };

            var courseServiceMock = Substitute.For <CourseService>();

            courseServiceMock.IsCourseExisted(course).Returns(true);
            courseServiceMock.AssignStudentsToCourse(courseId, new List <int>()).Returns(true);

            var lecturerServiceMock = Substitute.For <LecturerService>();
            //lecturerServiceMock.IsStudentExisted(new Lecturer()).Returns(true);

            var controller = new CourseController(courseServiceMock, null, null, null, lecturerServiceMock);

            // Act
            var result = controller.AssignLecturers(model);

            // Assert
            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Courses", redirectToActionResult.ActionName);
        }
Exemple #3
0
        public async Task AssignLecturers_ReturnsBadRequest_WhenAssignmentViewModelIsEmpty()
        {
            //Arrange
            CourseLecturerAssignmentViewModel model = null;
            CourseService    courseService          = Substitute.For <CourseService>();
            LecturerService  LecturerService        = Substitute.For <LecturerService>();
            CourseController controller             = new CourseController(courseService, null, LecturerService);

            //Act
            IActionResult actual = controller.AssignLecturers(model);

            //Assert
            actual.Should().BeAssignableTo <BadRequestResult>();
        }
Exemple #4
0
        public async Task AssignLecturers_ReturnNotFound_WhenNonExistingCourseId()
        {
            //Arrange
            CourseService    courseService = Substitute.For <CourseService>();
            CourseController controller    = new CourseController(courseService, null, null);

            //Act
            IActionResult actual = controller.AssignLecturers(0);

            //Assert
            var expected = new NotFoundResult();

            actual.Should().BeEquivalentTo(expected);
        }
        public void AssignLecturers_Get_ReturnsNotFound_WhenNonExistingCourseId()
        {
            // Arrange
            int nonExistingCourseId = 0;

            var courseServiceMock = Substitute.For <CourseService>();

            courseServiceMock.GetCourse(nonExistingCourseId).Returns(default(Course));
            var controller = new CourseController(courseServiceMock, null, null, null, null);

            // Act
            var result = controller.AssignLecturers(nonExistingCourseId);

            // Assert
            var viewResult = Assert.IsType <NotFoundResult>(result);
        }
Exemple #6
0
        public async Task AssignLecturers_ReturnsViewResult_WithViewModel()
        {
            // Arrange
            var courseServiceMock = Substitute.For <CourseService>();

            courseServiceMock.GetCourse(Arg.Any <int>()).Returns(new Course());
            LecturerService lecturerService = Substitute.For <LecturerService>();

            lecturerService.GetAllLecturers().Returns(new List <Lecturer>());
            var controller = new CourseController(courseServiceMock, null, lecturerService);

            // Act
            var result = controller.AssignLecturers(0);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.IsAssignableFrom <CourseLecturerAssignmentViewModel>(viewResult.ViewData.Model);
        }
        public void AssignLecturers_Get_ReturnsViewResult_WithCourseLecturersAssignmentViewModel()
        {
            // Arrange
            const int courseId              = 1;
            const int assignedLecturerId    = 2;
            const int nonAssignedLecturerId = 3;

            var allLecturers = new List <Lecturer>()
            {
                new Lecturer()
                {
                    Id = assignedLecturerId
                },
                new Lecturer()
                {
                    Id = nonAssignedLecturerId
                }
            };
            CourseLecturersAssignmentViewModel expectedModel = new CourseLecturersAssignmentViewModel()
            {
                Course = new Course()
                {
                    Id        = courseId,
                    Lecturers = new List <Lecturer>()
                    {
                        new Lecturer()
                        {
                            Id = assignedLecturerId
                        }
                    }
                },
                LecturersAssignmentsList = new List <LecturerAssignment>()
                {
                    new LecturerAssignment()
                    {
                        Lecturer = new Lecturer()
                        {
                            Id = assignedLecturerId
                        },
                        IsAssigned = true
                    },
                    new LecturerAssignment()
                    {
                        Lecturer = new Lecturer()
                        {
                            Id = nonAssignedLecturerId
                        },
                        IsAssigned = false
                    }
                }
            };

            var courseServiceMock = Substitute.For <CourseService>();

            courseServiceMock.GetCourse(courseId).Returns(new Course()
            {
                Id        = courseId,
                Lecturers = new List <Lecturer>()
                {
                    new Lecturer()
                    {
                        Id = assignedLecturerId
                    }
                }
            });

            var lecturerServise = Substitute.For <LecturerService>();

            lecturerServise.GetAllLecturers().Returns(allLecturers);

            var controller = new CourseController(courseServiceMock, null, null, null, lecturerServise);

            // Act
            var result = controller.AssignLecturers(courseId);

            // Assert
            var viewResult  = Assert.IsType <ViewResult>(result);
            var actualModel = Assert.IsType <CourseLecturersAssignmentViewModel>(viewResult.Model);

            actualModel.WithDeepEqual(expectedModel).Assert();
        }
Exemple #8
0
        public async Task AssignLecturers_ReturnsViewResult_WithCoursesAndStudentsAreAssigned()
        {
            // Arrange
            const int    courseId              = 1;
            const int    assignedLecturerId    = 11;
            const int    nonassignedLecturerId = 22;
            const string courseName            = "test";

            CourseLecturerAssignmentViewModel expectedModel = new CourseLecturerAssignmentViewModel()
            {
                Id        = courseId,
                Name      = courseName,
                Lecturers = new List <LecturersViewModel>()
                {
                    new LecturersViewModel()
                    {
                        LecturerId = assignedLecturerId, Name = "Test1", IsAssigned = true
                    },
                    new LecturersViewModel()
                    {
                        LecturerId = nonassignedLecturerId, Name = "Test2", IsAssigned = false
                    }
                }
            };
            var courseServiceMock = Substitute.For <CourseService>();

            courseServiceMock.GetCourse(courseId).Returns(new Course()
            {
                Id        = courseId,
                Name      = courseName,
                Lecturers = new List <LecturerCourse>()
                {
                    new LecturerCourse()
                    {
                        LecturerId = assignedLecturerId
                    }
                }
            });

            var lecturerService = Substitute.For <LecturerService>();
            var lecturers       = new List <Lecturer>()
            {
                new Lecturer()
                {
                    Id = assignedLecturerId, Name = "Test1"
                },
                new Lecturer()
                {
                    Id = nonassignedLecturerId, Name = "Test2"
                }
            };

            lecturerService.GetAllLecturers().Returns(lecturers);
            var controller = new CourseController(courseServiceMock, null, lecturerService);

            // Act
            var result = controller.AssignLecturers(courseId);

            // Assert
            var viewResult  = Assert.IsType <ViewResult>(result);
            var actualModel = Assert.IsAssignableFrom <CourseLecturerAssignmentViewModel>(viewResult.ViewData.Model);

            actualModel.Should().BeEquivalentTo(expectedModel);
        }