public void RemoveValidItemShouldRemoveItTest() { var timeZoneService = new TimeZoneService(new MockTimeZoneRepository()); timeZoneService.Add(GetMockTimeZone(1)); timeZoneService.Add(GetMockTimeZone(2)); timeZoneService.Add(GetMockTimeZone(3)); Assert.IsNotNull(timeZoneService.GetByID(1)); timeZoneService.Remove(1); Assert.IsNull(timeZoneService.GetByID(1)); }
// DELETE api/<controller>/5 public IHttpActionResult Delete(int id) { try { var timeZoneService = new TimeZoneService(new TimeZoneRepository()); TimeZoneDTO timeZone = timeZoneService.GetByID(id); if (!User.IsInRole("Admin") && (timeZone.Owner != User.Identity.Name)) { return(Unauthorized()); } timeZoneService.Remove(id); return(Ok(HttpStatusCode.NoContent)); } catch (Exception e) { return(InternalServerError(e)); } }