public void CustomCategoryMustHaveOwner() { var newCategory = ExpensesTrackerFactory.CustomCategory("Coffee", string.Empty); var validation = _DomainService.IsValidNewCustomCategory(newCategory, null); Assert.IsFalse(validation.IsValid()); Assert.AreEqual(Messages.CustomCategoriesMustHaveOwner, validation.ValidationErrorMessage); }
internal async Task <ActionResult <NewCategoryResponse> > CreateCustomCategory(ExpenseCategoryRequest request) { var userId = request.UserId; var categories = await _context.ExpenseCategory.Where(c => c.IsDefault || c.OwnerId == userId).ToListAsync(); var newCategory = ExpensesTrackerFactory.CustomCategory(request.CategoryName, userId); var validation = _domainService.IsValidNewCustomCategory(newCategory, categories); if (validation.IsValid()) { _context.ExpenseCategory.Add(newCategory); int result = await _context.SaveChangesAsync(); return(new NewCategoryResponse { CategoryId = newCategory.UId, UserId = newCategory.OwnerId }); } return(new NewCategoryResponse { ValidationMessage = validation.ValidationErrorMessage }); }