public IActionResult GetUnit([FromRoute] int id) { if (!IsAuthorized()) { return(Unauthorized()); } try { var facade = new UnitsFacade(); var response = facade.GetUnit(id); 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 get unit."); } return(StatusCode(StatusCodes.Status500InternalServerError)); }
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 TestEntityFactory() { HelpdeskFacade = new HelpdeskFacade(); UnitsFacade = new UnitsFacade(); TopicsFacade = new TopicsFacade(); QueueFacade = new QueueFacade(); CheckInFacade = new CheckInFacade(); StudentFacade = new StudentFacade(); }
public void DeleteUnitNotFound() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; UnitsFacade unitsFacade = new UnitsFacade(); int maxInt = 2147483647; DeleteUnitResponse deleteUnitResponse = unitsFacade.DeleteUnit(maxInt); Assert.AreEqual(HttpStatusCode.NotFound, deleteUnitResponse.Status); }
public void GetUnitsByHelpdeskIDNotFound() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; UnitsFacade unitsFacade = new UnitsFacade(); int maxInt = 2147483647; GetUnitsByHelpdeskIDResponse getUnitsByHelpdeskIDResponse = unitsFacade.GetUnitsByHelpdeskID(maxInt, false); Assert.AreEqual(HttpStatusCode.NotFound, getUnitsByHelpdeskIDResponse.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 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); }