public void Delete_ExistingClient() { var client = GetClient(); var clientsInMemory = new List <Client> { client }; var mockDbSet = new Mock <DbSet <Client> >(); PrepareQueryableMock(clientsInMemory, mockDbSet); //mocking add method mockDbSet.Setup(m => m.Remove(It.IsAny <Client>())) .Returns(() => client) .Callback(() => clientsInMemory.Remove(client)); var dbContext = new ClientsApiDbContext { Clients = mockDbSet.Object }; var repo = new ClientsRepository(dbContext); repo.Delete(client.CPF); Assert.IsTrue(clientsInMemory.Count == 0); }
public ActionResult Delete(int id) { _clientRepo.Delete(id); TempData["Message"] = "The client was successfully deleted!"; return(RedirectToAction("Index")); }
private void DeleteTest() { using (var context = new Context()) { var clientsRepository = new ClientsRepository(context); context.Database.Log = (message) => Debug.WriteLine(message); var downloadedClient = clientsRepository.Get(_clientDataMock.ClientId, false); var id = downloadedClient.ClientId; Assert.IsNotNull(downloadedClient, "Client does not exist before delete."); clientsRepository.Delete(downloadedClient); downloadedClient = clientsRepository.Get(id, false); Assert.IsNull(downloadedClient, "Client exists after delete."); } }
public ActionResult Delete(int clientId) { if (clientId <= 0) { return(BadRequest(_translationService.Translate(Request.Headers, "EC6"))); } try { _clientsRepository.Delete(clientId); _clientsRepository.SaveChanges(); } catch (Exception ex) { return(BadRequest(_translationService.TranslateException(ex, Request.Headers))); } return(Ok(clientId)); }
private void DeleteClient_Click(object sender, EventArgs e) { Client client = (Client)ClientsDataGrid.CurrentRow.DataBoundItem; if (!client.Id.HasValue) { throw new ApplicationException("Delete event: Client id not defined!"); } var confirmResult = MessageBox.Show($"Are you sure to delete client {client.Name}?", "Delete confirm", MessageBoxButtons.YesNo); if (confirmResult == DialogResult.Yes) { _clientsRepository.Delete(client.Id.Value); FillGrids(); } }
// POST: Clients/Delete/5 public async Task <int> DeleteConfirmed(int id) { return(await _repository.Delete(id)); }