Ejemplo n.º 1
0
        public void ReadLastByCode_MultipleEntriesOfTheFirstDatasetSameCode_AssertLastRead(SignalCode code, double firstValue, double secondValue)
        {
            /*Connect to test database to write*/
            using (SQLiteConnection databaseConnection = new SQLiteConnection(string.Format(@"Data Source={0}{1};New=False;", path, testDatabaseName)))
            {
                databaseConnection.Open();
                /*Insert test data*/
                string query = "INSERT INTO res_dataset1(signalCode, signalValue) VALUES(@code, @value)";
                using (SQLiteCommand command = new SQLiteCommand(query, databaseConnection))
                {
                    command.Parameters.AddWithValue("@code", code.ToString());
                    command.Parameters.AddWithValue("@value", firstValue);
                    command.ExecuteNonQuery();
                    Thread.Sleep(2000);
                }
                query = "INSERT INTO res_dataset1(signalCode, signalValue) VALUES(@code, @value)";
                using (SQLiteCommand command = new SQLiteCommand(query, databaseConnection))
                {
                    command.Parameters.AddWithValue("@code", code.ToString());
                    command.Parameters.AddWithValue("@value", secondValue);
                    command.ExecuteNonQuery();
                }
            }

            Module2DatabaseManager module2DatabaseManager = new Module2DatabaseManager(loggingMock.Object, testDatabaseName);
            /*Assert*/
            IModule2Property recievedProperty = module2DatabaseManager.ReadLastByCode(code);

            Assert.AreEqual(code, recievedProperty.Code);
            Assert.AreEqual(secondValue, recievedProperty.Value);
        }
Ejemplo n.º 2
0
        public void ReadPropertiesByTimeframe_TwoPropertiesExist_AssertAllRead(SignalCode code, double firstValue, double secondValue)
        {
            DateTime periodStart = DateTime.Now;

            /*Connect to test database to write*/
            using (SQLiteConnection databaseConnection = new SQLiteConnection(string.Format(@"Data Source={0}{1};New=False;", path, testDatabaseName)))
            {
                databaseConnection.Open();
                /*Insert test data*/
                string query = "INSERT INTO res_dataset1(signalCode, signalValue) VALUES(@code, @value)";
                using (SQLiteCommand command = new SQLiteCommand(query, databaseConnection))
                {
                    command.Parameters.AddWithValue("@code", code.ToString());
                    command.Parameters.AddWithValue("@value", firstValue);
                    command.ExecuteNonQuery();
                    Thread.Sleep(2000);
                }
                query = "INSERT INTO res_dataset1(signalCode, signalValue) VALUES(@code, @value)";
                using (SQLiteCommand command = new SQLiteCommand(query, databaseConnection))
                {
                    command.Parameters.AddWithValue("@code", code.ToString());
                    command.Parameters.AddWithValue("@value", secondValue);
                    command.ExecuteNonQuery();
                }
            }

            DateTime periodEnd = DateTime.Now;
            Module2DatabaseManager module2DatabaseManager = new Module2DatabaseManager(loggingMock.Object, testDatabaseName);
            /*Assert*/
            List <IModule2Property> recievedProperty = module2DatabaseManager.ReadPropertiesByTimeframe(periodStart, periodEnd, code);

            Assert.AreEqual(recievedProperty.Count, 2);
            Assert.AreEqual(recievedProperty[0].Value, secondValue);
            Assert.AreEqual(recievedProperty[1].Value, firstValue);
        }
Ejemplo n.º 3
0
        public void WriteProperty_TestDatabase_AssertNoExceptions(SignalCode code, double value)
        {
            Mock <IModule2Property> property = new Mock <IModule2Property>();

            property.SetupGet(x => x.Code).Returns(code);
            property.SetupGet(x => x.Value).Returns(value);

            Module2DatabaseManager module2DatabaseManager = new Module2DatabaseManager(loggingMock.Object, testDatabaseName);

            Assert.DoesNotThrow(() => module2DatabaseManager.WriteProperty(property.Object));
        }