/// <summary> /// Generates an new DDAttributesCollection from its XML representation. /// </summary> /// <param name="reader">XML reader stream</param> /// <returns>an new DDAttributesCollection </returns> public static DDAttributesCollection Deserialize(XmlReader reader) { var ac = new DDAttributesCollection(); ac.Deserialize(reader); return(ac); }
/// <summary> /// Generates an attribute from its XML representation. /// </summary> /// <param name="reader"></param> private static void AddDeserializedAttribute(DDAttributesCollection ac, XmlReader reader) { var name = reader.GetAttribute(DDSchema.XML_SERIALIZE_ATTRIBUTE_NAME); var t = reader.GetAttribute(DDSchema.XML_SERIALIZE_ATTRIBUTE_TYPE); //if (name != null) //{ DDValue v = null; //if (t != null) v = DDValueSxe.Deserialize(reader); v = DDValueSxe.Deserialize(reader); if (name != null) { ac.Add(name, v); } else { ac.Add(v); } //} //else //{ // if (reader.NodeType == XmlNodeType.Element) reader.ReadStartElement(); // if (reader.NodeType == XmlNodeType.EndElement) reader.ReadEndElement(); // need to close the opened element //} }
/// <summary> /// Adds an new items to specified DDAttributesCollection from its XML representation. /// </summary> /// <param name="ac">The deserialized attributes collection.</param> /// <param name="s">string</param> public static void Deserialize(this DDAttributesCollection ac, String s) { using (XmlReader r = XmlReader.Create(new StringReader(s))) { ac.Deserialize(r); } }
/// <summary> /// Generates an new DDAttributesCollection from its XML representation. /// </summary> /// <param name="s">string</param> /// <returns>an new DDAttributesCollection </returns> public static DDAttributesCollection Deserialize(String s) { var ac = new DDAttributesCollection(); ac.Deserialize(s); return(ac); }
/// <summary> /// Adds an new items to specified DDAttributesCollection from its XML representation. /// </summary> /// <param name="ac">The deserialized attributes collection.</param> /// <param name="tr">text reader</param> public static void Deserialize(this DDAttributesCollection ac, TextReader tr) { using (XmlReader r = XmlReader.Create(tr)) { ac.Deserialize(r); } }
/// <summary> /// Generates an attributes collection from its XML representation. /// </summary> /// <param name="reader"></param> private static void AddDeserializedAttributesCollection(DDAttributesCollection ac, XmlReader reader) { reader.MoveToContent(); var isEmptyElement = reader.IsEmptyElement; // Save Empty Status of Root Element reader.Read(); // read root element if (isEmptyElement) { return; // Exit for element without child <n /> } var initialDepth = reader.Depth; while ((reader.Depth >= initialDepth)) // do all childs { if ((reader.IsStartElement(DDSchema.XML_SERIALIZE_NODE_ATTRIBUTE) == false) || (reader.Depth > initialDepth)) { reader.Skip(); // Skip none <a> elements with childs and subchilds <a> elements 'Deep proptection' if (reader.NodeType == XmlNodeType.EndElement) { reader.ReadEndElement(); // need to close the opened element after deep protection } } else { AddDeserializedAttribute(ac, reader); // deserializes attribute } reader.MoveToContent(); } if ((reader.NodeType == XmlNodeType.EndElement) && (reader.Name == DDSchema.XML_SERIALIZE_NODE_ATTRIBUTE_COLLECTION)) { reader.ReadEndElement(); // need to close the opened element, only self type } }
public static Stream SerializeItem(DDAttributesCollection iSerializable, IFormatter formatter) { var s = new MemoryStream(0); SerializeItem(s, iSerializable, formatter); return(s); }
public void TestDDAttributesCollectionXmlSerializationEmptyName() { var a = new DDAttributesCollection(); a.Add(string.Empty, "Empty"); ValidateXMLDeserialization(a); }
/// <summary> /// Generates an new DDAttributesCollection from its Json representation. /// </summary> /// <param name="tr">Text reader stream that contains the Json document to deserialize.</param> /// <returns>an new DDAttributesCollection </returns> public static DDAttributesCollection Deserialize(TextReader tr) { var ac = new DDAttributesCollection(); Deserialize(ac, tr); return(ac); }
public void TestDDAttributesCollectionXmlSerializationNullValue() { var a = new DDAttributesCollection(); a.Add(string.Empty, null); ValidateXMLDeserialization(a); }
/// <summary> /// Serializes the specified DDAttributesCollection and writes the Json document to a text writer /// </summary> /// <param name="ac">the attributes collection to serialize</param> /// <param name="tw">text writer used to write the Json document.</param> public static void Serialize(this DDAttributesCollection ac, TextWriter tw) { using (JsonWriter writer = new JsonTextWriter(tw)) { ac.Serialize(writer); } }
/// <summary> /// Generates an new DDAttributesCollection from its Json representation. /// </summary> /// <param name="s">Stream that contains the Json document to deserialize.</param> /// <returns>an new DDAttributesCollection </returns> public static DDAttributesCollection Deserialize(Stream s) { var ac = new DDAttributesCollection(); Deserialize(ac, s); return(ac); }
/// <summary> /// Adds an new items to specified DDAttributesCollection from its Json representation. /// </summary> /// <param name="ac">The deserialized attributes collection.</param> /// <param name="tr">Text reader stream that contains the Json document to deserialize.</param> public static void Deserialize(this DDAttributesCollection ac, TextReader tr) { using (JsonReader reader = new JsonTextReader(tr)) { Deserialize(ac, reader); } }
/// <summary> /// Generates an new DDAttributesCollection from its Json representation. /// </summary> /// <param name="reader">Json stream reader</param> /// <returns>an new DDAttributesCollection</returns> public static DDAttributesCollection Deserialize(JsonReader reader) { var ac = new DDAttributesCollection(); Deserialize(ac, reader); return(ac); }
/// <summary> /// Adds an new items to specified DDAttributesCollection from its Json representation. /// </summary> /// <param name="ac">The deserialized attributes collection.</param> /// <param name="s">Json stream reader</param> internal static void JsonDeserialize(this DDAttributesCollection ac, JsonReader reader) { string prevValueString = null; string prevName = null; JsonToken prevTokenType = JsonToken.None; while (reader.Read()) { if (reader.TokenType == JsonToken.EndArray) { break; // end list of attributes } if ((reader.TokenType == JsonToken.PropertyName) && (prevTokenType == JsonToken.StartObject) && (reader.Value != null)) { ac.Add(reader.Value.ToString(), DDValueSje.Deserialize(reader)); } // save current values prevTokenType = reader.TokenType; if (reader.TokenType == JsonToken.None) { prevValueString = null; prevName = null; } else if (reader.TokenType == JsonToken.PropertyName) { prevName = reader.Value.ToString(); } else if (reader.TokenType == JsonToken.String) { prevValueString = reader.Value.ToString(); } } }
/// <summary> /// Generates an attribute from its XML representation. /// </summary> /// <param name="reader"></param> private static void AddDeserializedAttribute(DDAttributesCollection ac, XmlReader reader) { var name = reader.GetAttribute(DDSchema.XML_SERIALIZE_ATTRIBUTE_NAME); var t = reader.GetAttribute(DDSchema.XML_SERIALIZE_ATTRIBUTE_TYPE); if (name != null) { DDValue v = null; if (t != null) { v = DDValueSxe.Deserialize(reader); } ac.Add(name, v); } if ((name == null) || (t == null)) // reads and close empty node { if (reader.NodeType == XmlNodeType.Element) { reader.ReadStartElement(); } if (reader.NodeType == XmlNodeType.EndElement) { reader.ReadEndElement(); // need to close the opened element } } }
public void Set(DDAttributesCollection attr) { currentStackRaw.Attributes.Merge(attr, ResolveConflict.OVERWRITE); if (bNeedRebuild == false) { bNeedRebuild = true; } }
private void ValidateXMLDeserialization(DDAttributesCollection original, MemoryStream xml) { xml.Position = 0; UTestDrDataCommon.WriteMemmoryStreamToXmlFile(xml); var deserialized = XMLDeserialize(xml); ValidateDeserialization(original, (DDAttributesCollection)deserialized); }
private void ValidateDeserialization(DDAttributesCollection original, IFormatter iFormatter, Stream stream) { stream.Position = 0; UTestDrDataCommon.WriteMemmoryStreamToBinFile((MemoryStream)stream); var deserialized = (DDAttributesCollection)DeserializeItem(stream, iFormatter); ValidateDeserialization(original, deserialized); }
public void TestMergeEmptyCollectionWithEmptyCollection() { var a1 = new DDAttributesCollection(); var a2 = new DDAttributesCollection(); a1.Merge(a2); Assert.IsTrue(a1.Count == 0, "Incorrect attribute count."); }
public void TestMergeStockCollectionWithEmptyCollection() { var a1 = GetStockAttributesCollection(); var a2 = new DDAttributesCollection(); a1.Merge(a2); Assert.IsTrue(a1 == GetStockAttributesCollection(), "The both attribute collection must be equals."); Assert.IsTrue(a2 == new DDAttributesCollection(), "The both attribute collection must be equals."); }
private void testAddAttributeAndValue(string name, DDValue value) { var attrs = new DDAttributesCollection(); attrs.Add(name, value); Assert.IsTrue(attrs.Count == 1, "Collection items count is incorrect."); Assert.IsTrue(attrs.Contains(name), "Attribute '{0}' was not found by name.", name); Assert.IsTrue(attrs.ContainsValue(value), "Attribute '{0}' was not found by value.", value); }
public static void CompareAttributeCollection(DDAttributesCollection at1, DDAttributesCollection at2) { if ((at1 == null) && (at2 == null)) return; Assert.IsTrue(at1.Count == at2.Count, "Number of attributes must be the same in both collections."); foreach (var a1 in at1) { CompareAttribute(a1.Value, at2.GetValue(a1.Key, null)); } }
private MemoryStream XMLSerialize(DDAttributesCollection value) { var v = (DDAttributesCollectionSx)value; var memoryStream = new MemoryStream(); var serializer = new XmlSerializer(v.GetType()); serializer.Serialize(memoryStream, v); return(memoryStream); }
/// <summary> /// Adds an new items to specified DDAttributesCollection from its Json representation. /// </summary> /// <param name="ac">The deserialized attributes collection.</param> /// <param name="s">String that contains the Json document to deserialize.</param> public static void Deserialize(this DDAttributesCollection ac, string s) { var sr = new StringReader(s); using (JsonReader reader = new JsonTextReader(sr)) { Deserialize(ac, reader); } }
public void TestAddNewEmptyValueAutoGeneratedName() { var attrs = new DDAttributesCollection(); var name = attrs.Add(new DDValue()); Assert.IsTrue(attrs.Count == 1, "Collection items count is incorrect."); Assert.IsTrue(attrs.Contains(name), "Contains for autogenerated name is incorrected."); }
public void TestDDAttributesCollectionXmlSerializationFromFileSkipIncorrectValue() { var a = new DDAttributesCollection(); a.Add(string.Empty, null); a.Add("A", null); a.Add("B", new DDValue(new string[] { "", "Value_A", "Value_B" })); ValidateXMLDeserialization(a, UTestDrDataCommon.GetMemoryStreamFromFile()); }
private CHECK_EXPECTED_RESULT checkExpectedResult(DDAttributesCollection a, string attrName, string value) { if (a.Contains(attrName)) { var p = a[attrName].GetValueAsString(); log.WriteTrace("Starting match service property '{0}' value '{1}' by pattern '{2}'.", attrName, value, p); return(base.IsExpected(value, p) ? CHECK_EXPECTED_RESULT.SUCCESS : CHECK_EXPECTED_RESULT.FAILED); } return(CHECK_EXPECTED_RESULT.SKIPPED); }
/// <summary> /// Serializes the specified DDAttributesCollection and writes the Json document to a stream /// </summary> /// <param name="ac">the attributes collection to serialize</param> /// <param name="s">stream used to write the Json document.</param> public static void Serialize(this DDAttributesCollection ac, Stream s) { using (StreamWriter sw = new StreamWriter(s)) { using (JsonWriter writer = new JsonTextWriter(sw)) { ac.Serialize(writer); } } }
public void TestAddNewValueWithName1() { var attrs = new DDAttributesCollection(); var nameValue = "Юникод Name"; var nameReturn = attrs.Add(nameValue, new DDValue()); Assert.IsTrue(attrs.Count == 1, "Collection items count is incorrect."); Assert.IsTrue(attrs.Contains(nameReturn), "Contains for autogenerated name is incorrected."); Assert.IsTrue(nameReturn == nameValue, "Added name and returned must be same."); }
/// <summary> /// Adds an new items to specified DDAttributesCollection from its Json representation. /// </summary> /// <param name="ac">The deserialized attributes collection.</param> /// <param name="s">Stream that contains the Json document to deserialize.</param> public static void Deserialize(this DDAttributesCollection ac, Stream s) { using (StreamReader sr = new StreamReader(s)) { using (JsonReader reader = new JsonTextReader(sr)) { ac.Deserialize(reader); } } }
public void TestAddNewValueTestUniqNameSkip() { var attrs = new DDAttributesCollection(); try { var nameReturn_A1 = attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("A"), ResolveConflict.THROW_EXCEPTION); var nameReturn_A2 = attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("B"), ResolveConflict.SKIP); Assert.IsTrue(nameReturn_A2 == null, "Existing value should not be overwritten and return value should be equal null!"); Assert.IsTrue(attrs[TEST_ENUM.TEST_ENUM_A] == "A", "Existing value should not be overwritten!"); } catch (ArgumentException) { Assert.Fail("Incorrect ArgumentException, new value should be skipped!"); } catch (AssertFailedException e) { throw; } catch (Exception) { Assert.Fail("Incorrect Exception, new value should be skipped!"); } }
private void ValidateXMLDeserialization(DDAttributesCollection original, MemoryStream xml) { xml.Position = 0; UTestDrDataCommon.WriteMemmoryStreamToXmlFile(xml); var deserialyzed = XMLDeserialyze(xml); ValidateDeserialization(original, deserialyzed); }
public void TestAddNewValueWithName2() { var attrs = new DDAttributesCollection(); var nameReturn_a = attrs.Add(TEST_ENUM.TEST_ENUM_a, new DDValue("a")); var nameReturn_A = attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("A")); Assert.IsTrue(attrs.Count == 2, "Collection items count is incorrect."); Assert.IsTrue(attrs.Contains(nameReturn_a), "Contains for autogenerated name is incorrected."); Assert.IsTrue(attrs.Contains(nameReturn_A), "Contains for autogenerated name is incorrected."); Assert.IsTrue(nameReturn_a == TEST_ENUM.TEST_ENUM_a.ToString(), "Added name and returned must be same."); Assert.IsTrue(nameReturn_A == TEST_ENUM.TEST_ENUM_A.ToString(), "Added name and returned must be same."); Assert.IsTrue(attrs[TEST_ENUM.TEST_ENUM_a] == "a", "The added value is incorrected."); Assert.IsTrue(attrs[TEST_ENUM.TEST_ENUM_A] == "A", "The added value is incorrected."); }
public void TestDDAttributesCollectionISerializableNullData() { var ddAttributesCollection = new DDAttributesCollection(); ValidateDeserialization(ddAttributesCollection, new BinaryFormatter()); }
private void ValidateDeserialization(DDAttributesCollection original, IFormatter iFormatter) { var stream = SerializeItem(original, iFormatter); ValidateDeserialization(original, iFormatter, stream); }
public void TestDDAttributesCollectionXmlSerializationFromFileSkipIncorrectValue() { var a = new DDAttributesCollection(); a.Add(string.Empty, null); a.Add("A", null); a.Add("B", new DDValue(new string[]{"", "Value_A", "Value_B"})); ValidateXMLDeserialization(a, UTestDrDataCommon.GetMemoryStreamFromFile()); }
private void ValidateXMLDeserialization(DDAttributesCollection original) { var xml = XMLSerialyze(original); ValidateXMLDeserialization(original, xml); }
private DDAttributesCollection GetStockAttributesCollection() { var attrs = new DDAttributesCollection(); Assert.IsTrue(attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("A"), ResolveConflict.THROW_EXCEPTION) == TEST_ENUM.TEST_ENUM_A.ToString(), "Incorrect attribute name."); Assert.IsTrue(attrs.Add(TEST_ENUM.TEST_ENUM_B, new DDValue("B"), ResolveConflict.OVERWRITE) == TEST_ENUM.TEST_ENUM_B.ToString(), "Incorrect attribute name."); Assert.IsTrue(attrs.Add(TEST_ENUM.TEST_ENUM_a, new DDValue("a"), ResolveConflict.OVERWRITE) == TEST_ENUM.TEST_ENUM_a.ToString(), "Incorrect attribute name."); Assert.IsTrue(attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("Skipped"), ResolveConflict.SKIP) == null, "Skipped attribute name should be null."); Assert.IsTrue(attrs.Add(TEST_ENUM.TEST_ENUM_NULL, null) == TEST_ENUM.TEST_ENUM_NULL.ToString(), "Incorrect attribute value."); return attrs; }
public void TestAddNewValueTestUniqNameException2() { var attrs = new DDAttributesCollection(); try { var nameReturn_A1 = attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("A"), ResolveConflict.SKIP); var nameReturn_A2 = attrs.Add(TEST_ENUM.TEST_ENUM_A, new DDValue("B"), ResolveConflict.THROW_EXCEPTION); Assert.Fail("Add new value with not uniq name!"); } catch (ArgumentException) { Assert.IsTrue(attrs[TEST_ENUM.TEST_ENUM_A] == "A", "Cannot find first value by name."); } catch (AssertFailedException e) { throw; } catch (Exception e) { Assert.Fail("Catch incorrect exception after attempt to add new value with not uniq name!" + e.Message); } }
public static Stream SerializeItem(DDAttributesCollection iSerializable, IFormatter formatter) { var s = new MemoryStream(0); SerializeItem(s, iSerializable, formatter); return s; }
private void ValidateDeserialization(DDAttributesCollection original, IFormatter iFormatter, Stream stream) { stream.Position = 0; UTestDrDataCommon.WriteMemmoryStreamToBinFile((MemoryStream)stream); var deserialyzed = (DDAttributesCollection)DeserializeItem(stream, iFormatter); ValidateDeserialization(original, deserialyzed); }
private MemoryStream XMLSerialyze(DDAttributesCollection value) { var memoryStream = new MemoryStream(); var serializer = new XmlSerializer(value.GetType()); serializer.Serialize(memoryStream, value); return memoryStream; }
private void ValidateDeserialization(DDAttributesCollection original, DDAttributesCollection deserialyzed) { Assert.IsTrue(original == deserialyzed, "Deserialized object must be mathematically equal to the original object."); Assert.AreNotEqual(original, deserialyzed, "Deserialized object should not be same as original object."); }