public IActionResult DeleteUnit([FromRoute] int id) { if (!IsAuthorized()) { return(Unauthorized()); } try { var facade = new UnitsFacade(); var response = facade.DeleteUnit(id); switch (response.Status) { case HttpStatusCode.OK: return(Ok(response)); case HttpStatusCode.BadRequest: return(BadRequest(BuildBadRequestMessage(response))); case HttpStatusCode.InternalServerError: return(StatusCode(StatusCodes.Status500InternalServerError)); case HttpStatusCode.NotFound: return(NotFound()); } s_logger.Fatal("This code should be unreachable, unknown result has occured."); } catch (Exception ex) { s_logger.Error(ex, "Unable to delete unit."); } return(StatusCode(StatusCodes.Status500InternalServerError)); }
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 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); }