/// /// <param name="module1Property">Module 1 property to be repacked</param> public IModule2Property RepackToModule2Property(IModule1Property module1Property) { logger.LogNewInfo(string.Format("Repacking module 1 property with code {0} and value {1} to Module 2 property.", module1Property.Code, module1Property.Module1Value)); Module2Property property = new Module2Property(module1Property.Code, module1Property.Module1Value); return(property); }
/// /// <param name="property">Module 1 property</param> public void WriteProperty(IModule1Property property) { logger.LogNewInfo(string.Format("Trying to write property with signal code {0} and value {1} to database", property.Code, property.Module1Value)); Dataset set = DatasetRepository.GetDataset(property.Code); string tableName = DatabaseTableNamesRepository.GetTableNameByDataset(set); string signalCode = property.Code.ToString(); double value = property.Module1Value; string query = @"DELETE FROM " + tableName + " WHERE signalCode=@codeToDelete; INSERT INTO " + tableName + " (signalCode, signalValue) VALUES(@codeToInsert, @value)"; using (SQLiteCommand command = new SQLiteCommand(query, databaseConnection)) { command.Parameters.AddWithValue("@codeToDelete", signalCode); command.Parameters.AddWithValue("@codeToInsert", signalCode); command.Parameters.AddWithValue("@value", value); if (command.ExecuteNonQuery() == 0) { logger.LogNewWarning("Could not write to database."); } else { logger.LogNewInfo("Property written successfully."); } } }
public void AddOrReplaceProperty_ExistingProperty_PropertyReplaced(Dataset dataset, SignalCode signal, double value) { IModule1Property existingProperty = MockModule1Property(signal, 100); IModule1Property newProperty = MockModule1Property(signal, value); Mock <List <IModule1Property> > mockedList = new Mock <List <IModule1Property> >(); List <IModule1Property> properties = mockedList.Object; properties.Add(existingProperty); Description description = new Description(dataset, mockedLogger) { Properties = properties }; IModule1Property propertyInside = description.Properties[0]; Assert.AreEqual(existingProperty.Code, propertyInside.Code); Assert.AreEqual(existingProperty.Module1Value, propertyInside.Module1Value); description.AddOrReplaceProperty(newProperty); propertyInside = description.Properties[0]; Assert.AreEqual(newProperty.Code, propertyInside.Code); Assert.AreEqual(newProperty.Module1Value, propertyInside.Module1Value); }
public void PackToModule1Property_RegularParameters_AssertObjectContent(SignalCode code, double value) { Module1DataAdapter dataAdapter = new Module1DataAdapter(mockedLogger); IModule1Property module1Property = dataAdapter.PackToModule1Property(code, value); Assert.AreEqual(module1Property.Code, code); Assert.AreEqual(module1Property.Module1Value, value); }
public void RepackToModule2Property_RegularParameters_AssertObjectContent(SignalCode signal, double value) { IModule1Property property = MockModule1Property(signal, value); IModule2Property module2Property = adapter.RepackToModule2Property(property); Assert.AreEqual(signal, module2Property.Code); Assert.AreEqual(value, module2Property.Value); }
/// /// <param name="property">Module 1 property</param> public void AddOrReplaceProperty(IModule1Property property) { logger.LogNewInfo(string.Format("Add or replace property called with signal code {0} and value {1}", property.Code, property.Module1Value)); if (DoesPropertyExist(property.Code)) { Properties.RemoveAll(x => x.Code == property.Code); } Properties.Add(property); }
public void DoesPropertyExist_ExistingProperty_ReturnsTrue(Dataset dataset, SignalCode signal) { IModule1Property module1Property = MockModule1Property(signal, 200); Mock <List <IModule1Property> > mockedList = new Mock <List <IModule1Property> >(); List <IModule1Property> properties = mockedList.Object; properties.Add(module1Property); Description description = new Description(dataset, mockedLogger) { Properties = properties }; Assert.IsTrue(description.DoesPropertyExist(signal)); }
public void AddOrReplaceProperty(IModule1Property property) { logger.LogNewInfo("Trying to replace property in list description."); Dataset dataset = DatasetRepository.GetDataset(property.Code); IDescription description; if (DoesDescriptionExist(dataset)) { description = GetDescriptionByDataset(dataset); } else { description = new Description(dataset, logger); } description.AddOrReplaceProperty(property); AddOrReplaceDescription(description); }
public void AddOrReplaceProperty_ExistingDescription_VerifyAddPropertyCalled() { Mock <IDescription> description = new Mock <IDescription>(); description.SetupGet(x => x.Dataset).Returns(Dataset.SET1); List <IDescription> descriptions = new List <IDescription> { description.Object }; IListDescription listDescription = new ListDescription(mockedLogger, descriptions); IModule1Property newProperty = MockModule1Property(SignalCode.CODE_ANALOG, 120); listDescription.AddOrReplaceProperty(newProperty); description.Verify(x => x.AddOrReplaceProperty(newProperty), Times.Exactly(1)); }
public void AddOrReplaceProperty_NonExistingDescription_PropertyAdded() { List <IDescription> descriptions = new List <IDescription>(); IListDescription listDescription = new ListDescription(mockedLogger, descriptions); Assert.AreEqual(listDescription.Descriptions.Count, 0); IModule1Property newProperty = MockModule1Property(SignalCode.CODE_ANALOG, 120); listDescription.AddOrReplaceProperty(newProperty); Assert.AreEqual(listDescription.Descriptions.Count, 1); Assert.AreEqual(listDescription.Descriptions[0].Dataset, Dataset.SET1); Assert.AreEqual(listDescription.Descriptions[0].Properties.Count, 1); Assert.AreEqual(listDescription.Descriptions[0].Properties[0].Code, SignalCode.CODE_ANALOG); Assert.AreEqual(listDescription.Descriptions[0].Properties[0].Module1Value, 120); }
public void GetPropertyByCode_ExistingProperty_AssertObjectContent(Dataset dataset, SignalCode signal, double value) { IModule1Property module1Property = MockModule1Property(signal, value); Mock <List <IModule1Property> > mockedList = new Mock <List <IModule1Property> >(); List <IModule1Property> properties = mockedList.Object; properties.Add(module1Property); Description description = new Description(dataset, mockedLogger) { Properties = properties }; IModule1Property receivedProperty = description.GetPropertyByCode(signal); Assert.AreEqual(module1Property.Code, receivedProperty.Code); Assert.AreEqual(module1Property.Module1Value, receivedProperty.Module1Value); }
/// /// <param name="value">Signal value</param> /// <param name="signalCode">Code for given signal</param> public bool UpdateDataset(double value, SignalCode signalCode) { logging.LogNewInfo(string.Format("Update dataset called for signal {0} and value {1}", signalCode, value)); Dataset dataset = DatasetRepository.GetDataset(signalCode); IModule1Property property = dataAdapter.PackToModule1Property(signalCode, value); listDescription.AddOrReplaceProperty(property); if (listDescription.IsDatasetFull(dataset)) { logging.LogNewInfo(string.Format("Dataset {0} is full, sending the whole list to module 2", dataset.ToString())); module2Proxy.UpdateDatabase(listDescription); } logging.LogNewInfo("Calling database manager to write new property.."); databaseManager.WriteProperty(property); return(true); }