public async void Store_Should_Return_Status_201() { var viewModel = new StoreUserViewModel { Name = "Flavio", Email = "*****@*****.**", Password = "******" }; var response = await _controller.Store(viewModel); Assert.IsAssignableFrom <CreatedResult>(response); }
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)); }
public async void Store_Should_Exist_A_User_Into_Database() { var viewModel = new StoreUserViewModel { Name = "Flavio", Email = "*****@*****.**", Password = "******" }; await _controller.Store(viewModel); Assert.Collection(_context.Users, (user) => { Assert.Equal(1, user.Id); Assert.Equal(viewModel.Name, user.Name); Assert.Equal(viewModel.Email, user.Email); }); }