public void AddLectur_ValidCourseId_ShouldAddToCourse()
        {
            var controller = new CoursesController(this.mockedData, new User("nasko", "123456", Role.Lecturer));

            var view = controller.AddLecture(5, DateTime.Now.ToString());

            Assert.IsNotNull(view);
            Assert.AreEqual(this.course.Lectures.First().Name, DateTime.Now.ToString());
        }
Пример #2
0
        public void TestWithNoCourses()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Guest);
            CoursesController controller = new CoursesController(data, user);

            string message = controller.All().Display();

            Assert.AreEqual("No courses.", message);
        }
Пример #3
0
        public void All_WithValidData_ShouldCallDatabaseGetAll()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            database.Setup(a => a.Courses.GetAll()).Returns(new List<Course>());

            var courseController = new CoursesController(database.Object, new User("Ivan Ivanov", "123456", Role.Lecturer));

            courseController.All();

            database.Verify(d => d.Courses.GetAll(), Times.Exactly(1));
        }
Пример #4
0
        public void All_ShouldReturnAnIViewObject()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            database.Setup(a => a.Courses.GetAll()).Returns(new List<Course>());

            var courseController = new CoursesController(database.Object, new User("Ivan Ivanov", "123456", Role.Lecturer));

            var result = courseController.All();

            NUnit.Framework.Assert.IsInstanceOf(typeof(IView), result);
        }
Пример #5
0
        public void All_WithoutALoggedUser_ShouldStillReturnResult()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            database.Setup(a => a.Courses.GetAll()).Returns(new List<Course>());

            var courseController = new CoursesController(database.Object, null);

            var result = courseController.All();

            NUnit.Framework.Assert.IsInstanceOf(typeof(IView), result);
        }
Пример #6
0
        public void AddLecture_WithValidInput_ShouldCallDatabaseCourses()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            database.Setup(a => a.Courses.Get(It.IsAny<int>())).Returns(new Course("Test1234"));

            var courseController = new CoursesController(database.Object, new User("Ivan Ivanov", "123456", Role.Lecturer));

            var result = courseController.AddLecture(1, "TestLecture");

            database.Verify(a => a.Courses.Get(It.IsAny<int>()), Times.Exactly(1));
        }
Пример #7
0
        public void TestAddLecture_InvalidCourseId_ShouldThrow()
        {
            Course course = null;
            var mockedData = new Mock<IBangaloreUniversityData>();
            var mockedCourseRepo = new Mock<IRepository<Course>>();
            mockedCourseRepo.Setup(repo => repo.Get(It.IsAny<int>())).Returns(course);
            mockedData.Setup(data => data.Courses).Returns(mockedCourseRepo.Object);

            var controller = new CoursesController(mockedData.Object, new User("asdfff", "1as65df1", Role.Lecturer));

            controller.AddLecture(1, "");
        }
Пример #8
0
        public void TestAddLecture_InvalidUser_ShouldThrow()
        {
            var course = new Course("Very advanced Java");
            var mockedData = new Mock<IBangaloreUniversityData>();
            var mockedCourseRepo = new Mock<IRepository<Course>>();
            mockedCourseRepo.Setup(repo => repo.Get(It.IsAny<int>())).Returns(course);
            mockedData.Setup(data => data.Courses).Returns(mockedCourseRepo.Object);

            var controller = new CoursesController(mockedData.Object, null);

            controller.AddLecture(12, "");
        }
Пример #9
0
        public void AddLecture_WithValidInput_ShouldAddNewLectureToSpecifiedCourse()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            var course = new Course("Test1234");
            Assert.AreEqual(0, course.Lectures.Count);
            database.Setup(a => a.Courses.Get(It.IsAny<int>())).Returns(course);

            var courseController = new CoursesController(database.Object, new User("Ivan Ivanov", "123456", Role.Lecturer));

            var result = courseController.AddLecture(5, "TestLecture");

            Assert.AreEqual(1, course.Lectures.Count);
        }
