public async void Store_Should_Return_Status_201()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            var account = await Factory.Account(userId : user.Id);

            await _context.Accounts.AddAsync(account);

            await _context.SaveChangesAsync();

            _accessor.HttpContext.User = new ClaimsPrincipal
                                         (
                new ClaimsIdentity
                (
                    new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
            }
                )
                                         );

            var viewModel = new StoreRevenueViewModel
            {
                Description = "Supermarket",
                Value       = 500,
                Date        = DateTime.Now.AddDays(-2)
            };

            var result = await _controller.Store(account.Id, viewModel);

            Assert.IsAssignableFrom <OkObjectResult>(result);
        }
        public async void Store_Should_Exist_Revenue_Into_Database()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            var account = await Factory.Account(userId : user.Id);

            await _context.Accounts.AddAsync(account);

            await _context.SaveChangesAsync();

            _accessor.HttpContext.User = new ClaimsPrincipal
                                         (
                new ClaimsIdentity
                (
                    new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString())
            }
                )
                                         );

            var viewModel = new StoreRevenueViewModel
            {
                Description = "Supermarket",
                Value       = 500,
                Date        = DateTime.Now.AddDays(-2)
            };

            await _controller.Store(account.Id, viewModel);

            Assert.Collection(_context.Revenues,
                              (it) =>
            {
                Assert.Equal(viewModel.Description, it.Description);
                Assert.Equal(viewModel.Value, it.Value);
                Assert.Equal(viewModel.Date, it.Date);
            });
        }
Exemple #3
0
        public async Task <IActionResult> Store([FromRoute] int accountId, [FromBody] StoreRevenueViewModel viewModel)
        {
            var user = await _auth.User();

            var account = await(from current in _context.Accounts
                                where current.Id == accountId && current.UserId == user.Id
                                select current).FirstAsync();

            var revenue = new Revenue
            {
                Account     = account,
                Description = viewModel.Description,
                Value       = viewModel.Value,
                Date        = viewModel.Date
            };

            await _context.Revenues.AddAsync(revenue);

            await _context.SaveChangesAsync();

            var response = new ResponseViewModel <int>(revenue.Id);

            return(Ok(response));
        }