public static XElement generateFromTLValue(TLValue TV) { XElement XE = generateFromValue(TV); XE.Name = "TLValue"; XE.Add(new XAttribute("Tag", TV.Tag)); return XE; }
public void Composer_TLValue_OK() { // value in object TLValue value1 = new TLValue(); value1.Name = "val 1"; value1.Value = "0022"; value1.Length = 2; value1.Tag = "04"; TLValue value2 = new TLValue(); value2.Name = "val 2"; value2.Value = string.Empty; value2.Length = 2; value2.Tag = "09"; // value definition in XML XElement definition = new XElement("Head"); definition.Add(XElementHelper.generateFromTLValue(value1)); definition.Add(XElementHelper.generateFromTLValue(value2)); // exercise the composer Composer composer = new Composer(); composer.ParseValueDefinition(definition); // check the result Assert.AreEqual(2, composer.Vals.Count); AreEqualTLValue(value1, (TLValue)composer.Vals[0]); AreEqualTLValue(value2, (TLValue)composer.Vals[1]); }
public void Test_TLValue_Input_OK() { TLValue expected = new TLValue(); expected.Name = "ola testing ah"; expected.Value = "22"; expected.Length = 2; expected.Tag = "44"; int resultIndex = expected.ParseValueInput("4402336600225566", 0); Assert.AreEqual(8, resultIndex); Assert.AreEqual(expected.Value, "3366"); Assert.AreEqual(expected.Length, 2); }
public void NamedValue_AllNamed_Less1Byte_OK() { //TLV Object Creation TLValue expected = new TLValue(); expected.Name = "ola testing ah"; expected.Value = "0C0C"; expected.Length = expected.Value.Length / 2; expected.Tag = "0A"; // XML definition Creation XElement XE = DefineXMLForTLValue_def_Multi(expected,3); // set the expected result PairResult[] expPair = DefineListExpectedforTLValue_mix_def_multi_ok(expected, 2).ToArray(); TLValue res = (TLValue)xmlParser.getItem(XE); PairResult[] resPair = res.GetValueOutput(); //validate the result ComparisonHelper.Compare(expPair, resPair); }
public ValueItem getItem(XElement element) { ValueItem result = null; // create the basic value switch (element.Name.ToString().ToLower()) { case "singlevalue": result = new SingleValue(); break; case "tlvalue": result = new TLValue(); break; } //add the decorator foreach (var descendant in element.Descendants()) { switch (descendant.Name.ToString().ToLower()) { case "namedvalue" : if (result is TLValue) { result = new ValueDescriptionDecorator((TLValue)result); } break; default: break; } } if (result != null) { result.ParseDefinition(element); } return result; }
public void Composer_ValueDefinition_OK() { TLValue bareValue1 = new TLValue(); bareValue1.Name = "val 1"; bareValue1.Value = "0022"; bareValue1.Length = 2; bareValue1.Tag = "04"; ValueDescriptionDecorator value1= new ValueDescriptionDecorator(bareValue1); value1.ArrayOfOptions.Add(1, createOptions(3, 1, 1)); value1.ArrayOfOptions.Add(2, createOptions(10, 2, 1)); //value definition in XML XElement definition = new XElement("Definition"); definition.Add(XElementHelper.generateFromValueDescriptionDecorator(value1)); Composer composer = new Composer(); composer.ParseValueDefinition(definition); // check the result Assert.AreEqual(1, composer.Vals.Count); Assert.IsInstanceOfType(composer.Vals[0], typeof(ValueDescriptionDecorator)); AreEqualValueDescriptionDecorator(value1, (ValueDescriptionDecorator)composer.Vals[0]); }
private void AreEqualTLValue(TLValue expected, TLValue result) { Assert.IsInstanceOfType(result, typeof(TLValue)); Assert.AreEqual(expected.Length, result.Length); Assert.AreEqual(expected.Name, result.Name); Assert.AreEqual(expected.Value, result.Value); Assert.AreEqual(expected.Tag, result.Tag); }
public void valInit() { // value in object value_basicTLV_1 = new TLValue(); value_basicTLV_1.Name = "val 1"; value_basicTLV_1.Value = "0022"; value_basicTLV_1.Length = 2; value_basicTLV_1.Tag = "04"; value_basicTLV_2 = new TLValue(); value_basicTLV_2.Name = "val 2"; value_basicTLV_2.Value = string.Empty; // purposely put wrong length value_basicTLV_2.Length = 10; value_basicTLV_2.Tag = "09"; composer_BasicTLV = new Composer(); composer_BasicTLV.Vals.Add(value_basicTLV_1); composer_BasicTLV.Vals.Add(value_basicTLV_2); }
private XElement DefineXMLForTLValue_def_ok_residued(TLValue expected,string residueDesc) { XElement result = DefineXMLForTLValue_def_ok(expected); XElement XResidueElement = new XElement("NamedValue"); XResidueElement.Add(new XAttribute("Length", "*")); XResidueElement.Add(new XAttribute("Name", residueDesc)); XResidueElement.Add(new XAttribute("Position", "2")); //add the residue result.Add(XResidueElement); return result; }
private List<PairResult> DefineListExpectedforTLValue_mix_def_multi_ok(TLValue expected, int p) { List<PairResult> listOfExpected = new List<PairResult>(); // for value_basicTLV_1 listOfExpected.Add(new PairResult() { Title = TLValue.TAG_TITLE + expected.Name, Value = expected.Tag }); listOfExpected.Add(new PairResult() { Title = TLValue.LENGTH_TITLE + expected.Name, Value = expected.Length.ToString("X2") }); for (int i = 0; i < p; i++) { listOfExpected.Add(new PairResult() { Title = "Call ID"+i, Value = "0C", Description = "EVENT_EVENT_DOWNLOAD_MT_CALL" }); } return listOfExpected; }
private XElement DefineXMLForTLValue_def_Multi(TLValue expected, int p) { XElement XE = new XElement("TLValue"); XE.Add(new XAttribute("Length", expected.Length.ToString())); XE.Add(new XAttribute("Default", expected.Value)); XE.Add(new XAttribute("Name", expected.Name)); XE.Add(new XAttribute("Tag", expected.Tag)); for (int i = 0; i < p; i++) { // adding of head element XElement XSubElement = new XElement("NamedValue"); XSubElement.Add(new XAttribute("Length", 1)); XSubElement.Add(new XAttribute("Name", "Call ID"+i)); XSubElement.Add(new XAttribute("Position",1+i)); // adding of child head element XElement option1 = new XElement("Options", "0C"); option1.Add(new XAttribute("Name", "EVENT_EVENT_DOWNLOAD_MT_CALL")); XSubElement.Add(option1); XElement option2 = new XElement("Options", "0D"); option2.Add(new XAttribute("Name", "EVENT_EVENT_DOWNLOAD_CALL_CONNECTED")); XSubElement.Add(option2); //add to head XE.Add(XSubElement); } return XE; }
private List<PairResult> DefineListExpectedforTLValue_def_ok_residued(TLValue expected,string residueValue,string residueDesc) { List<PairResult> result = DefineListExpectedforTLValue_def_ok(expected); // add the residue; result.Add(new PairResult() { Title = residueDesc, Value = residueValue }); return result; }
private static XElement DefineXMLForTLValue_mix_def_ok(TLValue expected,int byteNumber) { XElement XE = new XElement("TLValue"); XE.Add(new XAttribute("Length", expected.Length.ToString())); XE.Add(new XAttribute("Default", expected.Value)); XE.Add(new XAttribute("Name", expected.Name)); XE.Add(new XAttribute("Tag", expected.Tag)); //adding of first element (no options) XElement XSubElement_Position1 = new XElement("NamedValue"); XSubElement_Position1.Add(new XAttribute("Length", "1")); XSubElement_Position1.Add(new XAttribute("Name", "Call ID")); XSubElement_Position1.Add(new XAttribute("Position", "1")); //add to head XE.Add(XSubElement_Position1); // adding of Second element (with options) XElement XSubElement_Position2 = new XElement("NamedValue"); XSubElement_Position2.Add(new XAttribute("Length", byteNumber)); XSubElement_Position2.Add(new XAttribute("Name", "Event ID")); XSubElement_Position2.Add(new XAttribute("Position","2")); // adding of child head element XElement option1 = new XElement("Options", repeat("0C",byteNumber)); option1.Add(new XAttribute("Name", "EVENT_EVENT_DOWNLOAD_MT_CALL")); XSubElement_Position2.Add(option1); XElement option2 = new XElement("Options", repeat("0D",byteNumber)); option2.Add(new XAttribute("Name", "EVENT_EVENT_DOWNLOAD_CALL_CONNECTED")); XSubElement_Position2.Add(option2); //add to head XE.Add(XSubElement_Position2); return XE; }
private static List<PairResult> DefineListExpectedforTLValue_mix_def_ok(TLValue expected,int bytenumber) { List<PairResult> listOfExpected = new List<PairResult>(); // for value_basicTLV_1 listOfExpected.Add(new PairResult() { Title = TLValue.TAG_TITLE + expected.Name, Value = expected.Tag }); listOfExpected.Add(new PairResult() { Title = TLValue.LENGTH_TITLE + expected.Name, Value = expected.Length.ToString("X2") }); listOfExpected.Add(new PairResult() { Title = "Call ID", Value = "00" }); listOfExpected.Add(new PairResult() { Title = "Event ID", Value = repeat("0C",bytenumber), Description = "EVENT_EVENT_DOWNLOAD_MT_CALL" }); return listOfExpected; }
public void Test_TLValue_Definition_OK() { TLValue expected = new TLValue(); expected.Name = "ola testing ah"; expected.Value = "11223355"; expected.Length = expected.Value.Length / 2; expected.Tag = "0A"; XElement XE = new XElement("TLValue"); XE.Add(new XAttribute("Length", expected.Length.ToString())); XE.Add(new XAttribute("Default", expected.Value)); XE.Add(new XAttribute("Name", expected.Name)); XE.Add(new XAttribute("Tag", expected.Tag)); ValueItem result = xmlParser.getItem(XE); Assert.IsInstanceOfType(result, typeof(TLValue)); TLValue res = (TLValue)result; Assert.AreEqual(expected.Value, res.Value); Assert.AreEqual(expected.Length, res.Length); Assert.AreEqual(expected.Name, res.Name); Assert.AreEqual(expected.Tag, res.Tag); }
public void NamedValue_AllNamed_Residue_OK() { string residueVal = "0B0B"; string residueDesc = "this is residue"; //TLV Object Creation TLValue expected = new TLValue(); expected.Name = "ola testing ah"; expected.Value = "0C"+residueVal; expected.Length = expected.Value.Length / 2; expected.Tag = "0A"; // XML definition Creation XElement XE = DefineXMLForTLValue_def_ok_residued(expected,residueDesc); // set the expected result PairResult[] expPair = DefineListExpectedforTLValue_def_ok_residued(expected,residueVal,residueDesc).ToArray(); TLValue res = (TLValue)xmlParser.getItem(XE); PairResult[] resPair = res.GetValueOutput(); //validate the result ComparisonHelper.Compare(expPair, resPair); }