public void GetAllUnitsByHelpdeskID()
        {
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a deleted unit. ID provided is 0, which will indicates creation of new helpdesk.
            TestDataUnit unitData  = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, isDeleted: true);
            TestDataUnit unitData2 = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get all units that were just created.
            UnitsFacade unitsFacade = new UnitsFacade();
            GetUnitsByHelpdeskIDResponse getUnitsByHelpdeskIDResponse = unitsFacade.GetUnitsByHelpdeskID(helpdeskData.Response.HelpdeskID, false);

            Assert.AreEqual(HttpStatusCode.OK, getUnitsByHelpdeskIDResponse.Status);
            Assert.AreEqual(unitData.Request.Name, getUnitsByHelpdeskIDResponse.Units[0].Name);
            Assert.AreEqual(unitData2.Request.Name, getUnitsByHelpdeskIDResponse.Units[1].Name);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var helpdeskUnits = context.Helpdeskunit.ToList();

                Assert.IsNotNull(helpdeskUnits);
            }
        }
        public void AddUnitDupCode()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Attempt to create unit with duplicate name.
            unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", unitData.Request.Code, false, topics);

            // Check that duplicate name yields bad request.
            Assert.AreEqual(HttpStatusCode.BadRequest, unitData.Response.Status);
        }
        public void AddUnit()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                int confirmId = unitData.Response.UnitID;
                var unit      = context.Unit.Include("Topic").FirstOrDefault(u => u.UnitId == confirmId);
                Assert.IsNotNull(unit);
                Assert.IsTrue
                (
                    unitData.Request.IsDeleted == unit.IsDeleted &&
                    unitData.Request.Name == unit.Name &&
                    unitData.Request.Code == unit.Code &&
                    unitData.Request.Topics.Count + 1 == unit.Topic.Count &&
                    unit.Topic.Count > 0
                );
            }
        }
Пример #4
0
        public void GetTopicsByUnitID()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get all topics associated with the unit id.
            var topicsFacade = new TopicsFacade();
            GetTopicsByUnitIDResponse topicResponse = topicsFacade.GetTopicsByUnitID(unitData.Response.UnitID);

            // Check that the topics retrieved are correct.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(topicResponse.Topics.Count == 3);
        }
        public void AddTimespanNameExists()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Add timespan.
            TestDataTimeSpan timespanDataA = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID);

            // Check that timespan was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, timespanDataA.Response.Status);
            Assert.IsTrue(timespanDataA.Response.SpanId > 0);

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var timespan = context.Timespans.FirstOrDefault(t => t.SpanId == timespanDataA.Response.SpanId);
                Assert.IsNotNull(timespan);
            }

            // Try to add another timspan with the same name
            TestDataTimeSpan timespanDataB = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID, timespanDataA.Request.Name);

            // Check that timespan was not created due to duplicate name.
            Assert.AreEqual(HttpStatusCode.BadRequest, timespanDataB.Response.Status);
        }
        public void UpdateQueueItem()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get topics for the unit that was just created.
            TopicsFacade topicsFacade = new TopicsFacade();
            GetTopicsByUnitIDResponse topicResponse = topicsFacade.GetTopicsByUnitID(unitData.Response.UnitID);

            // Check that there are two units in the response (Layouts, Lifecycle).
            Assert.IsTrue(topicResponse.Topics.Count() == 3);

            // Add test queue item, pass in topic [0].
            TestDataQueue queueData = testEntityFactory.AddQueueItem(null, topicResponse.Topics[0].TopicId);

            // Check that queue item was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, queueData.Response.Status);

            // Create request to alter queue item.
            var queueUpdateRequest = new UpdateQueueItemRequest
            {
                TopicID     = topicResponse.Topics[0].TopicId,
                Description = "UpdateQueueItem Test"
            };

            // Update the queue item
            UpdateQueueItemResponse updateQueueResponse = testEntityFactory.QueueFacade.UpdateQueueItem(queueData.Response.ItemId, queueUpdateRequest);

            // Check that queue item was updated successfully.
            Assert.AreEqual(HttpStatusCode.OK, updateQueueResponse.Status);

            // Do another request to change to another topic
            queueUpdateRequest = new UpdateQueueItemRequest
            {
                TopicID     = topicResponse.Topics[1].TopicId,
                Description = "UpdateQueueItem Test 2"
            };

            // Update the queue item again
            updateQueueResponse = testEntityFactory.QueueFacade.UpdateQueueItem(queueData.Response.ItemId, queueUpdateRequest);

            // Check that queue item was updated successfully.
            Assert.AreEqual(HttpStatusCode.OK, updateQueueResponse.Status);
        }
        public void GetUnit()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            TestDataUnit unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID);

            Topic topic = new Topic()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                IsDeleted = false,
                UnitId    = unitData.Response.UnitID
            };
            Topic deletedTopic = new Topic()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                IsDeleted = true,
                UnitId    = unitData.Response.UnitID
            };

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                context.Topic.Add(topic);
                context.Topic.Add(deletedTopic);
                context.SaveChanges();
            }

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get the unit that was just created.
            UnitsFacade     unitsFacade     = new UnitsFacade();
            GetUnitResponse getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);

            // Check that unit response is okay and that names match.
            Assert.AreEqual(HttpStatusCode.OK, getUnitResponse.Status);
            Assert.AreEqual(unitData.Request.Name, getUnitResponse.Unit.Name);
            Assert.IsTrue(getUnitResponse.Unit.Topics.Count == 2);
            Assert.AreEqual(topic.Name, getUnitResponse.Unit.Topics[1].Name);
        }
        public void AddHelpdesk()
        {
            testEntityFactory.PopulateEmptyStrings = true;

            TestDataHelpdesk testEntityData = testEntityFactory.AddHelpdesk();

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

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

                Assert.IsNotNull(helpdesk);
            }
        }
        public void UpdateUnitNotFound()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create unit with non-existing id.
            int          maxInt   = 2147483647;
            TestDataUnit unitData = testEntityFactory.AddUpdateUnit(maxInt, helpdeskData.Response.HelpdeskID);

            Assert.AreEqual(HttpStatusCode.NotFound, unitData.Response.Status);
        }
        public void AddUnitTopicNameTooLong()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { AlphaNumericStringGenerator.GetString(51), });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.BadRequest, unitData.Response.Status);
        }
        public void UpdateTimespan()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Add timespan.
            TestDataTimeSpan timespanData = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID);

            // Check that timespan was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, timespanData.Response.Status);
            Assert.IsTrue(timespanData.Response.SpanId > 0);

            UpdateTimeSpanRequest updateTimespanRequest = new UpdateTimeSpanRequest()
            {
                Name      = AlphaNumericStringGenerator.GetString(10),
                StartDate = new DateTime(2019, 01, 01),
                EndDate   = new DateTime(2019, 06, 01),
            };

            UpdateTimeSpanResponse updateTimespanResponse = testEntityFactory.HelpdeskFacade.UpdateTimeSpan(timespanData.Response.SpanId, updateTimespanRequest);

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

            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                var timespan = context.Timespans.FirstOrDefault(u => u.SpanId == timespanData.Response.SpanId);

                Assert.AreEqual(timespan.StartDate, updateTimespanRequest.StartDate);
                Assert.AreEqual(timespan.Name, updateTimespanRequest.Name);
                Assert.AreEqual(timespan.EndDate, updateTimespanRequest.EndDate);
            }
        }
        public void DeleteUnit()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Test get, delete, get.
            UnitsFacade unitsFacade = new UnitsFacade();

            // Get the unit that was just created.
            GetUnitResponse getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);

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

            // Delete the unit that was just created.
            DeleteUnitResponse deleteUnitResponse = unitsFacade.DeleteUnit(unitData.Response.UnitID);

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

            // Try getting the unit that was just deleted. Should be NotFound.
            //Will update unit test when get unit method is implemented that excludes units
            //with IsDeleted = true
            getUnitResponse = unitsFacade.GetUnit(unitData.Response.UnitID);
            Assert.IsTrue(getUnitResponse.Unit.IsDeleted);
        }
        public void UpdateTimespanNameExists()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Add timespan.
            TestDataTimeSpan timespanDataA = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID);

            // Check that timespan was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, timespanDataA.Response.Status);
            Assert.IsTrue(timespanDataA.Response.SpanId > 0);

            // Add another timespan
            TestDataTimeSpan timespanDataB = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID);

            // Check that timespan was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, timespanDataB.Response.Status);
            Assert.IsTrue(timespanDataB.Response.SpanId > 0);

            // This request will try to update timespan B's name to be the same as A's name, which should fail.
            var updateTimespanRequest = new UpdateTimeSpanRequest()
            {
                Name      = timespanDataA.Request.Name,
                StartDate = new DateTime(2019, 01, 01),
                EndDate   = new DateTime(2019, 06, 01),
            };

            var updateTimespanResponse = testEntityFactory.HelpdeskFacade.UpdateTimeSpan(timespanDataB.Response.SpanId, updateTimespanRequest);

            Assert.AreEqual(HttpStatusCode.BadRequest, updateTimespanResponse.Status);
            Assert.IsFalse(updateTimespanResponse.Result);
        }
Пример #14
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);
        }
        public void ForceCheckoutQueueRemove()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Get topics that were created and check that there are 2 (Layouts and Lifecycle).
            List <TopicDTO> unitTopics = testEntityFactory.TopicsFacade.GetTopicsByUnitID(unitData.Response.UnitID).Topics;

            Assert.IsTrue(unitTopics.Count == 3);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Create students and check that they were created successfully.
            TestDataNickname nicknameDataA = testEntityFactory.AddNickname();

            Assert.AreEqual(HttpStatusCode.OK, nicknameDataA.Response.Status);
            Assert.IsTrue(nicknameDataA.Response.StudentID > 0);
            TestDataNickname nicknameDataB = testEntityFactory.AddNickname();

            Assert.AreEqual(HttpStatusCode.OK, nicknameDataB.Response.Status);
            Assert.IsTrue(nicknameDataB.Response.StudentID > 0);

            // Create two checkins and check that they're created successfully.
            TestDataCheckIn checkinDataA = testEntityFactory.AddCheckIn(nicknameDataA.Response.StudentID, null, null, unitData.Response.UnitID);

            Assert.AreEqual(HttpStatusCode.OK, checkinDataA.Response.Status);
            Assert.IsTrue(checkinDataA.Response.CheckInID > 0);
            TestDataCheckIn checkinDataB = testEntityFactory.AddCheckIn(nicknameDataB.Response.StudentID, null, null, unitData.Response.UnitID);

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

            // Create three queue items, 2 which are associated with checkinDataA and 1 with checkinDataB.
            TestDataQueue queueDataA = testEntityFactory.AddQueueItem(nicknameDataA.Response.StudentID,
                                                                      unitTopics[0].TopicId, checkinDataA.Response.CheckInID);

            Assert.AreEqual(HttpStatusCode.OK, queueDataA.Response.Status);
            Assert.IsTrue(queueDataA.Response.ItemId > 0);
            TestDataQueue queueDataB = testEntityFactory.AddQueueItem(nicknameDataA.Response.StudentID,
                                                                      unitTopics[0].TopicId, checkinDataA.Response.CheckInID);

            Assert.AreEqual(HttpStatusCode.OK, queueDataB.Response.Status);
            Assert.IsTrue(queueDataB.Response.ItemId > 0);
            TestDataQueue queueDataC = testEntityFactory.AddQueueItem(nicknameDataB.Response.StudentID,
                                                                      unitTopics[0].TopicId, checkinDataB.Response.CheckInID);

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

            // Manuall checkout checkinDataB and check that it succeeded.
            CheckOutRequest checkoutRequestB = new CheckOutRequest
            {
                ForcedCheckout = false
            };
            var checkoutBResponse = testEntityFactory.CheckInFacade.CheckOut(checkoutRequestB, checkinDataB.Response.CheckInID);

            Assert.AreEqual(HttpStatusCode.OK, checkoutBResponse.Status);
            Assert.IsTrue(checkoutBResponse.Result == true);

            // Do the force checkout and queue remove.
            var forceCheckoutQueueRemoveResponse = testEntityFactory.HelpdeskFacade.ForceCheckoutQueueRemove(helpdeskData.Response.HelpdeskID);

            Assert.AreEqual(HttpStatusCode.OK, forceCheckoutQueueRemoveResponse.Status);
            Assert.IsTrue(forceCheckoutQueueRemoveResponse.Result == true);

            // Check all checkouts and and queue removals occured as expected.
            using (helpdesksystemContext context = new helpdesksystemContext())
            {
                // CheckinA was was not manually checked out, so ForcedCheckout should be true.
                var checkinA = context.Checkinhistory.FirstOrDefault(c => c.CheckInId == checkinDataA.Response.CheckInID);
                Assert.IsTrue(checkinA.ForcedCheckout == true);
                Assert.IsTrue(checkinA.CheckoutTime != null);

                // CheckinB was manually checked out, so ForcedCheckout should be false.
                var checkinB = context.Checkinhistory.FirstOrDefault(c => c.CheckInId == checkinDataB.Response.CheckInID);
                Assert.IsTrue(checkinB.ForcedCheckout == false);
                Assert.IsTrue(checkinB.CheckoutTime != null);

                // Check that all queue items were removed.
                var queueItemA = context.Queueitem.FirstOrDefault(q => q.ItemId == queueDataA.Response.ItemId);
                Assert.IsTrue(queueItemA.TimeRemoved != null);

                var queueItemB = context.Queueitem.FirstOrDefault(q => q.ItemId == queueDataB.Response.ItemId);
                Assert.IsTrue(queueItemB.TimeRemoved != null);

                var queueItemC = context.Queueitem.FirstOrDefault(q => q.ItemId == queueDataC.Response.ItemId);
                Assert.IsTrue(queueItemC.TimeRemoved != null);
            }
        }
        public void UpdateQueueItemStatusInvalidTimeRemoved()
        {
            // Fill empty string parameters "" with auto-generated string.
            testEntityFactory.PopulateEmptyStrings = true;

            // Add test helpdesk.
            TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk();

            // Check that helpdesk was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status);
            Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0);

            // Create a unit. ID provided is 0, which will indicates creation of new helpdesk.
            List <string> topics   = new List <string>(new string[] { "Layouts", "Lifecycle" });
            TestDataUnit  unitData = testEntityFactory.AddUpdateUnit(0, helpdeskData.Response.HelpdeskID, "", "", false, topics);

            // Check that unit was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, unitData.Response.Status);
            Assert.IsTrue(unitData.Response.UnitID > 0);

            // Get topics for the unit that was just created.
            TopicsFacade topicsFacade = new TopicsFacade();
            GetTopicsByUnitIDResponse topicResponse = topicsFacade.GetTopicsByUnitID(unitData.Response.UnitID);

            // Check that there are two units in the response (Layouts, Lifecycle).
            Assert.IsTrue(topicResponse.Topics.Count() == 3);

            // Add test queue item, pass in topic [0].
            TestDataQueue queueData = testEntityFactory.AddQueueItem(null, topicResponse.Topics[0].TopicId);

            // Check that queue item was created successfully.
            Assert.AreEqual(HttpStatusCode.OK, queueData.Response.Status);

            // Create update request for TimeHelped.
            var queueUpdateRequest = new UpdateQueueItemStatusRequest
            {
                TimeHelped  = DateTime.Now,
                TimeRemoved = null
            };

            // Update queue item TimeHelped.
            var queueUpdateResponse = testEntityFactory.QueueFacade.UpdateQueueItemStatus(queueData.Response.ItemId, queueUpdateRequest);

            // Check that queue item was updated successfully.
            Assert.AreEqual(HttpStatusCode.OK, queueData.Response.Status);
            Assert.IsTrue(queueUpdateResponse.Result == true);

            // Create update request for TimeRemoved.
            // NOTICE we're providing a TimedRemoved time that precedes TimeHelped. This should fail.
            DateTime timeRemoved = queueUpdateRequest.TimeHelped.Value.AddMinutes(-1);

            queueUpdateRequest = new UpdateQueueItemStatusRequest
            {
                TimeHelped  = null,
                TimeRemoved = timeRemoved
            };

            // Update queue item TimeRemoved.
            queueUpdateResponse = testEntityFactory.QueueFacade.UpdateQueueItemStatus(queueData.Response.ItemId, queueUpdateRequest);

            // Check that queue item was updated successfully.
            Assert.AreEqual(HttpStatusCode.BadRequest, queueUpdateResponse.Status);
            Assert.IsTrue(queueUpdateResponse.Result == false);
        }