public void TestAddLecture_TryAddLectureWhenUserIsNotAuthorized_ShouldThrow() { User lecturer = new User("Pesho", "pasword", Role.Student); IBangaloreUniversityData fakeData = new FakeData(); var courseController = new CoursesController(fakeData, lecturer); int fakeCourseId = 10; IView view = courseController.AddLecture(fakeCourseId, "Refactoring"); }
public void TestAddLecture_InvalidCourseId_ShouldThrow() { User lecturer = new User("Pesho", "pasword", Role.Lecturer); IBangaloreUniversityData data = new FakeData2(); var courseController = new CoursesController(data, lecturer); int invalidCourseId = 2; IView view = courseController.AddLecture(invalidCourseId, "Refactoring"); }
public void TestAddLecture_TryAddLectureWhenNoLoggedInUser_ShouldThrow() { User noUser = null; IBangaloreUniversityData fakeData = new FakeData(); var courseController = new CoursesController(fakeData, noUser); int fakeCourseId = 10; IView view = courseController.AddLecture(fakeCourseId, "Refactoring"); }
public void TestAddLectureWhenDontHavePermisionShouldThrowException() { var mockedData = new Mock <IBangaloreUniversityData>(); var courses = new MockedRepositories.MockCourseRepository(); courses.Add(new Course("habala")); mockedData.Setup(r => r.Courses()).Returns(courses); var controller = new CoursesController(mockedData.Object, new User("blablabla", "b;a;ba;ba;", Role.Student)); var result = controller.AddLecture(1, "balba"); }
public void TestAddLectureWhenNotLoggedShouldThrowException() { var mockedData = new Mock <IBangaloreUniversityData>(); var courses = new MockedRepositories.MockCourseRepository(); courses.Add(new Course("habala")); mockedData.Setup(r => r.Courses()).Returns(courses); var controller = new CoursesController(mockedData.Object, null); var result = controller.AddLecture(1, "balba"); }
public void AddLecture_ByNotLoggedGuestToNonExistingCourse_ShouldThrowException() { var dbMock = new Mock <IBangaloreUniversityDate>(); dbMock.Setup(d => d.Courses.Add(It.IsAny <Course>())); CoursesController courseController = new CoursesController(dbMock.Object, null); courseController.AddLecture(2, "Inheritance"); }
public void AddLecture_ValidCourseId_ShouldAddToCourse() { var controller = new CoursesController(this.mockedData, new User("nasko", "123456", Role.Lecturer)); string lectureName = DateTime.Now.ToString(); var view = controller.AddLecture(5, lectureName); Assert.AreEqual(this.course.Lectures.First().Name, lectureName); Assert.IsNotNull(view); }
public void AddLecture_ByStudentToNonExistingCourse_ShouldThrowException() { User firstUser = new User(FirstUsername, "password", Role.Lecturer); var dbMock = new Mock <IBangaloreUniversityDate>(); dbMock.Setup(d => d.Courses.Add(It.IsAny <Course>())); CoursesController courseController = new CoursesController(dbMock.Object, firstUser); courseController.AddLecture(2, "Inheritance"); }
public void TestAddLectureWhenLoggedAndCourseIsSetShouldReturnAddMessage() { var mockedData = new Mock <IBangaloreUniversityData>(); var courses = new MockedRepositories.MockCourseRepository(); courses.Add(new Course("habala")); mockedData.Setup(r => r.Courses()).Returns(courses); var controller = new CoursesController(mockedData.Object, new User("blablabla", "b;a;ba;ba;", Role.Lecturer)); var result = controller.AddLecture(1, "balba"); var message = string.Format(Message.LectureAddedSuccessfully, "habala"); Assert.AreEqual(message, result.Display()); }
public void AddLecture_ValidCourseId_ShouldAddToCourse() { // Arrange var controller = new CoursesController(this.mockedData, new User("Pesho", "123456", Role.Lecturer)); const int LectureId = 5; string lectureName = DateTime.Now.ToString(); // Act var view = controller.AddLecture(LectureId, lectureName); // Assert Assert.AreEqual(this.course.Lectures.First().Name, lectureName); Assert.IsNotNull(view); }
public void AddLecture_ToAnExistingCourse_ShouldAddLectures() { User firstUser = new User(FirstUsername, "password", Role.Lecturer); var dbMock = new Mock <IBangaloreUniversityDate>(); dbMock.Setup(d => d.Courses.Add(It.IsAny <Course>())); dbMock.Setup(db => db.Courses.Get(It.IsAny <int>())).Returns(new Course(FirstCourse)); CoursesController courseController = new CoursesController(dbMock.Object, firstUser); courseController.Enroll(1); courseController.AddLecture(1, "Inheritance"); courseController.AddLecture(1, "Polymorphism"); courseController.AddLecture(1, "Abstraction"); courseController.AddLecture(1, "Encapsulation"); IView view = courseController.Details(1); string actualResut = view.Display(); string expectedResult = "CourseA\r\n- Inheritance\r\n- Polymorphism\r\n- Abstraction\r\n- Encapsulation"; Assert.AreEqual(expectedResult, actualResut, "Add lecture does not return proper view."); }
public void TestAddLecture_ValidCourseId_ShouldAddLectureToCourse() { User lecturer = new User("Pesho", "pasword", Role.Lecturer); IBangaloreUniversityData fakeData = new FakeData(); var courseController = new CoursesController(fakeData, lecturer); int fakeCourseId = 10; IView view = courseController.AddLecture(fakeCourseId, "Refactoring"); string viewResult = view.Display(); string expectedAddedLectureName = fakeData.CoursesRepository.GetAll().First().Lectures.GetAll().First().Name; Assert.AreEqual(expectedAddedLectureName, "Refactoring", "AddLecture() doesn't add lecture when it should."); string expectedResult = string.Format("Lecture successfully added to course High Quality Code."); Assert.AreEqual(viewResult, expectedResult, "AddLecture() doesn't add lecture when it should."); }
public void AddLecture_InvalidCourseId_ShouldThrow() { // Arrange var dataMock = new Mock <IBangaloreUniversityData>(); var courseRepoMock = new Mock <IRepository <Course> >(); this.course = new Course("C# for babies"); courseRepoMock.Setup(r => r.Get(It.IsAny <int>())).Returns(default(Course)); dataMock.Setup(d => d.Courses).Returns(courseRepoMock.Object); this.mockedData = dataMock.Object; var controller = new CoursesController(this.mockedData, new User("Pesho", "123456", Role.Lecturer)); const int LectureId = 5; string lectureName = DateTime.Now.ToString(); // Act var view = controller.AddLecture(LectureId, lectureName); }
public void TestAddLecture() { var course = new Course("kur kurs"); var repoMock = new Mock <IRepository <Course> >(); repoMock.Setup(x => x.Get(It.IsAny <int>())).Returns(course); var dataMock = new Mock <IBangaloreUniversityData>(); dataMock.Setup(x => x.CoursesRepository).Returns(repoMock.Object); var lectureName = "kur lekciq"; this.mockedData = dataMock.Object; var controller = new CoursesController( this.mockedData, new User("nasko", "123445667432", Role.Lecturer)); var view = controller.AddLecture(1, "kur lekciq"); Assert.AreEqual(course.Lectures.First().Name, lectureName, "The lecture name is not equal to the expected one"); }