Пример #10
0
        public void TestAddLecture_InvalidUserRole_ShouldThrow()
        {
            var course = new Course("Advanced Java");
            var mockedData = new Mock<IBangaloreUniversityData>();
            var mockedCoursesRepo = new Mock<IRepository<Course>>();
            mockedCoursesRepo.Setup(repo => repo.Get(It.IsAny<int>())).Returns(course);
            mockedData.Setup(data => data.Courses).Returns(mockedCoursesRepo.Object);

            var controller = new CoursesController(
                mockedData.Object, new User("123456", "123456", Role.Student));

            var view = controller.AddLecture(800, "ABC");
        }
        public void AddLecture_ValidCourseId_ShouldAddToCourse()
        {
            // Arrange
            var controller = new CoursesController(this.mockedData, new User("Nasko", "123456", Role.Lecturer));

            string lectureName = DateTime.Now.ToString();

            // Act
            var view = controller.AddLecture(5, lectureName);

            // Assert
            Assert.AreEqual(this.course.Lectures.First().Name, lectureName);
            Assert.IsNotNull(view);
        }
Пример #12
0
        public void TestAddLecture_ValidCourse_ShouldAddToCourse()
        {
            var course = new Course("Advanced Java");
            var mockedData = new Mock<IBangaloreUniversityData>();
            var mockedCoursesRepo = new Mock<IRepository<Course>>();
            mockedCoursesRepo.Setup(repo => repo.Get(It.IsAny<int>())).Returns(course);
            mockedData.Setup(data => data.Courses).Returns(mockedCoursesRepo.Object);

            var controller = new CoursesController(
                mockedData.Object, new User("123456", "123456", Role.Lecturer));

            var view = controller.AddLecture(800, "ABC");

            Assert.AreEqual(course.Lectures.First().Name, "ABC");
            Assert.IsNotNull(view);
        }
        public void TestAllCoursesMultipleCoursesNoStudents_ShouldReturnCourses()
        {
            // Arrange
            IBangaloreUniversityDatabase data = new BangaloreUniversityDatabase();
            User testUser = new User("test user", "password", Role.Student);
            CoursesController controller = new CoursesController(data, testUser);
            Course testCourse1 = new Course("test course1");
            Course testCourse2 = new Course("test course2");
            Course testCourse3 = new Course("test course3");
            Course testCourse4 = new Course("test course4");
            Course testCourse5 = new Course("test course5");
            Course testCourse6 = new Course("test course6");
            Course testCourse7 = new Course("test course7");
            Course testCourse8 = new Course("test course8");
            Course testCourse9 = new Course("test course9");
            Course testCourse10 = new Course("test course10");
            data.Courses.Add(testCourse1);
            data.Courses.Add(testCourse2);
            data.Courses.Add(testCourse3);
            data.Courses.Add(testCourse4);
            data.Courses.Add(testCourse5);
            data.Courses.Add(testCourse6);
            data.Courses.Add(testCourse7);
            data.Courses.Add(testCourse8);
            data.Courses.Add(testCourse9);
            data.Courses.Add(testCourse10);

            // Act
            IView view = controller.All();
            string result = view.Display();
            StringBuilder expected = new StringBuilder();
            expected.AppendLine("All courses:");
            expected.AppendLine("test course1 (0 students)");
            expected.AppendLine("test course10 (0 students)");
            expected.AppendLine("test course2 (0 students)");
            expected.AppendLine("test course3 (0 students)");
            expected.AppendLine("test course4 (0 students)");
            expected.AppendLine("test course5 (0 students)");
            expected.AppendLine("test course6 (0 students)");
            expected.AppendLine("test course7 (0 students)");
            expected.AppendLine("test course8 (0 students)");
            expected.Append("test course9 (0 students)");

            // Assert
            Assert.AreEqual(expected.ToString(), result);
        }
