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