public void Rename_Category() { string initialName = "test"; ExecuteCommand(new AddCategoryCommand(null, initialName)); var category = Session.QueryOver<Category>().Where(c => c.Name == initialName).SingleOrDefault(); string newName = "newName"; var renameCategoryCommand = new RenameCategoryCommand(category.Id, newName); ExecuteCommand(renameCategoryCommand); var renamedCategory = Session.QueryOver<Category>().Where(c => c.Id == category.Id).SingleOrDefault(); Assert.AreEqual(newName, renamedCategory.Name); }
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); }
public void Rename_Category() { string initialName = "test"; ExecuteCommand(new AddCategoryCommand(null, initialName)); var category = Session.QueryOver <Category>().Where(c => c.Name == initialName).SingleOrDefault(); string newName = "newName"; var renameCategoryCommand = new RenameCategoryCommand(category.Id, newName); ExecuteCommand(renameCategoryCommand); var renamedCategory = Session.QueryOver <Category>().Where(c => c.Id == category.Id).SingleOrDefault(); Assert.AreEqual(newName, renamedCategory.Name); }
public async Task <CommandResult> Handle(RenameCategoryCommand request, CancellationToken cancellationToken) { try { var category = new Category { Id = request.CategoryId }; _context.Attach(category); _mapper.Map(request, category); await _context.SaveChangesAsync(cancellationToken); return(CommandResult.Success(request.CategoryId)); } catch (Exception e) { return(CommandResult.Error(new RenameCategoryException("There was an error when trying to rename the category.", e))); } }