Exemplo n.º 1
0
        /// <summary>
        /// Used to add a queue item to the database
        /// </summary>
        /// <param name="request">The request with the information to be added</param>
        /// <returns>The id of the queue item or null if not successful</returns>
        public int AddToQueue(AddToQueueRequest request)
        {
            int?id = null;

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                Queueitem item = new Queueitem()
                {
                    StudentId   = request.StudentID.Value,
                    TimeAdded   = DateTime.Now,
                    TopicId     = request.TopicID,
                    Description = request.Description,
                };

                context.Queueitem.Add(item);
                context.SaveChanges();

                id = item.ItemId;

                if (request.CheckInID.HasValue)
                {
                    Checkinhistory checkinhistory = context.Checkinhistory.FirstOrDefault(ci => ci.CheckInId == request.CheckInID.Value);

                    if (checkinhistory == null)
                    {
                        throw new NotFoundException($"Unable to find queue item with id [{request.CheckInID.Value}]");
                    }

                    Checkinqueueitem checkinqueueitem = new Checkinqueueitem()
                    {
                        CheckInId   = request.CheckInID.Value,
                        QueueItemId = item.ItemId,
                    };

                    context.Checkinqueueitem.Add(checkinqueueitem);
                }

                context.SaveChanges();
            }

            return(id.Value);
        }
Exemplo n.º 2
0
        public void CheckOutWithQueueItems()
        {
            Unit unit = new Unit()
            {
                Code      = AlphaNumericStringGenerator.GetString(8),
                IsDeleted = false,
                Name      = AlphaNumericStringGenerator.GetString(10),
            };

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

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Unit.Add(unit);
                topic.UnitId = unit.UnitId;
                context.Topic.Add(topic);
                context.SaveChanges();
            }

            CheckInRequest request = new CheckInRequest()
            {
                UnitID   = unit.UnitId,
                Nickname = AlphaNumericStringGenerator.GetString(10),
                SID      = AlphaNumericStringGenerator.GetStudentIDString()
            };

            CheckInFacade facade = new CheckInFacade();

            CheckInResponse response = facade.CheckIn(request);

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

            Queueitem queueitem = new Queueitem()
            {
                StudentId   = response.StudentID,
                TopicId     = topic.TopicId,
                Description = "Check In Unit Test",
                TimeAdded   = DateTime.Now
            };



            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Queueitem.Add(queueitem);

                Checkinqueueitem checkinqueueitem = new Checkinqueueitem()
                {
                    CheckInId   = response.CheckInID,
                    QueueItemId = queueitem.ItemId
                };
                context.Checkinqueueitem.Add(checkinqueueitem);

                context.SaveChanges();
            }

            CheckOutRequest coRequest = new CheckOutRequest()
            {
                ForcedCheckout = false
            };

            CheckOutResponse coResponse = facade.CheckOut(coRequest, response.CheckInID);

            Assert.AreEqual(HttpStatusCode.OK, coResponse.Status);
            Assert.IsTrue(coResponse.Result);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                Checkinhistory checkOut = context.Checkinhistory.FirstOrDefault(co => co.CheckInId == response.CheckInID);
                Queueitem      item     = context.Queueitem.FirstOrDefault(qi => qi.ItemId == queueitem.ItemId);

                Assert.IsNotNull(checkOut);

                var baseTime = DateTime.Now.AddMinutes(-1);
                var addTime  = checkOut.CheckoutTime;
                var timeDiff = baseTime.CompareTo(addTime);
                Assert.IsTrue(timeDiff == -1);

                Assert.AreEqual(coRequest.ForcedCheckout, checkOut.ForcedCheckout);

                Assert.IsNotNull(item);

                var baseQueueTime   = DateTime.Now.AddMinutes(-1);
                var removeQueueTime = item.TimeRemoved;
                var queueTimeDiff   = baseQueueTime.CompareTo(removeQueueTime);
                Assert.IsTrue(queueTimeDiff == -1);
            }
        }
        public void JoinQueueCheckInOldStudent()
        {
            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),
            };

            Checkinhistory checkin = new Checkinhistory()
            {
                CheckInTime = DateTime.Now,
            };

            Nicknames nickname = new Nicknames()
            {
                NickName = AlphaNumericStringGenerator.GetString(10),
                Sid      = AlphaNumericStringGenerator.GetStudentIDString()
            };

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

                checkin.StudentId = nickname.StudentId;
                checkin.UnitId    = unit.UnitId;

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

                context.Helpdeskunit.Add(helpdeskunit);

                checkin.UnitId = unit.UnitId;
                context.Checkinhistory.Add(checkin);

                context.SaveChanges();

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

            AddToQueueRequest request = new AddToQueueRequest()
            {
                StudentID   = nickname.StudentId,
                TopicID     = topic.TopicId,
                CheckInID   = checkin.CheckInId,
                Description = "JoinQueueCheckInOldStudent 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);

                Checkinqueueitem checkinqueueitem = context.Checkinqueueitem.FirstOrDefault(cqi => cqi.CheckInId == checkin.CheckInId && cqi.QueueItemId == queueitem.ItemId);
                Assert.IsNotNull(checkinqueueitem);
            }
        }