public void Delete_Success_ReturnNull() { // Arrange var repository = new ManufacturerRepository(); var input = repository.Create(GenerateInput()); // Act repository.Delete(input.Id); var result = repository.Get(input.Id); // Assert Assert.IsNull(result); }
public void Delete_EntityIsNull_ShouldReturnNotFoundStatusCode() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("96821ACB-9710-424C-8244-AA77F3472FE8").Options; using (var context = new ApplicationDbContext(options)) using (var manufacturersRepository = new ManufacturerRepository(context)) { var result = manufacturersRepository.Delete(1); Assert.NotNull(result); Assert.Equal((int)HttpStatusCode.NotFound, result.StatusCode); } }
public void Delete_ExceptionThrownByRepo_ShouldReturnInternalServerErrorAndNull() { Mock <ApplicationDbContext> mock = new Mock <ApplicationDbContext>(new DbContextOptions <ApplicationDbContext>()); mock.Object.Manufacturers = GetQueryableMockDbSet <Manufacturer>(); using (var manufacturersRepository = new ManufacturerRepository(mock.Object)) { var result = manufacturersRepository.Delete(It.IsAny <int>()); Assert.NotNull(result); Assert.Null(result.Data); Assert.Equal((int)HttpStatusCode.InternalServerError, result.StatusCode); } }
public IActionResult OnPostDelete(int id) { ManufacturerRepository manufacturerRepository = new ManufacturerRepository(); try { manufacturerRepository.Delete(id); } catch (Exception) { Message = "The try to delete manufacturer was incorrect!"; IsWarningMessage = true; } return(RedirectToPage()); }
public void Delete_SuccessfulDelete_ShouldReturnNoContentStatusCodeAndNull() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("96821ACB-9710-424C-8244-AA77F3472FE8").Options; using (var context = new ApplicationDbContext(options)) { context.AddRange(_manufacturers); context.SaveChanges(); } using (var context = new ApplicationDbContext(options)) using (var manufacturersRepository = new ManufacturerRepository(context)) { var result = manufacturersRepository.Delete(1); Assert.NotNull(result); Assert.Null(result.Data); Assert.Equal((int)HttpStatusCode.NoContent, result.StatusCode); } }
public bool DeleteManufacturer(Manufacturer manufacturer) { return(_manufacturerRepository.Delete(manufacturer.Id)); }
public ActionResult Delete(int id) { repo.Delete(id); return(RedirectToAction("Index")); }
public void Delete(int id) { manufacturerRepository.Delete(id); }
public ActionResult Delete_Manufacturer(int id) { manufacturerRepository.Delete(id); return(RedirectToAction("Index")); }