public async void Should_Exist_A_File() { 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", }; await _controller.Store(fileForm); await _context.Entry(user).ReloadAsync(); Assert.Collection(_context.Files, (it) => { Assert.Equal(fileForm.FileName, it.Name); Assert.NotNull(it.Path); Assert.Equal(it.Id, user.FileId); }); }
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_Account_Has_Been_Updated() { 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(); _accessor.HttpContext.User = new ClaimsPrincipal ( new ClaimsIdentity ( new Claim[] { new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()) } ) ); var viewModel = new UpdateAccountViewModel { Name = "Itaú", Type = "Corrente" }; _context.Entry(account).Reload(); await _controller.Update(account.Id, viewModel); Assert.Equal(viewModel.Name, account.Name); Assert.Equal(viewModel.Type, account.Type); }