public void AddHelpdeskNoName()
        {
            var request = new AddHelpdeskRequest()
            {
                HasCheckIn = false,
                HasQueue   = true
            };

            var facade   = new HelpdeskFacade();
            var response = facade.AddHelpdesk(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
        public void UpdateHelpdesk()
        {
            var request = new AddHelpdeskRequest()
            {
                HasCheckIn = false,
                HasQueue   = true,
                Name       = AlphaNumericStringGenerator.GetString(10)
            };

            var facade   = new HelpdeskFacade();
            var response = facade.AddHelpdesk(request);

            Assert.AreEqual(HttpStatusCode.OK, response.Status);
            Assert.IsTrue(response.HelpdeskID > 0);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var helpdesk = context.Helpdesksettings.FirstOrDefault(p => p.HelpdeskId == response.HelpdeskID);

                Assert.IsNotNull(helpdesk);
            }

            var updateRequest = new UpdateHelpdeskRequest()
            {
                HasCheckIn = true,
                HasQueue   = true,
                Name       = AlphaNumericStringGenerator.GetString(10)
            };

            var updateResponse = facade.UpdateHelpdesk(response.HelpdeskID, updateRequest);

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

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var helpdesk = context.Helpdesksettings.FirstOrDefault(p => p.HelpdeskId == response.HelpdeskID);

                Assert.IsNotNull(helpdesk);
                Assert.AreEqual(updateRequest.HasCheckIn, helpdesk.HasCheckIn);
                Assert.AreEqual(updateRequest.HasQueue, helpdesk.HasQueue);
                Assert.AreEqual(updateRequest.Name, helpdesk.Name);
            }
        }
        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);
            }
        }
        public IActionResult AddHelpdesk([FromBody] AddHelpdeskRequest request)
        {
            if (!IsAuthorized())
            {
                return(Unauthorized());
            }

            if (request == null)
            {
                return(BadRequest());
            }

            try
            {
                var facade   = new HelpdeskFacade();
                var response = facade.AddHelpdesk(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 helpdesk.");
            }
            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a test helpdesk in the database.
        /// </summary>
        /// <param name="name">Name of the Helpdesk (auto-generates if not provided, or empty string is provided).</param>
        /// <param name="hasCheckin">Determines if the helpdesk utilises the check-in/check-out functionality.</param>
        /// <param name="hasQueue">Determines if the helpdesk utilises the queue functionality.</param>
        /// <returns></returns>
        public TestDataHelpdesk AddHelpdesk(string name = "", bool?hasCheckin = true, bool?hasQueue = true)
        {
            var request = new AddHelpdeskRequest();

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

            request.Name = string.IsNullOrEmpty(name) && PopulateEmptyStrings?AlphaNumericStringGenerator.GetString(10) : name;

            request.HasCheckIn = (bool)hasCheckin;
            request.HasQueue   = (bool)hasQueue;

            var response = HelpdeskFacade.AddHelpdesk(request);

            TestDataHelpdesk data = new TestDataHelpdesk(request, response);

            return(data);
        }