public void IPAddressDAO_Create_UnsuccessfulCreation(string ip, long timestampLocked, int registrationFailures,
                                                             long lastRegFailTimestamp)
        {
            // Arrange
            UnitTestIPAddressDAO ipDAO    = new UnitTestIPAddressDAO();
            IPAddressRecord      ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);
            bool result = false;

            // Act

            try
            {
                // Create the same IP Address twice.
                ipDAO.Create(ipRecord);
                ipDAO.Create(ipRecord);
            }
            catch (ArgumentException)
            {
                // Catch the exception and set the result to true.
                result = true;
            }

            // Assert

            // The result should be true.
            Assert.IsTrue(result);
        }
        public void IPAddressDAO_DeleteByIds_SuccessfulDeletion(string ip, long timestampLocked, int registrationFailures,
                                                                long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create an IP address.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);

            // Act

            // Delete the IP address.
            ipDAO.DeleteByIds(new List <string>()
            {
                ip
            });
            // Check if the IP exists and set the result accordingly.
            bool result = ipDAO.CheckIPExistence(ip);

            // Assert

            // The result should be false.
            Assert.IsFalse(result);
        }
        public void IPAddressDAO_Update_UnsuccessfulUpdate(string ip, long timestampLocked, int registrationFailures,
                                                           long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create the IP.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);

            // Prepare a new data to update but with a wrong IP address.
            IPAddressRecord updatedRecord = new IPAddressRecord(NonExistingIP, 1, 1, 1);
            bool            result        = false;

            // Act

            try
            {
                // Update the IP address.
                ipDAO.Update(updatedRecord);
            }
            catch (Exception)
            {
                // Catch the exception and set the result to true.
                result = true;
            }

            // Assert

            // The result should be true.
            Assert.IsTrue(result);
        }
        public void IPAddressDAO_Update_SuccessfulUpdate(string ip, long timestampLocked, int registrationFailures,
                                                         long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create an IP.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);

            // Prepare a new data to update.
            IPAddressRecord updatedRecord = new IPAddressRecord(ip, 1, 1, 1);

            // Act

            // Update the data of the IP.
            ipDAO.Update(updatedRecord);
            // Read the IP.
            IPAddressObject ipObject = (IPAddressObject)ipDAO.ReadById(ip);
            // Check if the IP was updated correctly and set the result to true.
            bool result = DataEquals(ipRecord, ipObject);

            // Assert

            // The result should be true.
            Assert.IsTrue(result);
        }
        public void IPAddressDAO_ReadById_UnsuccessfulRead(string ip, long timestampLocked, int registrationFailures,
                                                           long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create an IP.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);
            bool result = false;

            // Act
            try
            {
                // Read a non-existing IP.
                IPAddressObject ipObject = (IPAddressObject)ipDAO.ReadById(NonExistingIP);
            }
            catch (ArgumentException)
            {
                // Catch the exception and set the result to true.
                result = true;
            }

            // Assert

            // The result should be true.
            Assert.IsTrue(result);
        }
        public void IPAddressDAO_DeleteByIds_UnsuccessfulDeletion(string ip, long timestampLocked, int registrationFailures,
                                                                  long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create an IP address.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);

            bool result = false;

            // Act
            try
            {
                // Delete an non-existing IP.
                ipDAO.DeleteByIds(new List <string>()
                {
                    NonExistingIP
                });
            }
            catch (ArgumentException)
            {
                // Catch the exception and set the result to true.
                result = true;
            }

            // Assert

            // The result should be true.
            Assert.IsTrue(result);
        }
        /// <summary>
        /// Creates a record in the data store with the <paramref name="ipAddress"/>.
        /// </summary>
        /// <param name="ipAddress">ip address to insert into the data store (string)</param>
        /// <returns>Task (bool) whether the function completed without exception</returns>
        public static bool CreateIP(string ipAddress)
        {
            // Initialize the locked time and registration failures to initially have no value.
            IPAddressRecord record = new IPAddressRecord(ipAddress, Constants.NoValueLong, Constants.NoValueInt, Constants.NoValueLong);

            // Call the create method via the IP DAO with the record.
            return(_ipDAO.Create(record));
        }
        public void IPAddressDAO_Create_SuccessfulCreation(string ip, long timestampLocked, int registrationFailures,
                                                           long lastRegFailTimestamp)
        {
            // Arrange
            UnitTestIPAddressDAO ipDAO    = new UnitTestIPAddressDAO();
            IPAddressRecord      ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            // Act

            // Create IP Address.
            ipDAO.Create(ipRecord);
            IPAddressObject ipObject = (IPAddressObject)ipDAO.ReadById(ip);
            // Check if the data created is correct.
            bool correctDataResult = DataEquals(ipRecord, ipObject);

            // Assert

            // The data should be correct.
            Assert.IsTrue(correctDataResult);
        }
        public void IPAddressDAO_CheckIPExistence_IPNonExists(string ip, long timestampLocked, int registrationFailures,
                                                              long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create an IP.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);

            // Act

            // Check if the IP exists and set the result accordingly.
            bool result = ipDAO.CheckIPExistence(NonExistingIP);

            // Assert

            // The result should be false.
            Assert.IsFalse(result);
        }
        public void IPAddressDAO_ReadById_SuccessfulRead(string ip, long timestampLocked, int registrationFailures,
                                                         long lastRegFailTimestamp)
        {
            // Arrange

            UnitTestIPAddressDAO ipDAO = new UnitTestIPAddressDAO();
            // Create an IP.
            IPAddressRecord ipRecord =
                new IPAddressRecord(ip, timestampLocked, registrationFailures, lastRegFailTimestamp);

            ipDAO.Create(ipRecord);

            // Act

            // Read the IP.
            IPAddressObject ipObject = (IPAddressObject)ipDAO.ReadById(ip);
            // Check if the read IP is correct and set the result accordingly.
            bool result = DataEquals(ipRecord, ipObject);

            // Assert

            // The result should be true.
            Assert.IsTrue(result);
        }