public IActionResult DeleteTimeSpan([FromRoute] int id) { if (!IsAuthorized()) { return(Unauthorized()); } try { var facade = new HelpdeskFacade(); var response = facade.DeleteTimeSpan(id); switch (response.Status) { case HttpStatusCode.OK: return(Ok(response)); case HttpStatusCode.BadRequest: return(BadRequest(BuildBadRequestMessage(response))); case HttpStatusCode.InternalServerError: return(StatusCode(StatusCodes.Status500InternalServerError)); case HttpStatusCode.NotFound: return(NotFound()); } s_logger.Fatal("This code should be unreachable, unknown result has occured."); } catch (Exception ex) { s_logger.Error(ex, "Unable to delete timespan."); } return(StatusCode(StatusCodes.Status500InternalServerError)); }
public void DeleteTimespan() { HelpdeskFacade helpdeskFacade = new HelpdeskFacade(); AddTimeSpanRequest addTimeSpanRequest = new AddTimeSpanRequest() { HelpdeskId = 1, Name = AlphaNumericStringGenerator.GetString(10), StartDate = DateTime.Today, EndDate = DateTime.Today.AddYears(1) }; AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest); Assert.AreEqual(HttpStatusCode.OK, addTimeSpanResponse.Status); DeleteTimeSpanResponse deleteResponse = helpdeskFacade.DeleteTimeSpan(addTimeSpanResponse.SpanId); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.Status); GetTimeSpanResponse response = helpdeskFacade.GetTimeSpan(addTimeSpanResponse.SpanId); Assert.AreEqual(HttpStatusCode.NotFound, response.Status); using (helpdesksystemContext context = new helpdesksystemContext()) { var timespan = context.Timespans.FirstOrDefault(ts => ts.SpanId == addTimeSpanResponse.SpanId); Assert.IsNull(timespan); } }
public void DeleteTimespanNotFound() { HelpdeskFacade helpdeskFacade = new HelpdeskFacade(); DeleteTimeSpanResponse deleteResponse = helpdeskFacade.DeleteTimeSpan(-1); Assert.AreEqual(HttpStatusCode.OK, deleteResponse.Status); }