public async Task Given_existing_id_When_Delete_it_removes_superhero_and_returns_Deleted() { var result = await _repository.Delete(1); Assert.Null(_context.Superheroes.Find(1)); Assert.Equal(Deleted, result); }
public void Given_existing_id_When_Delete_it_removes_hero_and_returns_Deleted() { // Act var result = _repository.Delete(1); // Assert Assert.Null(_context.Superheroes.Find(1)); Assert.Equal(Deleted, result); }
public void Delete_deletes() { var response = _repository.Delete(8); Assert.Equal(Deleted, response); Assert.Null(_context.Superheroes.Find(8)); }
public void Given_existing_id_when_Delete_it_returns_Deleted() { var entity = new Superhero(); var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(entity); var repository = new SuperheroRepository(context.Object); var result = repository.Delete(42); Assert.Equal(Deleted, result); }
public void Given_existing_id_when_Delete_it_saves_changes() { var entity = new Superhero(); var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(entity); var repository = new SuperheroRepository(context.Object); repository.Delete(42); context.Verify(s => s.SaveChanges()); }
public void Delete_given_id_when_not_does_not_exist_returns_NotFound() { // Arrange var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(default(Superhero)); var repository = new SuperheroRepository(context.Object); // Act var response = repository.Delete(42); // Assert Assert.Equal(NotFound, response); }
public void Delete_given_id_when_not_does_not_exist_does_not_call_SaveChanges() { // Arrange var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(default(Superhero)); var repository = new SuperheroRepository(context.Object); // Act repository.Delete(42); // Assert context.Verify(c => c.SaveChanges(), Times.Never); }
public void Delete_given_id_when_exists_returns_Deleted() { // Arrange var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(new Superhero()); var repository = new SuperheroRepository(context.Object); // Act var response = repository.Delete(42); // Assert Assert.Equal(Deleted, response); }
public void Delete_given_existing_id_calls_SaveChanges() { // Arrange var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(new Superhero()); var repository = new SuperheroRepository(context.Object); // Act repository.Delete(42); // Assert context.Verify(c => c.SaveChanges()); }
public void Delete_given_existing_entity_removes_it() { // Arrange var hero = new Superhero(); var context = new Mock <ISuperheroContext>(); context.Setup(s => s.Superheroes.Find(42)).Returns(hero); var repository = new SuperheroRepository(context.Object); // Act repository.Delete(42); // Assert context.Verify(c => c.Superheroes.Remove(hero)); }
public ActionResult Delete(int id) { Superhero superhero = superheroRepository.GetSuperhero(id); if (superhero == null) { return(View("NotFound")); } else { superheroRepository.Delete(superhero); superheroRepository.Save(); var superheroes = superheroRepository.FindAllSuperheroes(); return(View("Index", superheroes)); } }