public async void Update_Should_Revenue_Has_Been_Updated() { var user = await Factory.User(); await _context.Users.AddAsync(user); var account = await Factory.Account(userId : user.Id); await _context.Accounts.AddAsync(account); var revenue = await Factory.Revenue(accountId : account.Id); await _context.Revenues.AddAsync(revenue); await _context.SaveChangesAsync(); _accessor.HttpContext.User = new ClaimsPrincipal ( new ClaimsIdentity ( new Claim[] { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()) } ) ); var viewModel = new UpdateRevenueViewModel { Description = "Supermarket", Value = 5000, Date = DateTime.Now.AddDays(-1) }; await _controller.Update(account.Id, revenue.Id, viewModel); await _context.Entry(revenue).ReloadAsync(); Assert.Equal(viewModel.Description, revenue.Description); Assert.Equal(viewModel.Value, revenue.Value); Assert.Equal(viewModel.Date, revenue.Date); }
public async void Update_Should_Return_Status_200() { var user = await Factory.User(); await _context.Users.AddAsync(user); var account = await Factory.Account(userId : user.Id); await _context.Accounts.AddAsync(account); var revenue = await Factory.Revenue(accountId : account.Id); await _context.Revenues.AddAsync(revenue); await _context.SaveChangesAsync(); _accessor.HttpContext.User = new ClaimsPrincipal ( new ClaimsIdentity ( new Claim[] { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()) } ) ); var viewModel = new UpdateRevenueViewModel { Description = "Supermarket", Value = 5000, Date = DateTime.Now.AddDays(-1) }; var result = await _controller.Update(account.Id, revenue.Id, viewModel); Assert.IsAssignableFrom <OkObjectResult>(result); }
public async Task <IActionResult> Update([FromRoute] int accountId, [FromRoute] int id, [FromBody] UpdateRevenueViewModel viewModel) { var user = await _auth.User(); var revenue = await(from current in _context.Revenues join account in _context.Accounts on current.AccountId equals account.Id where current.AccountId == accountId && current.Id == id && account.UserId == user.Id select current).FirstAsync(); revenue.Description = viewModel.Description; revenue.Value = viewModel.Value; revenue.Date = viewModel.Date; await _context.SaveChangesAsync(); var response = new ResponseViewModel <int>(revenue.Id); return(Ok(response)); }