public void AdvertisementWithInvalidId_WhenDeleted_ThrowsExeption() { var service = new AdvertisementService(context); var ex = Assert.Throws <ArgumentException>(() => service.DeleteAdvertisement(1)); Assert.That(ex.Message, Is.EqualTo("Invalid advertisement id. (Parameter 'id')")); }
public async Task <IActionResult> DeleteAdvertisement([FromRoute] int id) { var advertisement = await AdvertisementService.DeleteAdvertisement(UserName, id); if (advertisement == null) { return(NotFound()); } return(Ok(advertisement)); }
public void Advertisement_CanBeDeleted() { context.Advertisements.Add(new Advertisement { Name = "Advertisement1", Description = "An advertisement for a job.", Active = true, JobPositionId = this.jobPositionId }); context.SaveChanges(); var service = new AdvertisementService(context); service.DeleteAdvertisement(1); Assert.AreEqual(0, context.Advertisements.Count()); }
public ActionResult Delete(int id) { AdvertisementViewModel advertisement = advertisementService.GetAdvertisementByID(id); if (advertisement == null) { return(HttpNotFound()); } advertisementService.DeleteAdvertisement(id); return(RedirectToAction("PartialViewBusinessandAdvertisement", "BusinessProfile", new { user = User.Identity.Name })); }
public IActionResult DeleteConfirmed(int id) { advertService.DeleteAdvertisement((int)id); return(RedirectToAction(nameof(Index))); }