public HttpStatusCodeResult DeleteAgent(int id) { HttpStatusCodeResult output = new HttpStatusCodeResult(System.Net.HttpStatusCode.Conflict); try { if (id > 0) { SNMPController controller = new SNMPController(Properties.Settings.Default.ProdDatabaseConnectionString); controller.DeleteAgent(id); output = new HttpStatusCodeResult(System.Net.HttpStatusCode.OK); } else { output = new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest); } } catch (Exception exc) { BusinessLayer.ExceptionHandling.ExceptionCore.HandleException(BusinessLayer.ExceptionHandling.ExceptionCategory.Normal, exc); output = new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError); } return(output); }
public void TestAddAndDeleteAgent() { List <Agent> agentsBeforeAdd = controller.GetAgents(); Agent newAgent = new Agent("Test-Server", "10.10.10.10", new Type(1, "Server"), 161); controller.AddAgentToDatabase(newAgent, false, false); List <Agent> agentsAfterAdd = controller.GetAgents(); Assert.AreEqual(agentsBeforeAdd.Count + 1, agentsAfterAdd.Count); // Check old Agents int i; for (i = 0; i < agentsBeforeAdd.Count; i++) { Assert.AreEqual(agentsBeforeAdd[i].AgentNr, agentsAfterAdd[i].AgentNr); Assert.AreEqual(agentsBeforeAdd[i].Name, agentsAfterAdd[i].Name); Assert.AreEqual(agentsBeforeAdd[i].IPAddress, agentsAfterAdd[i].IPAddress); Assert.AreEqual(agentsBeforeAdd[i].Type.TypeNr, agentsAfterAdd[i].Type.TypeNr); Assert.AreEqual(agentsBeforeAdd[i].Port, agentsAfterAdd[i].Port); Assert.AreEqual(agentsBeforeAdd[i].Status, agentsAfterAdd[i].Status); Assert.AreEqual(agentsBeforeAdd[i].SysDesc, agentsAfterAdd[i].SysDesc); Assert.AreEqual(agentsBeforeAdd[i].SysName, agentsAfterAdd[i].SysName); Assert.AreEqual(agentsBeforeAdd[i].SysUptime, agentsAfterAdd[i].SysUptime); } // Check new Agent Assert.AreEqual(newAgent.Name, agentsAfterAdd[i].Name); Assert.AreEqual(newAgent.IPAddress, agentsAfterAdd[i].IPAddress); Assert.AreEqual(newAgent.Type.TypeNr, agentsAfterAdd[i].Type.TypeNr); Assert.AreEqual(newAgent.Port, agentsAfterAdd[i].Port); Assert.AreEqual(newAgent.Status, agentsAfterAdd[i].Status); // Delete new Agent controller.DeleteAgent(agentsAfterAdd[i].AgentNr); List <Agent> agentsAfterDelete = controller.GetAgents(); Assert.AreEqual(agentsAfterDelete.Count, agentsBeforeAdd.Count); }