public void TestAddAndDeleteAgentFromDatabase()
        {
            List <AgentDataModel> agentsBeforeAdd = databaseConnection.GetAgentsFromDatabase();
            AgentDataModel        newAgent        = new AgentDataModel("Test-Server", "10.10.10.10", new TypeDataModel(1, "Server"), 161);

            databaseConnection.AddAgentToDatabase(newAgent, false, false);

            List <AgentDataModel> agentsAfterAdd = databaseConnection.GetAgentsFromDatabase();

            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].SysDescription, agentsAfterAdd[i].SysDescription);
                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
            databaseConnection.DeleteAgentInDatabase(agentsAfterAdd[i].AgentNr);

            List <AgentDataModel> agentsAfterDelete = databaseConnection.GetAgentsFromDatabase();

            Assert.AreEqual(agentsAfterDelete.Count, agentsBeforeAdd.Count);
        }
Esempio n. 2
0
 public void DeleteAgent(int agentNr)
 {
     try
     {
         _databaseConnection.DeleteAgentInDatabase(agentNr);
     }
     catch (SqlException e)
     {
         ExceptionCore.HandleException(ExceptionCategory.Fatal, e);
     }
     catch (Exception e)
     {
         ExceptionCore.HandleException(ExceptionCategory.Normal, e);
     }
 }