public IActionResult GetQueueItemsByHelpdeskID([FromRoute] int id)
        {
            try
            {
                var facade   = new QueueFacade();
                var response = facade.GetQueueItemsByHelpdeskID(id);

                switch (response.Status)
                {
                case HttpStatusCode.OK:
                    return(Ok(response));

                case HttpStatusCode.BadRequest:
                    return(BadRequest(BuildBadRequestMessage(response)));

                case HttpStatusCode.NotFound:
                    return(NotFound());

                case HttpStatusCode.InternalServerError:
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
                s_logger.Fatal("This code should be unreachable, unknown result has occured.");
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to get queue items.");
            }
            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
        public IActionResult AddToQueue([FromBody] AddToQueueRequest request)
        {
            try
            {
                var facade   = new QueueFacade();
                var response = facade.AddToQueue(request);

                switch (response.Status)
                {
                case HttpStatusCode.OK:
                    return(Ok(response));

                case HttpStatusCode.BadRequest:
                    return(BadRequest(BuildBadRequestMessage(response)));

                case HttpStatusCode.NotFound:
                    return(NotFound());

                case HttpStatusCode.InternalServerError:
                    return(StatusCode(StatusCodes.Status500InternalServerError));
                }
                s_logger.Fatal("This code should be unreachable, unknown result has occured.");
            }
            catch (Exception ex)
            {
                s_logger.Error(ex, "Unable to add queue item.");
            }
            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
        public void JoinInvalidCheckNotFound()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = true,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            Topic topic = new Topic()
            {
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.Unit.Add(unit);
                context.SaveChanges();

                Helpdeskunit helpdeskunit = new Helpdeskunit()
                {
                    HelpdeskId = helpdesk.HelpdeskId,
                    UnitId     = unit.UnitId
                };

                context.Helpdeskunit.Add(helpdeskunit);

                context.SaveChanges();

                topic.UnitId = unit.UnitId;
                context.Topic.Add(topic);
                context.SaveChanges();
            }

            AddToQueueRequest request = new AddToQueueRequest()
            {
                TopicID     = topic.TopicId,
                Nickname    = AlphaNumericStringGenerator.GetString(10),
                SID         = AlphaNumericStringGenerator.GetStudentIDString(),
                CheckInID   = -100,
                Description = "JoinInvalidCheckNotFound Test"
            };

            QueueFacade facade = new QueueFacade();

            AddToQueueResponse response = facade.AddToQueue(request);

            Assert.AreEqual(HttpStatusCode.NotFound, response.Status);
        }
        public void GetQueueItemsByHelpdeskIDNoHelpdesk()
        {
            QueueFacade facade = new QueueFacade();

            GetQueueItemsByHelpdeskIDResponse testResponse = facade.GetQueueItemsByHelpdeskID(-1);

            Assert.AreEqual(HttpStatusCode.NotFound, testResponse.Status);
        }
예제 #5
0
 public TestEntityFactory()
 {
     HelpdeskFacade = new HelpdeskFacade();
     UnitsFacade    = new UnitsFacade();
     TopicsFacade   = new TopicsFacade();
     QueueFacade    = new QueueFacade();
     CheckInFacade  = new CheckInFacade();
     StudentFacade  = new StudentFacade();
 }
예제 #6
0
        public TestDataQueue AddQueueItem(int?studentID = null, int?topicID = null, int?checkInID = null, string nickname = "", string sID = "", string description = "")
        {
            var request = new AddToQueueRequest();

            if (studentID != null)
            {
                request.StudentID = studentID;
            }
            if (topicID != null)
            {
                request.TopicID = (int)topicID;
            }
            if (checkInID != null)
            {
                request.CheckInID = (int)checkInID;
            }
            if (nickname != null)
            {
                if (nickname == "" && PopulateEmptyStrings)
                {
                    request.Nickname = AlphaNumericStringGenerator.GetString(20);
                }
                else
                {
                    request.Nickname = nickname;
                }
            }
            if (sID != null)
            {
                if (sID == "" && PopulateEmptyStrings)
                {
                    request.SID = AlphaNumericStringGenerator.GetStudentIDString();
                }
                else
                {
                    request.SID = sID;
                }
            }
            if (description != null)
            {
                if (description == "" && PopulateEmptyStrings)
                {
                    request.Description = "From Test Factory";
                }
                else
                {
                    request.Description = description;
                }
            }

            var response = QueueFacade.AddToQueue(request);

            TestDataQueue data = new TestDataQueue(request, response);

            return(data);
        }
        public void UpdateQueueItemStatusBothTimesNull()
        {
            var request = new UpdateQueueItemStatusRequest
            {
                TimeHelped  = null,
                TimeRemoved = null
            };
            var queueFacade = new QueueFacade();
            var response    = queueFacade.UpdateQueueItemStatus(-1, request);

            // Check that a request containing both TimeHelped and TimeRemoved is rejected.
            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
        public void UpdateQueueItemDoesNotExist()
        {
            // Invalid topic id shouldn't matter, as QueueID will be assessed first in the data layer.
            var request = new UpdateQueueItemRequest
            {
                TopicID = -1
            };
            var queueFacade = new QueueFacade();
            var response    = queueFacade.UpdateQueueItem(-1, request);

            // Check that a request containing both TimeHelped and TimeRemoved is rejected.
            Assert.AreEqual(HttpStatusCode.NotFound, response.Status);
        }
        public void UpdateQueueItemStatusBothTimesNotNull()
        {
            DateTime timeHelped  = DateTime.Now;
            DateTime timeRemoved = timeHelped.AddMinutes(1);
            var      request     = new UpdateQueueItemStatusRequest {
                TimeHelped  = timeHelped,
                TimeRemoved = timeRemoved
            };
            var queueFacade = new QueueFacade();
            var response    = queueFacade.UpdateQueueItemStatus(-1, request);

            // Check that a request containing both TimeHelped and TimeRemoved is rejected.
            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
        public void UpdateQueueItemStatusDoesNotExist()
        {
            DateTime timeHelped = DateTime.Now;
            var      request    = new UpdateQueueItemStatusRequest
            {
                TimeHelped  = timeHelped,
                TimeRemoved = null
            };
            var queueFacade = new QueueFacade();
            var response    = queueFacade.UpdateQueueItemStatus(-1, request);

            // Check that a request containing both TimeHelped and TimeRemoved is rejected.
            Assert.AreEqual(HttpStatusCode.NotFound, response.Status);
        }
        public void JoinQueueInvalidTopicFail()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = true,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.Unit.Add(unit);
                context.SaveChanges();

                Helpdeskunit helpdeskunit = new Helpdeskunit()
                {
                    HelpdeskId = helpdesk.HelpdeskId,
                    UnitId     = unit.UnitId
                };

                context.Helpdeskunit.Add(helpdeskunit);

                context.SaveChanges();
            }

            AddToQueueRequest request = new AddToQueueRequest()
            {
                Nickname = AlphaNumericStringGenerator.GetString(10),
                SID      = AlphaNumericStringGenerator.GetStudentIDString(),
                TopicID  = 0
            };

            QueueFacade facade = new QueueFacade();

            AddToQueueResponse response = facade.AddToQueue(request);

            Assert.AreEqual(HttpStatusCode.BadRequest, response.Status);
        }
        public void GetQueueItemsByHelpdeskIDNoItems()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = false,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.SaveChanges();
            }

            QueueFacade facade = new QueueFacade();

            GetQueueItemsByHelpdeskIDResponse testResponse = facade.GetQueueItemsByHelpdeskID(helpdesk.HelpdeskId);

            Assert.AreEqual(HttpStatusCode.NotFound, testResponse.Status);
        }
        public void GetQueueItemsByHelpdeskID()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = false,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            Topic topic = new Topic()
            {
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.Unit.Add(unit);
                context.SaveChanges();

                Helpdeskunit helpdeskunit = new Helpdeskunit()
                {
                    HelpdeskId = helpdesk.HelpdeskId,
                    UnitId     = unit.UnitId
                };

                context.Helpdeskunit.Add(helpdeskunit);
                context.SaveChanges();

                topic.UnitId = unit.UnitId;
                context.Topic.Add(topic);
                context.SaveChanges();
            }

            AddToQueueRequest request = new AddToQueueRequest()
            {
                Nickname    = AlphaNumericStringGenerator.GetString(10),
                SID         = AlphaNumericStringGenerator.GetStudentIDString(),
                TopicID     = topic.TopicId,
                Description = "GetQueueItemsByHelpdeskID Test"
            };

            QueueFacade facade = new QueueFacade();

            AddToQueueResponse response = facade.AddToQueue(request);

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

            GetQueueItemsByHelpdeskIDResponse testResponse = facade.GetQueueItemsByHelpdeskID(helpdesk.HelpdeskId);

            Assert.AreEqual(HttpStatusCode.OK, testResponse.Status);
            var itemIds = testResponse.QueueItems.Select(i => i.ItemId).ToList();

            Assert.IsTrue(itemIds.Contains(response.ItemId));
        }
        public void JoinQueueNoCheckInNewStudent()
        {
            Helpdesksettings helpdesk = new Helpdesksettings()
            {
                HasQueue   = true,
                HasCheckIn = false,
                IsDeleted  = false,
                Name       = AlphaNumericStringGenerator.GetString(10),
            };

            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            Topic topic = new Topic()
            {
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Helpdesksettings.Add(helpdesk);
                context.Unit.Add(unit);
                context.SaveChanges();

                Helpdeskunit helpdeskunit = new Helpdeskunit()
                {
                    HelpdeskId = helpdesk.HelpdeskId,
                    UnitId     = unit.UnitId
                };

                context.SaveChanges();

                topic.UnitId = unit.UnitId;
                context.Topic.Add(topic);
                context.SaveChanges();
            }

            AddToQueueRequest request = new AddToQueueRequest()
            {
                Nickname    = AlphaNumericStringGenerator.GetString(10),
                SID         = AlphaNumericStringGenerator.GetStudentIDString(),
                TopicID     = topic.TopicId,
                Description = "JoinQueueNoCheckInNewStudent Test"
            };

            QueueFacade facade = new QueueFacade();

            AddToQueueResponse response = facade.AddToQueue(request);

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

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                Queueitem queueitem = context.Queueitem.FirstOrDefault(qi => qi.ItemId == response.ItemId);

                var baseTime = DateTime.Now.AddMinutes(-1);
                var addTime  = queueitem.TimeAdded;
                Assert.AreEqual(request.TopicID, queueitem.TopicId);
                var timeDiff = baseTime.CompareTo(addTime);
                Assert.IsTrue(timeDiff == -1);

                Nicknames nicknames = context.Nicknames.FirstOrDefault(n => n.StudentId == queueitem.StudentId);

                Assert.AreEqual(request.Nickname, nicknames.NickName);
                Assert.AreEqual(request.SID, nicknames.Sid);
            }
        }