Пример #14
0
        public void TestWithOneCourseAndNoStudents()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Lecturer);
            CoursesController controller = new CoursesController(data, user);

            controller.Create("Object-Oriented+Programming");
            string message = controller.All().Display();

            var courses = new StringBuilder();
            courses.AppendLine("All courses:");
            foreach (var course in data.Courses.Items)
            {
                courses.AppendFormat("{0} ({1} students)", course.CourseName, course.Students.Count);
            }

            Assert.AreEqual(courses.ToString(), message);
        }
        public void AddLecture_InvalidCourseId_ShouldThrow()
        {
            var dataMock = new Mock<IBangaloreUniversityData>();
            var courseRepoMock = new Mock<IRepository<Course>>();
            this.course = null;

            courseRepoMock.Setup(r => r.Get(It.IsAny<int>()))
                .Returns(this.course);

            dataMock.Setup(d => d.Courses)
                .Returns(courseRepoMock.Object);

            this.mockedData = dataMock.Object;

            var controller = new CoursesController(this.mockedData, new User("nasko", "123456", Role.Lecturer));

            var view = controller.AddLecture(5, DateTime.Now.ToString());
        }
Пример #16
0
        public void TestWithSeveralCoursesAndDifferentStudents()
        {
            IBangaloreUniversityData data = new BangaloreUniversityData();
            User user = new User("firstLecturer", "firstPass", Role.Lecturer);
            CoursesController controller = new CoursesController(data, user);

            controller.Create("Object-Oriented+Programming");
            controller.Create("High-Quality+Code");
            controller.Create("Java+Basics");
            controller.Enroll(1);
            controller.Enroll(3);
            string message = controller.All().Display();

            var courses = new StringBuilder();
            courses.AppendLine("All courses:");
            foreach (var course in data.Courses.Items.OrderBy(c => c.CourseName).ThenByDescending(c => c.Students.Count))
            {
                courses.AppendFormat("{0} ({1} students)", course.CourseName, course.Students.Count).AppendLine();
            }

            Assert.AreEqual(courses.ToString().Trim(), message);
        }
