示例#1
0
            public void ValidationSucceeds()
            {
                UpdateExpenseInfo command = new UpdateExpenseInfo()
                {
                    expenseId = 1
                };

                List <ValidationResult> results = updateExpenseValidator.Validate(command).ToList();

                // Assert
                Assert.Empty(results);
            }
示例#2
0
            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);
            }
示例#3
0
        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."));
        }