public void ModificationTest() { var p = new BinaryParameter(null, "myBinaryId", "myBinaryName", _defValue); p.OnChanged += ParamOnChanged; _passedOnChanged = false; p.Value = _defValue; Assert.IsFalse(_passedOnChanged, "OnChanged called without a cause"); Assert.IsFalse(p.IsModified, "IsModified = true but must be false"); _passedOnChanged = false; p.Value = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 0 }; Assert.IsTrue(_passedOnChanged, "OnChanged call missing"); Assert.IsTrue(p.IsModified, "IsModified = false but must be true"); _passedOnChanged = false; p.Value = null; Assert.IsTrue(_passedOnChanged, "OnChanged call missing"); Assert.IsTrue(p.IsModified, "IsModified = false but must be true"); _passedOnChanged = false; p.Value = new byte[] { 10, 21, 32, 43 }; Assert.IsTrue(_passedOnChanged, "OnChanged call missing"); Assert.IsTrue(p.IsModified, "IsModified = false but must be true"); p.OnChanged -= ParamOnChanged; _passedOnChanged = false; p.Value = new byte[] { 50, 61, 72, 83, 234, 29 }; Assert.IsFalse(_passedOnChanged, "OnChanged not allowed but occurred"); Assert.IsTrue(p.IsModified, "IsModified = false but must be true"); p.ResetModifiedState(); Assert.IsFalse(p.IsModified, "IsModified = false but must be true"); }
public void AsTextTest() { var p = new BinaryParameter(null, "myBinaryId", "myBinaryName", new byte[] { 55, 66, 77, 88, 99, 111 }); var text = p.AsText; Assert.AreEqual("37-42-4D-58-63-6F", text, "AsText expected equal but as not"); p.AsText = "dE-12-45-ef"; Assert.AreEqual("3hJF7w==", p.AsString, "AsText expected equal but as not"); var exceptionThrown = false; try { p.AsText = "dE-xx12-45ef"; } catch (FormatException) { exceptionThrown = true; } Assert.IsTrue(exceptionThrown, "FormatException expected but did not occur"); p.HexSeperator = '.'; Assert.AreEqual("DE.12.45.EF", p.AsText, "AsText expected equal but as not"); }
public void ProhibitedValueChangeTest() { var p = new BinaryParameter(null, "myBinaryId", "myBinaryName", _defValue); CheckProhibitedValueChange(p, new byte[] { 0, 1 }, param => ((BinaryParameter)param).Value = new byte[] { 9, 8, 7, 6 } ); }
public void BufferTest() { var p = new BinaryParameter(null, "myBinaryId", "myBinaryName", _defValue) { Value = new byte[] { 50, 61, 72, 83, 234, 29, 44, 71 } }; p.ResetModifiedState(); Assert.IsTrue(p.BufferedValue.SequenceEqual(p.Value), "BufferedValue not set correctly"); }
public void InitializationTest() { var p = new BinaryParameter(null, "myBinaryId", "myBinaryName", _defValue); Assert.IsNotNull(p, "Parameter object could not be created"); Assert.AreEqual(p.Id, "myBinaryId", "Id not initialized correctly"); Assert.AreEqual(p.Designation, "myBinaryName", "Name not initialized correctly"); Assert.AreEqual(p.PathId, "myBinaryId", "PathId not initialized correctly"); Assert.IsTrue(p.Value.SequenceEqual(_defValue), "Value not initialized correctly"); Assert.IsTrue(p.BufferedValue.SequenceEqual(_defValue), "BufferedValue not initialized correctly"); Assert.AreEqual(p.AsString, Convert.ToBase64String(_defValue), "AsString not initialized correctly"); }
public void SetValueTest() { var p = new BinaryParameter(null, "myBinaryId", "myBinaryName", _defValue) { Value = new byte[] { 10, 21, 32, 43, 55, 123, 222, 12, 22, 3, 2, 56, 78, 99, 255 } }; Assert.AreEqual(p.AsString, "ChUgKzd73gwWAwI4TmP/", "AsString expected equal but was not"); p.Value = new byte[0]; Assert.AreEqual(p.AsString, "", "Empty string expected but is not"); p.Value = null; Assert.AreEqual(p.AsString, "", "Empty string expected but is not"); }
public Cont2(DataContainer parent) : base(parent, "Cont2", "Cont2") { IntParam3 = new IntParameter(this, "IntParam3", "IntParam3", 0); StrParam4 = new StringParameter(this, "StrParam4", "StrParam4", "def"); BoolParam5 = new BoolParameter(this, "BoolParam5", "BoolParam5", true); ChParam6 = new ChoiceParameter(this, "ChParam6", "ChParam6", 5, new List <Tuple <int, string> > { new Tuple <int, string>(0, "rot"), new Tuple <int, string>(5, "gelb"), new Tuple <int, string>(10, "grün"), new Tuple <int, string>(20, "blau"), }); BinParam7 = new BinaryParameter(this, "BinParam7", "BinParam7", new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }); }
public TestCont1(DataContainer parent, string id, string name) : base(parent, id, name) { Tc3 = new TestCont3(this); IntParam = new IntParameter(this, "IP", "IntParam", 0); StrParam = new StringParameter(this, "SP", "StrParam", "abc"); FloatParam = new FloatParameter(this, "FP", "FloatParam", 0.5f, "m/s", 5); BinParam = new BinaryParameter(this, "BP", "BinParam", new byte[] { 1, 2, 3, 4, 5 }); ChParam = new ChoiceParameter(this, "CP", "ChParam", 0, new List<Tuple<int, string>>() { new Tuple<int, string>(0, "Ch1"), new Tuple<int, string>(3, "Ch2"), new Tuple<int, string>(5, "Ch3"), new Tuple<int, string>(15, "Ch4"), }); }