Пример #17
0
        public void AddLecture_WithIncorrectRole_ShouldThrowCorrectException()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            var course = new Course("Test1234");
            database.Setup(a => a.Courses.Get(It.IsAny<int>())).Returns(course);

            var courseController = new CoursesController(database.Object, new User("Ivan ivanov", "123456", Role.Student));

            var exception = NUnit.Framework.Assert.Catch<AuthorizationFailedException>(
                () =>
                {
                    var result = courseController.AddLecture(5, "TestLecture");
                });
            Assert.AreEqual(Constants.NotAuthorized, exception.Message);
        }
        public void TestAllCoursesMultipleCoursesWithStudents_ShouldReturnCoursesWithCorrectStudentCountOrderedCorrectly()
        {
            // Arrange
            IBangaloreUniversityDatabase data = new BangaloreUniversityDatabase();
            User testUser = new User("test user", "password", Role.Student);
            CoursesController controller = new CoursesController(data, testUser);
            Course testCourse1 = new Course("C# Basics");
            Course testCourse2 = new Course("Java Basics");
            Course testCourse3 = new Course("C Basics");
            Course testCourse4 = new Course("JavaScript");
            Course testCourse5 = new Course("Java Advanced");
            Course testCourse6 = new Course("HTML & CSS");
            Course testCourse7 = new Course("Java Basics");
            Course testCourse8 = new Course("C# Advanced");
            Course testCourse9 = new Course("C# Basics");

            User student1 = new User("student1", "password", Role.Student);
            User student2 = new User("student2", "password", Role.Student);
            User student3 = new User("student3", "password", Role.Student);
            User student4 = new User("student4", "password", Role.Student);
            User student5 = new User("student5", "password", Role.Student);
            User student6 = new User("student6", "password", Role.Student);

            testCourse9.AddStudent(student1);
            testCourse9.AddStudent(student2);
            testCourse9.AddStudent(student3);
            testCourse9.AddStudent(student4);
            testCourse9.AddStudent(student5);
            testCourse9.AddStudent(student6);

            testCourse8.AddStudent(student1);
            testCourse8.AddStudent(student2);
            testCourse8.AddStudent(student3);
            testCourse8.AddStudent(student4);
            testCourse8.AddStudent(student5);

            testCourse1.AddStudent(student1);
            testCourse1.AddStudent(student2);
            testCourse1.AddStudent(student3);
            testCourse1.AddStudent(student4);
            testCourse1.AddStudent(student5);

            testCourse2.AddStudent(student2);
            testCourse2.AddStudent(student3);
            testCourse2.AddStudent(student4);
            testCourse2.AddStudent(student5);

            testCourse7.AddStudent(student4);
            testCourse7.AddStudent(student5);
            testCourse7.AddStudent(student6);

            testCourse5.AddStudent(student1);
            testCourse5.AddStudent(student3);

            testCourse6.AddStudent(student2);
            testCourse6.AddStudent(student3);

            testCourse3.AddStudent(student5);

            data.Courses.Add(testCourse1);
            data.Courses.Add(testCourse2);
            data.Courses.Add(testCourse3);
            data.Courses.Add(testCourse4);
            data.Courses.Add(testCourse5);
            data.Courses.Add(testCourse6);
            data.Courses.Add(testCourse7);
            data.Courses.Add(testCourse8);
            data.Courses.Add(testCourse9);

            // Act
            IView view = controller.All();
            string result = view.Display();
            StringBuilder expected = new StringBuilder();
            expected.AppendLine("All courses:");
            expected.AppendLine("C Basics (1 students)");
            expected.AppendLine("C# Advanced (5 students)");
            expected.AppendLine("C# Basics (6 students)");
            expected.AppendLine("C# Basics (5 students)");
            expected.AppendLine("HTML & CSS (2 students)");
            expected.AppendLine("Java Advanced (2 students)");
            expected.AppendLine("Java Basics (4 students)");
            expected.AppendLine("Java Basics (3 students)");
            expected.Append("JavaScript (0 students)");

            // Assert
            Assert.AreEqual(expected.ToString(), result);
        }
        public void TestAllCoursesOneCourse_ShouldReturnCourse()
        {
            // Arrange
            IBangaloreUniversityDatabase data = new BangaloreUniversityDatabase();
            User testUser = new User("test user", "password", Role.Student);
            CoursesController controller = new CoursesController(data, testUser);
            Course testCourse = new Course("test course");
            data.Courses.Add(testCourse);

            // Act
            IView view = controller.All();
            string result = view.Display();

            // Assert
            string expected = string.Format("All courses:{0}test course (0 students)", Environment.NewLine);
            Assert.AreEqual(expected, result);
        }
        public void TestAllCourses_ShouldReturnNoCourses()
        {
            // Arrange
            IBangaloreUniversityDatabase data = new BangaloreUniversityDatabase();
            User testUser = new User("test user", "password", Role.Student);
            CoursesController controller = new CoursesController(data, testUser);

            // Act
            IView view = controller.All();
            string result = view.Display();

            // Assert
            Assert.AreEqual("No courses.", result);
        }
        public void TestAllCoursesMultipleCoursesWithStudents_ShouldReturnCoursesWithCorrectStudentCount()
        {
            // Arrange
            IBangaloreUniversityDatabase data = new BangaloreUniversityDatabase();
            User testUser = new User("test user", "password", Role.Student);
            CoursesController controller = new CoursesController(data, testUser);
            Course testCourse1 = new Course("test course1");
            Course testCourse2 = new Course("test course2");
            Course testCourse3 = new Course("test course3");
            Course testCourse4 = new Course("test course4");
            Course testCourse5 = new Course("test course5");
            Course testCourse6 = new Course("test course6");
            Course testCourse7 = new Course("test course7");
            Course testCourse8 = new Course("test course8");
            Course testCourse9 = new Course("test course9");

            User student1 = new User("student1", "password", Role.Student);
            User student2 = new User("student2", "password", Role.Student);
            User student3 = new User("student3", "password", Role.Student);
            User student4 = new User("student4", "password", Role.Student);
            User student5 = new User("student5", "password", Role.Student);
            User student6 = new User("student6", "password", Role.Student);

            testCourse1.AddStudent(student1);
            testCourse1.AddStudent(student2);
            testCourse1.AddStudent(student3);
            testCourse1.AddStudent(student4);
            testCourse1.AddStudent(student5);
            testCourse1.AddStudent(student6);

            testCourse2.AddStudent(student1);
            testCourse2.AddStudent(student2);
            testCourse2.AddStudent(student3);
            testCourse2.AddStudent(student4);
            testCourse2.AddStudent(student5);

            testCourse3.AddStudent(student1);
            testCourse3.AddStudent(student2);
            testCourse3.AddStudent(student3);
            testCourse3.AddStudent(student4);
            testCourse3.AddStudent(student5);

            testCourse4.AddStudent(student2);
            testCourse4.AddStudent(student3);
            testCourse4.AddStudent(student4);
            testCourse4.AddStudent(student5);

            testCourse5.AddStudent(student4);
            testCourse5.AddStudent(student5);
            testCourse5.AddStudent(student6);

            testCourse6.AddStudent(student1);
            testCourse6.AddStudent(student2);
            testCourse6.AddStudent(student3);

            testCourse7.AddStudent(student2);
            testCourse7.AddStudent(student3);

            testCourse8.AddStudent(student5);

            data.Courses.Add(testCourse1);
            data.Courses.Add(testCourse2);
            data.Courses.Add(testCourse3);
            data.Courses.Add(testCourse4);
            data.Courses.Add(testCourse5);
            data.Courses.Add(testCourse6);
            data.Courses.Add(testCourse7);
            data.Courses.Add(testCourse8);
            data.Courses.Add(testCourse9);

            // Act
            IView view = controller.All();
            string result = view.Display();
            StringBuilder expected = new StringBuilder();
            expected.AppendLine("All courses:");
            expected.AppendLine("test course1 (6 students)");
            expected.AppendLine("test course2 (5 students)");
            expected.AppendLine("test course3 (5 students)");
            expected.AppendLine("test course4 (4 students)");
            expected.AppendLine("test course5 (3 students)");
            expected.AppendLine("test course6 (3 students)");
            expected.AppendLine("test course7 (2 students)");
            expected.AppendLine("test course8 (1 students)");
            expected.Append("test course9 (0 students)");

            // Assert
            Assert.AreEqual(expected.ToString(), result);
        }
