Beispiel #1
0
        public async void Store_Should_Return_Status_201()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

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

            var filePath = Path.Join(Directory.GetCurrentDirectory(), "Fixtures", "avatar.png");

            using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            var fileForm = new FormFile(fileStream, 0, fileStream.Length, "file", "avatar.png")
            {
                Headers            = new HeaderDictionary(),
                ContentDisposition = "form-data; name=\"file\"; filename=\"avatar.png\"",
                ContentType        = "image/png",
            };

            var result = await _controller.Store(fileForm);

            Assert.IsAssignableFrom <OkObjectResult>(result);
        }
Beispiel #2
0
        public async void Show_Should_Return_Status_200()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

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

            await _context.Accounts.AddAsync(account);

            await _context.SaveChangesAsync();

            var pay = await Factory.Revenue(accountId : account.Id, value : 280000);

            await _context.Revenues.AddAsync(pay);

            await _context.SaveChangesAsync();

            _accessor.HttpContext.User = await Factory.ClaimsPrincipal(userId : user.Id);

            var start = new DateTime(year: 2019, month: 12, day: 1);

            var end = new DateTime(year: 2019, month: 12, day: 31);

            var result = await _controller.Show(start, end);

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

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

            _accessor.HttpContext.User = await Factory.ClaimsPrincipal(userId : user.Id);

            var result = await _controller.Show();

            Assert.IsAssignableFrom <OkObjectResult>(result);
        }
        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 Task <IActionResult> Store([FromBody] StoreTransferViewModel viewModel)
        {
            var output = new Output
            {
                Description = viewModel.Description,
                Value       = -viewModel.Value,
                Date        = viewModel.Date,
                ToId        = viewModel.ToId,
                FromId      = viewModel.FromId
            };

            var input = new Input
            {
                Description = viewModel.Description,
                Value       = viewModel.Value,
                Date        = viewModel.Date,
                ToId        = viewModel.ToId,
                FromId      = viewModel.FromId
            };

            await _context.Outputs.AddAsync(output);

            await _context.Inputs.AddAsync(input);

            await _context.SaveChangesAsync();

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

            return(Created($"transfer/{output.Id}", response));
        }
Beispiel #6
0
        public async Task <IActionResult> Store([FromBody] StoreAccountViewModel viewModel)
        {
            var user = await _auth.User();

            var account = new Account
            {
                Name = viewModel.Name,
                Type = viewModel.Type,
                User = user
            };

            await _context.Accounts.AddAsync(account);

            await _context.SaveChangesAsync();

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

            return(Created($"/account/{account.Id}", response));
        }
Beispiel #7
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));
        }
Beispiel #8
0
        public async Task <IActionResult> Store([FromBody] StoreUserViewModel viewModel)
        {
            var user = new User
            {
                Name         = viewModel.Name,
                Email        = viewModel.Email,
                PasswordHash = await _hash.Make(viewModel.Password)
            };

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

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

            return(Created($"/user/{user.Id}", response));
        }
Beispiel #9
0
        public async Task <IActionResult> Store(IFormFile formFile)
        {
            var user = await _auth.User();

            var path = await _storage.Move(formFile);

            var file = new File
            {
                Name = formFile.FileName,
                Path = path
            };

            await _context.Files.AddAsync(file);

            user.File = file;

            await _context.SaveChangesAsync();

            var response = new ResponseViewModel <string>(path);

            return(Ok(response));
        }
Beispiel #10
0
        public async void Store_Should_Return_Status_201()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

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

            await _context.Accounts.AddAsync(nubank);

            await _context.SaveChangesAsync();

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

            await _context.Accounts.AddAsync(itau);

            await _context.SaveChangesAsync();

            _accessor.HttpContext.User = await Factory.ClaimsPrincipal(userId : user.Id);

            var viewModel = new StoreTransferViewModel
            {
                Description = "Save money",
                Date        = new DateTime(year: 2019, month: 12, day: 25),
                Value       = 25000,
                ToId        = nubank.Id,
                FromId      = itau.Id
            };

            var result = await _controller.Store(viewModel);

            Assert.IsAssignableFrom <CreatedResult>(result);
        }
Beispiel #11
0
        public async void Index_Should_Return_Status_200()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

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

            var begin = new DateTime(year: 2019, month: 12, day: 1);

            var end = new DateTime(year: 2019, month: 12, day: 31);

            var result = await _controller.Index(begin, end);

            Assert.IsAssignableFrom <OkObjectResult>(result);
        }
Beispiel #12
0
        public async void Store_Should_Return_Status_201()
        {
            var user = await Factory.User();

            await _context.Users.AddAsync(user);

            await _context.SaveChangesAsync();

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

            var viewModel = new StoreAccountViewModel
            {
                Name = "Caixa",
                Type = "Corrente"
            };

            var result = await _controller.Store(viewModel);

            Assert.IsAssignableFrom <CreatedResult>(result);
        }