예제 #1
0
        public async Task <IActionResult> Put(int id, [FromBody] CategoryDetailsServiceModel model)
        {
            bool categoryExist = await this._categories.Exists(id);

            if (!categoryExist)
            {
                return(this.BadRequest($"Category with given id {id} doesn't exist "));
            }
            return(this.Ok(await this._categories.Update(id, model.Name)));
        }
예제 #2
0
        public async Task <IActionResult> Get(int id)
        {
            CategoryDetailsServiceModel model = await this.categoryService.GetCategoryDetailsByIdAsync(id);

            if (model == null)
            {
                return(NotFound());
            }

            return(Ok(model));
        }
        public async Task GetDetailsByIdAsync_WithCategoryIdAndPage_ShouldReturnValidServiceModel()
        {
            // Arrange
            FitStoreDbContext database = this.Database;

            DatabaseHelper.SeedData(database);

            ICategoryService categoryService = new CategoryService(database);

            // Act
            CategoryDetailsServiceModel result = await categoryService.GetDetailsByIdAsync(firstCategoryId, page);

            // Assert
            result.Id.Should().Be(1);
            result.Name.Should().Be("Category 1");
            result.Subcategories.Count().Should().Be(2);
            result.Supplements.Count().Should().Be(2);
        }