コード例 #1
0
        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
        public IActionResult AddTimeSpan([FromBody] AddTimeSpanRequest request)
        {
            if (!IsAuthorized())
            {
                return(Unauthorized());
            }

            try
            {
                var facade   = new HelpdeskFacade();
                var response = facade.AddTimeSpan(request);

                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 add timespan.");
            }
            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
コード例 #3
0
        public void UpdateTimespanNoName()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

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

            AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest);

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

            UpdateTimeSpanRequest updateTimespanRequest = new UpdateTimeSpanRequest()
            {
                StartDate = new DateTime(2019, 01, 01),
                EndDate   = new DateTime(2019, 06, 01),
            };

            UpdateTimeSpanResponse updateTimespanResponse = helpdeskFacade.UpdateTimeSpan(addTimeSpanResponse.SpanId, updateTimespanRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, updateTimespanResponse.Status);
        }
コード例 #4
0
        public TestDataTimeSpan AddTimeSpan(int?helpdeskID = null, string name = "", DateTime?startDate = null, DateTime?endDate = null)
        {
            var request = new AddTimeSpanRequest();

            if (helpdeskID != null)
            {
                request.HelpdeskId = (int)helpdeskID;
            }

            if (name == "" && PopulateEmptyStrings)
            {
                request.Name = AlphaNumericStringGenerator.GetString(10);
            }
            else
            {
                request.Name = name;
            }

            if (startDate == null)
            {
                request.StartDate = DateTime.Now;
            }

            if (endDate == null)
            {
                request.EndDate = DateTime.Now;
                request.EndDate.AddDays(1);
            }

            var response = HelpdeskFacade.AddTimeSpan(request);

            TestDataTimeSpan data = new TestDataTimeSpan(request, response);

            return(data);
        }
コード例 #5
0
        public void AddTimespanStartDatePredatesSystem()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            AddTimeSpanRequest addTimeSpanRequest = new AddTimeSpanRequest();

            addTimeSpanRequest.HelpdeskId = 1;
            addTimeSpanRequest.Name       = AlphaNumericStringGenerator.GetString(10);
            DateTime startDate = new DateTime(2018, 1, 1, 0, 0, 0);
            DateTime endDate   = DateTime.Today;

            addTimeSpanRequest.StartDate = startDate;
            addTimeSpanRequest.EndDate   = endDate;

            AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, addTimeSpanResponse.Status);
        }
コード例 #6
0
        public void AddTimespanEndBeforeStart()
        {
            HelpdeskFacade helpdeskFacade = new HelpdeskFacade();

            DateTime startDate = DateTime.Today;
            DateTime endDate   = startDate.AddYears(-1);

            AddTimeSpanRequest addTimeSpanRequest = new AddTimeSpanRequest
            {
                HelpdeskId = 1,
                Name       = AlphaNumericStringGenerator.GetString(10),
                StartDate  = startDate,
                EndDate    = endDate
            };

            AddTimeSpanResponse addTimeSpanResponse = helpdeskFacade.AddTimeSpan(addTimeSpanRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, addTimeSpanResponse.Status);
        }
コード例 #7
0
        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);
            }
        }