Exemplo n.º 1
0
        public void SetupTests()
        {
            _category = new Category()
            {
                Label = "TestCommand"
            };

            _createCategoryCommand = new CreateCategoryCommand("TestCommand");
            _renameCategoryCommand = new RenameCategoryCommand(Guid.NewGuid(), "TestCommand2");
            _deleteCategoryCommand = new ArchiveCategoryCommand(Guid.NewGuid());

            SetupContextMock();
            SetupMapperMock();

            _categoryService = new CategoryService(_context, _mapper);
        }
Exemplo n.º 2
0
        public async Task <CommandResult> Handle(ArchiveCategoryCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var category = new Category {
                    Id = request.CategoryId
                };
                _context.Attach(category);

                // We don't really want to delete the category from the database,
                // because that would break all already existing references.
                category.IsArchived = true;

                await _context.SaveChangesAsync(cancellationToken);

                return(CommandResult.Success());
            }
            catch (Exception e)
            {
                return(CommandResult.Error(new DeleteCategoryException("There was an error when trying to delete the category.", e)));
            }
        }
Exemplo n.º 3
0
 public Task ArchiveCategory(ArchiveCategoryCommand command, CancellationToken token)
 => HandlerDispatcher.Invoke <ArchiveCategoryHandler, ArchiveCategoryCommand>(command, token);