public void GetCourse_ShouldReturnNotFound_WhenDifferentId()
        {
            var context = new TestCourseContext();
            context.Courses.Add(GetDemoCourse());

            var controller = new CoursesController(context);
            var getResult = controller.GetCourse(999);
            var result = getResult.Result as NotFoundResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }
        public void GetCourse_ShouldReturnCourse_WithSameId()
        {
            var context = new TestCourseContext();
            context.Courses.Add(GetDemoCourse());

            var controller = new CoursesController(context);
            var getResult = controller.GetCourse(3);
            var result = getResult.Result as OkNegotiatedContentResult<Course>;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.Content.Id, 3);
        }
        public void GetCourses_ShouldReturnAllCourses()
        {
            var context = new TestCourseContext();
            context.Courses.Add(new Course { Id = 1, Name = "Demo1" });
            context.Courses.Add(new Course { Id = 2, Name = "Demo2" });
            context.Courses.Add(new Course { Id = 3, Name = "Demo3" });

            var controller = new CoursesController(context);
            var result = controller.GetCourses() as TestCourseDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }
        public void DeleteCourse_ShouldReturnOK()
        {
            var context = new TestCourseContext();
            var item = GetDemoCourse();
            context.Courses.Add(item);

            var controller = new CoursesController(context);

            var deleteResult = controller.DeleteCourse(3);
            var result = deleteResult.Result as OkNegotiatedContentResult<Course>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
        public void DeleteCourse_ShouldReturnNotFound_WhenInvalidId()
        {
            var context = new TestCourseContext();
            var item = GetDemoCourse();
            context.Courses.Add(item);

            var controller = new CoursesController(context);

            var deleteResult = controller.DeleteCourse(999);
            var result = deleteResult.Result as NotFoundResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(NotFoundResult));
        }