public void DeleteCourse_ShouldDeleteCourse_WhenGivenCourseID() { //Arrange var course = new Course { CourseID = 1, Title = "Title", Text = "Text" }; var data = new List <Course>().AsQueryable(); var mockSet = new Mock <DbSet <Course> >(); mockSet.As <IQueryable <Course> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Course> >().Setup(m => m.Expression).Returns(data.Expression); var mockApplicationDatabase = new Mock <ApplicationDatabase>(); mockApplicationDatabase.Setup(c => c.Courses).Returns(mockSet.Object); var databaseController = new DatabaseController { ApplicationDatabase = mockApplicationDatabase.Object }; //Act databaseController.AddCourse(course); databaseController.DeleteCourse(course.CourseID); //Assert Assert.IsFalse(mockApplicationDatabase.Object.Courses.Any()); }
public void ShouldAddCourse_WhenNotExcisted() { //Arrange var data = new List <Course> { new Course { Title = "Title", Text = "Text" } }.AsQueryable(); var mockSet = new Mock <DbSet <Course> >(); mockSet.As <IQueryable <Course> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Course> >().Setup(m => m.Expression).Returns(data.Expression); var mockApplicationDatabase = new Mock <ApplicationDatabase>(); mockApplicationDatabase.Setup(c => c.Courses).Returns(mockSet.Object); var databaseController = new DatabaseController { ApplicationDatabase = mockApplicationDatabase.Object }; //Act //var result = databaseController.AddCourse(data.ElementAt(0)); var result = databaseController.AddCourse(new Course { Title = "Title2", Text = "Text" }); //Assert Assert.AreEqual(true, result); }
public void ShouldAddCourseIfNotExist() { //Arrange var course = new Course { Title = "Title", Text = "Text" }; var data = new List <Course>().AsQueryable(); var mockSet = new Mock <DbSet <Course> >(); mockSet.As <IQueryable <Course> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Course> >().Setup(m => m.Expression).Returns(data.Expression); var mockApplicationDatabase = new Mock <ApplicationDatabase>(); var databaseController = new DatabaseController { ApplicationDatabase = mockApplicationDatabase.Object }; mockApplicationDatabase.Setup(c => c.Courses).Returns(mockSet.Object); //Act var addCourse = databaseController.AddCourse(course); //Assert Assert.IsTrue(addCourse); }
private void Update_Click(object sender, EventArgs e) { if (CourseContent.Text != string.Empty && CourseTitle.Text != string.Empty) { if (update) { var course = new Course { CourseID = courseId, Title = CourseTitle.Text, Text = CourseContent.Text, StartDate = StartDate.Value, EndDate = EndDate.Value, Official = VisibleCheck.IsChecked.Value }; CreateMessage(databaseController.EditCourse(course), true); } else { var course = new Course { Title = CourseTitle.Text, Text = CourseContent.Text, StartDate = StartDate.Value, EndDate = EndDate.Value, Official = VisibleCheck.IsChecked.Value }; if (!databaseController.AddCourse(course) || CourseTitle.Text.Equals("")) { //If title already exists or is empty, add (1) to title course.Title += "(1)"; databaseController.AddCourse(course); CreateMessage(false, true); } CreateMessage(true, false); } Close(); } else { CreateMessage(false, false); } }