public ActionResult Delete(int id) { var repository = new HeroRepository(); repository.Delete(id); return(Ok()); }
public async Task Delete_Hero() { // Arrange int result; Guid?id; using (var context = CreateDbContext("Delete_Hero")) { var createdHero = new Hero() { Age = 10, Name = "Izuku Midoriya", Nickname = "Deku", Individuality = "All for one", Team = "Team Midoriya", HeroType = Domain.Entities.Enums.HeroType.Student }; context.Set <Hero>().Add(createdHero); context.Set <Hero>().Add(new Hero() { Name = "Another Hero", HeroType = Domain.Entities.Enums.HeroType.Vigilante, Age = 17 }); await context.SaveChangesAsync(); id = createdHero.Id; //receive autogenerated guid to get the entity later } // Act using (var context = CreateDbContext("Delete_Hero")) { var repository = new HeroRepository(context); await repository.Delete(id.Value); result = await repository.SaveChangesAsync(); } // Assert result.Should().BeGreaterThan(0); result.Should().Be(1); // Simulate access from another context to verifiy that correct data was saved to database using (var context = CreateDbContext("Delete_Hero")) { (await context.Set <Hero>().FirstOrDefaultAsync(x => x.Id == id)).Should().BeNull(); (await context.Set <Hero>().ToListAsync()).Should().NotBeEmpty(); } }
public void Delete(int id) { HeroRepository.Delete(id); }