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