public void TestSetup()
        {
            databaseConnection = new DatabaseConnectionMonitor(Properties.Settings.Default.TestDatabase);

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

            if (agents.Count == 0)
            {
                databaseConnection.AddAgentToDatabase(agent, false, false);
            }
        }
        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);
        }
コード例 #3
0
        public void AddAgentToDatabase(Agent agent, bool cpuCheck, bool discCheck)
        {
            AgentDataModel agentData = new AgentDataModel(agent.Name, agent.IPAddress, new TypeDataModel(agent.Type.TypeNr, agent.Type.Name), agent.Port);

            try
            {
                _databaseConnection.AddAgentToDatabase(agentData, cpuCheck, discCheck);
            }
            catch (SqlException e)
            {
                ExceptionCore.HandleException(ExceptionCategory.Fatal, e);
            }
            catch (Exception e)
            {
                ExceptionCore.HandleException(ExceptionCategory.Normal, e);
            }
        }