示例#1
0
        public void GetAllCoursesByCategoryTest()
        {
            var sut = new CatalogBll(this.catalog.Object, this.converter.Object);

            foreach (var category in categories)
            {
                var actual = sut.GetAllCoursesByCategory(category.Name);

                this.catalog.Verify(
                    cat => cat.GetAllCoursesByCategory(category.Name),
                    Times.AtLeastOnce());
                Assert.That(actual, Is.All.InstanceOf(typeof(CourseDTO)));
            }
        }
示例#2
0
        public IHttpActionResult GetCoursesByCategory(string categoryName)
        {
            try
            {
                IEnumerable <CourseDTO> courses = catalog.GetAllCoursesByCategory(categoryName);
                if (courses == null)
                {
                    throw new Exception("Courses aren't found by this category!");
                }

                return(Ok(courses.ToList()));
            }
            catch (ArgumentNullException ex)
            {
                var message = $"Category with name = {categoryName} " +
                              $"not found. {ex.Message}";
                return(BadRequest(message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }