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 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 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); }