コード例 #1
0
        public async Task <bool> UpdateExpense(int id, ExpenseUpdateDto expenseUpdate)
        {
            var expense = await this.GetExpense(id);

            _mapper.Map(expenseUpdate, expense);
            return(await SaveAll());
        }
コード例 #2
0
        public async Task <IActionResult> PutExpense(int id, ExpenseUpdateDto expenseUpdate)
        {
            /*if (id != expenseUpdate.Id)
             * {
             *  return BadRequest();
             * }
             * var expense = await _repo.GetExpense(id);
             * _mapper.Map(expenseUpdate, expense);
             * if (await _repo.SaveAll())
             *  return NoContent();*/
            await _repo.UpdateExpense(id, expenseUpdate);

            return(NoContent());


            throw new Exception($"Updating expemse {id} failed on save");
        }
コード例 #3
0
        public async Task  PutExpense_WhenCalled_UpdatesExpense()
        {
            var repo       = new Mock <IExpenseRepository>();
            var mapper     = new Mock <IMapper>();
            var controller = new ExpensesController(mapper.Object, repo.Object);
            var expense    = new ExpenseUpdateDto()
            {
                Id            = 17,
                Type          = "A",
                Amount        = 500,
                IncurredDate  = new DateTime(2020, 09, 15),
                SubmitterName = "rajendra",
                Receipts      = null
            };

            var res = await controller.PutExpense(17, expense);

            repo.Verify(r => r.UpdateExpense(17, expense));
        }