public void ValidationSucceeds() { UpdateExpenseInfo command = new UpdateExpenseInfo() { expenseId = 1 }; List <ValidationResult> results = updateExpenseValidator.Validate(command).ToList(); // Assert Assert.Empty(results); }
public void ExpenseMustExist() { UpdateExpenseInfo command = new UpdateExpenseInfo() { expenseId = 0 }; List <ValidationResult> results = updateExpenseValidator.Validate(command).ToList(); // Assert Assert.NotEmpty(results); Assert.Single(results); Assert.Contains(new ValidationResult("ID", "No expense exists with the ID: 0"), results); }
public IActionResult Update(int id, [FromBody] UpdateExpenseInfo expenseToProcess) { if ((expenseToProcess.expenseId != 0) && (expenseToProcess.expenseId != id)) { // TODO - Throw an error as the IDs do not match. } expenseToProcess.expenseId = id; try { updateExpense.Handle(expenseToProcess); } catch (Exception e) { // TODO - Log exception return(new ExceptionActionResult(e)); } return(Ok("Expense updated successfully.")); }