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 ); } }
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 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 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 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 AddUnitNoHelpdesk() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; // Create unit with null helpdesk id. TestDataUnit unitData = testEntityFactory.AddUpdateUnit(0, null); Assert.AreEqual(HttpStatusCode.BadRequest, unitData.Response.Status); }
public void AddUnitCodeWrongLength() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; // Create unit with empty string for code. string code = AlphaNumericStringGenerator.GetString(20); TestDataUnit unitData = testEntityFactory.AddUpdateUnit(0, 1, "", code); Assert.AreEqual(HttpStatusCode.BadRequest, unitData.Response.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); }
/// <summary> /// Adds a test unit to the database. /// </summary> /// <param name="unitID">The ID of the unit to update. Should not be provided if adding a new helpdesk.</param> /// <param name="helpdeskID">The ID of the helpdesk that the unit is being added to.</param> /// <param name="name">Name of the unit (auto-generates if not provided, or empty string is provided).</param> /// <param name="code">Code of the unit (auto-generates if not provided, or empty string is provided).</param> /// <param name="isDeleted">Whether or not the helpdesk is removed from the system.</param> /// <param name="topics">A list of topics associated with the unit.</param> /// <returns></returns> public TestDataUnit AddUpdateUnit(int unitID = 0, int?helpdeskID = null, string name = "", string code = "", bool?isDeleted = false, List <string> topics = null) { var request = new AddUpdateUnitRequest(); if (helpdeskID != null) { request.HelpdeskID = (int)helpdeskID; } if (name != null) { if (name == "" && PopulateEmptyStrings) { request.Name = AlphaNumericStringGenerator.GetString(10); } else { request.Name = name; } } if (code != null) { if (code == "" && PopulateEmptyStrings) { request.Code = AlphaNumericStringGenerator.GetString(8); } else { request.Code = code; } } if (isDeleted != null) { request.IsDeleted = (bool)isDeleted; } if (topics != null) { request.Topics = topics; } var facade = new UnitsFacade(); var response = facade.AddOrUpdateUnit(unitID, request); TestDataUnit data = new TestDataUnit(request, response); return(data); }
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 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 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); }