public void EqualityTest() { var A = new SensorTemplate("C", 100, 0, 1, SensorTemplate.MatchStyle.Contains, "Test"); var B = new SensorTemplate("C", 100, 0, 1, SensorTemplate.MatchStyle.Contains, "Test"); var C = new SensorTemplate("Q", 100, 0, 1, SensorTemplate.MatchStyle.StartsWith, "Test"); Assert.AreEqual(A, B); Assert.IsFalse(A.Equals(null)); Assert.IsFalse(A.Equals(C)); }
public void ConstructionWithWhitespaceSensorUnit() { var s = new SensorTemplate(" ", UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, _pattern); }
public void EmptyPatternTest() { var A = new SensorTemplate("C", 100, 0, 1, SensorTemplate.MatchStyle.Contains, "Test"); A.Pattern = null; }
public void ConstructionWithNullPattern() { var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, null); }
public void ConstructionWithValidSensor() { var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, _pattern); Assert.Pass(); }
public void SetUpperLimitLowerThanLowerLimit() { var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); s.UpperLimit = 0; }
public void ToStringTest() { var A = new SensorTemplate("C", 100, 0, 1, SensorTemplate.MatchStyle.Contains, "Test"); var B = new SensorTemplate("C", 100, 0, 1, SensorTemplate.MatchStyle.EndsWith, "Test"); var C = new SensorTemplate("Q", 100, 0, 1, SensorTemplate.MatchStyle.StartsWith, "Test"); Assert.AreEqual("Match if contains 'Test'", A.ToString()); Assert.AreEqual("Match if ends with 'Test'", B.ToString()); Assert.AreEqual("Match if starts with 'Test'", C.ToString()); }
public void SensorNameMatchedCorrectly() { var testSensor = new Sensor("Temperature", "C"); var testSensorTwo = new Sensor("Dissolved Oxygen", "Q"); var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); Assert.IsTrue(s.Matches(testSensor)); Assert.IsFalse(s.Matches(testSensorTwo)); s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.StartsWith, "Temp"); Assert.IsTrue(s.Matches(testSensor)); Assert.IsFalse(s.Matches(testSensorTwo)); s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.EndsWith, "Temp"); Assert.IsFalse(s.Matches(testSensor)); s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.EndsWith, "n"); Assert.IsTrue(s.Matches(testSensorTwo)); }
public void SetterTests() { var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); s.Unit = "Q"; Assert.AreEqual("Q", s.Unit); s.UpperLimit = 1000; Assert.AreEqual(1000, s.UpperLimit); s.LowerLimit = 20; Assert.AreEqual(20, s.LowerLimit); s.MaximumRateOfChange = 200; Assert.AreEqual(200, s.MaximumRateOfChange); s.Pattern = "X"; Assert.AreEqual("X", s.Pattern); }
public void ProvidesDefaultValuesWhenMatches() { var testSensor = new Sensor("Temperature", "C", 150, 50, "F", 8.3f, null); var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); s.ProvideDefaultValues(testSensor); Assert.AreEqual(testSensor.Unit, s.Unit); Assert.AreEqual(testSensor.UpperLimit, s.UpperLimit); Assert.AreEqual(testSensor.LowerLimit, s.LowerLimit); Assert.AreEqual(testSensor.MaxRateOfChange, s.MaximumRateOfChange); }
public void ProvideDefaultValuesNullSensor() { var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); s.ProvideDefaultValues(null); }
public void LowerLimitHigherThanUpperLimitConstruct() { var s = new SensorTemplate(UNIT, LOWER_LIMIT, UPPER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); }
public void GetterTests() { var s = new SensorTemplate(UNIT, UPPER_LIMIT, LOWER_LIMIT, MAX_CHANGE, SensorTemplate.MatchStyle.Contains, "Temp"); Assert.AreEqual(UNIT, s.Unit); Assert.AreEqual(UPPER_LIMIT, s.UpperLimit); Assert.AreEqual(LOWER_LIMIT, s.LowerLimit); Assert.AreEqual(MAX_CHANGE, s.MaximumRateOfChange); }
public void btnSave() { try { var msg = ""; var template = new SensorTemplate(Unit, UpperLimit, LowerLimit, MaximumRateOfChange, (SensorTemplate.MatchStyle)Enum.Parse(typeof(SensorTemplate.MatchStyle), (MatchMode).ToString()), TextToMatch,_sType); // Construct object to prevent inconsistent state if updating (when setting properties and some are invalid) var list = AllTemplates; // To trigger update if(SelectedTemplate == null) { // New list.Add(template); AllTemplates = list; foreach (var sensor in _sensors) { foreach (var sensorTemplate in list) if(sensorTemplate.Matches(sensor.Sensor)) sensorTemplate.ProvideDefaultValues(sensor.Sensor); } msg = "Sensor preset successfully created."; } else { // Update list[list.IndexOf(SelectedTemplate)] = template; SelectedTemplate = template; AllTemplates = list; foreach (var sensor in _sensors) { foreach (var sensorTemplate in list) if(sensorTemplate.Matches(sensor.Sensor)) sensorTemplate.ProvideDefaultValues(sensor.Sensor); } msg = "Sensor preset successfully updated."; } SensorTemplate.ExportAll(AllTemplates); Common.ShowMessageBox("Presets", msg, false, false); Editing = false; SelectedTemplate = null; AllTemplates = new List<SensorTemplate>(); // To force update! AllTemplates = list; } catch (Exception e) { Common.ShowMessageBox("Error", e.Message, false, true); } }