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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method is responsible for getting a specific timespan from the helpdesk system
        /// </summary>
        /// <param name="id">The SpanId of the specific timespan to be retrieved</param>
        /// <returns>The response that indicates if the operation was a success,
        /// and the details of the retrieved timespan if it was</returns>
        public GetTimeSpanResponse GetTimeSpan(int id)
        {
            s_logger.Info("Getting timespan...");

            GetTimeSpanResponse response = new GetTimeSpanResponse();

            try
            {
                var dataLayer = new HelpdeskDataLayer();

                TimeSpanDTO timespan = dataLayer.GetTimeSpan(id);
                response.Timespan = timespan ?? throw new NotFoundException("Unable to find timespan!");
                response.Status   = HttpStatusCode.OK;
            }
            catch (NotFoundException ex)
            {
                s_logger.Error(ex, "Unable to find timespan!");
                response.Status = HttpStatusCode.NotFound;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.NotFound, "Unable to find timespan!"));
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to get timespan!");
                response.Status = HttpStatusCode.InternalServerError;
                response.StatusMessages.Add(new StatusMessage(HttpStatusCode.InternalServerError, "Unable to get timespan!"));
            }
            return(response);
        }
        public void GetTimespanNotFound()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            GetTimeSpanResponse getTimespanResponse = helpdeskFacade.GetTimeSpan(-1);

            Assert.AreEqual(HttpStatusCode.NotFound, getTimespanResponse.Status);
        }
        public void GetTimespanFound()
        {
            AddHelpdeskRequest addHelpdeskRequest = new AddHelpdeskRequest
            {
                HasCheckIn = false,
                HasQueue   = true,
                Name       = AlphaNumericStringGenerator.GetString(10)
            };

            HelpdeskFacade      helpdeskFacade      = new HelpdeskFacade();
            AddHelpdeskResponse addHelpdeskResponse = helpdeskFacade.AddHelpdesk(addHelpdeskRequest);

            Assert.AreEqual(HttpStatusCode.OK, addHelpdeskResponse.Status);

            AddTimeSpanRequest addTimeSpanRequest = new AddTimeSpanRequest
            {
                HelpdeskId = addHelpdeskResponse.HelpdeskID,
                Name       = AlphaNumericStringGenerator.GetString(10),
                StartDate  = DateTime.Today,
                EndDate    = DateTime.Today.AddYears(1)
            };

            AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest);

            Assert.AreEqual(HttpStatusCode.OK, addTimeSpanResponse.Status);

            GetTimeSpanResponse getTimespanResponse = helpdeskFacade.GetTimeSpan(addTimeSpanResponse.SpanId);

            Assert.AreEqual(HttpStatusCode.OK, getTimespanResponse.Status);
            Assert.AreEqual(addTimeSpanRequest.Name, getTimespanResponse.Timespan.Name);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var timespan = context.Timespans.FirstOrDefault(t => t.SpanId == addTimeSpanResponse.SpanId);

                Assert.IsNotNull(timespan);
                Assert.AreEqual(addHelpdeskResponse.HelpdeskID, timespan.HelpdeskId);
                Assert.AreEqual(addTimeSpanRequest.Name, timespan.Name);
            }
        }