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);
            }
        }
示例#2
0
        /// <summary>
        /// This method is responsible for handling the deletion of a timespan from the system
        /// </summary>
        /// <param name="id">The SpanID of the timespan to be deleted</param>
        /// <returns>A response indicating success or failure</returns>
        public DeleteTimeSpanResponse DeleteTimeSpan(int id)
        {
            DeleteTimeSpanResponse response = new DeleteTimeSpanResponse();

            try
            {
                var dataLayer = new HelpdeskDataLayer();

                bool result = dataLayer.DeleteTimeSpan(id);

                if (result == false)
                {
                    throw new NotFoundException("Unable to find timespan with id " + id);
                }

                response.Status = HttpStatusCode.OK;
            }
            catch (NotFoundException ex)
            {
                s_logger.Warn($"Unable to find the timespan with id [{id}]");
                response.Status = HttpStatusCode.NotFound;
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to delete the timespan.");
                response.Status = HttpStatusCode.InternalServerError;
            }

            return(response);
        }
        public void DeleteTimespanNotFound()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            DeleteTimeSpanResponse deleteResponse = helpdeskFacade.DeleteTimeSpan(-1);

            Assert.AreEqual(HttpStatusCode.OK, deleteResponse.Status);
        }