Ejemplo n.º 1
0
 private void AddCategory()
 {
     NewCategoryRequest.Raise(new CategoryConfirmation(), x =>
     {
         if (x.Confirmed)
         {
             _categoryService.Add(x.Category);
             Categories.Add(x.Category);
             SelectedCategory = x.Category;
         }
     });
 }
        public async Task <ActionResult <CategoryResponse> > SaveCategory([FromBody] NewCategoryRequest request)
        {
            if (request == null)
            {
                return(BadRequest());
            }

            var newCategory = request.ToNew();

            var savedCategory = await categoryRepository.Insert(newCategory).ConfigureAwait(false);

            return(Created(nameof(SaveCategory), CategoryResponse.Of(savedCategory)));
        }
Ejemplo n.º 3
0
        public async Task Should_AddCategory_With_Name()
        {
            var expected           = "Name";
            var newCategoryRequest = new NewCategoryRequest
            {
                Name = expected
            };

            var category = await _newCategoryHandler.Handle(newCategoryRequest, CancellationToken.None);

            Assert.IsNotNull(category.CategoryId);
            Assert.IsNull(category.ParentCategory);
            Assert.AreEqual(expected, category.Name);

            category = await _context.Categories.FindAsync(category.CategoryId);

            Assert.IsNull(category.ParentCategory);
            Assert.AreEqual(expected, category.Name);
        }