Пример #22
0
        public void AddLecture_WithoutLoggedUser_ShouldThrowCorrectException()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            var course = new Course("Test1234");
            database.Setup(a => a.Courses.Get(It.IsAny<int>())).Returns(course);

            var courseController = new CoursesController(database.Object, null);

            var exception = NUnit.Framework.Assert.Catch<ArgumentException>(
                () =>
                {
                    var result = courseController.AddLecture(5, "TestLecture");
                });
            Assert.AreEqual(Constants.NoLoggedInUserMessage, exception.Message);
        }
Пример #23
0
        public void AddLecture_WithValidData_ReturnAnIViewObject()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            var course = new Course("Test1234");
            Assert.AreEqual(0, course.Lectures.Count);
            database.Setup(a => a.Courses.Get(It.IsAny<int>())).Returns(course);

            var courseController = new CoursesController(database.Object, new User("Ivan Ivanov", "123456", Role.Lecturer));

            var result = courseController.AddLecture(5, "TestLecture");

            NUnit.Framework.Assert.IsInstanceOf(typeof(IView),result);
        }
Пример #24
0
        public void AddLecture_WithNonExistantCourse_ShouldThrowCorrectException()
        {
            var database = new Mock<IBangaloreUniversityDatabase>();
            Course course = null;
            database.Setup(a => a.Courses.Get(It.IsAny<int>())).Returns(course);

            var courseController = new CoursesController(database.Object, new User("Ivan Ivanov", "123456", Role.Lecturer));

            var exception = NUnit.Framework.Assert.Catch<ArgumentException>(
                () =>
                {
                    var result = courseController.AddLecture(5, "TestLecture");
                });
            Assert.AreEqual(string.Format(Constants.CourseDoesNotExist, 5), exception.Message);
        }
 public void InitializeCoursesController()
 {
     var data = new BangaloreUniversityData();
     var user = new User("pesho", "32432we", Role.Lecturer);
     this.controller = new CoursesController(data, user);
 }