コード例 #1
0
        public void GetAllDecksByCategoryTest()
        {
            var sut = new CatalogBll(this.catalog.Object, this.converter.Object);

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

                this.catalog.Verify(
                    cat => cat.GetAllDecksByCategory(category.Name),
                    Times.AtLeastOnce());

                Assert.That(actual, Is.All.InstanceOf(typeof(DeckDTO)));
            }
        }
コード例 #2
0
        public IHttpActionResult GetDecksByCategory(string categoryName)
        {
            try
            {
                IEnumerable <DeckDTO> decks = catalog
                                              .GetAllDecksByCategory(categoryName);
                if (decks == null)
                {
                    throw new Exception("Decks aren't found by this category!");
                }

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