Esempio n. 1
0
        public void ConstructorWithString()
        {
            ASXmlDocument xml = new ASXmlDocument("<root />");

            Assert.AreEqual("<root />", xml.XmlString);
            Assert.AreEqual("<root />", xml.XmlDocument.OuterXml);
        }
Esempio n. 2
0
        public void DefaultConstructor()
        {
            ASXmlDocument xml = new ASXmlDocument();

            Assert.AreEqual("", xml.XmlString);
            Assert.AreEqual("", xml.XmlDocument.OuterXml);
        }
Esempio n. 3
0
        public void ConstructorWithXmlDocument()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<root />");

            ASXmlDocument xml = new ASXmlDocument(doc);

            Assert.AreEqual(doc.OuterXml, xml.XmlString);
            Assert.AreEqual(doc, xml.XmlDocument);
        }
Esempio n. 4
0
        public void GetterAndSetterInteractions()
        {
            ASXmlDocument xml = new ASXmlDocument("<root />");

            Assert.AreEqual("<root />", xml.XmlString);
            Assert.AreEqual("<root />", xml.XmlDocument.OuterXml); // black box impl. note: this clears the internal XmlString
            Assert.AreEqual("<root />", xml.XmlString);

            // set using XmlString
            xml.XmlString = "<trunk />";
            Assert.AreEqual("<trunk />", xml.XmlString);
            Assert.AreEqual("<trunk />", xml.XmlDocument.OuterXml);

            // modify under covers and note that value is reflected immediately because XmlString not
            // cached when an XmlDocument is present
            xml.XmlDocument.DocumentElement.SetAttribute("attr", "value");
            Assert.AreEqual("<trunk attr=\"value\" />", xml.XmlString);

            // set using XmlDocument
            XmlDocument doc = new XmlDocument();
            xml.XmlDocument = doc;
            Assert.AreEqual("", xml.XmlString);
            Assert.AreSame(doc, xml.XmlDocument);
        }
Esempio n. 5
0
        public void WriteObject_Strings_Caching_AMF3()
        {
            ASString empty = new ASString("");
            ASString valueA = new ASString("a");
            ASString valueB = new ASString("b");
            ASString valueC = new ASString("c");
            ASXmlDocument xml = new ASXmlDocument(valueB.Value);
            ASArray array = new ASArray(new IASValue[] { valueA, valueB });
            array.DynamicProperties[valueB.Value] = valueA;
            ASClass clazz = new ASClass(valueB.Value, ASClassLayout.Dynamic, new string[] { valueC.Value });
            ASObject obj = new ASObject(clazz);
            obj.MemberValues[0] = valueC;
            obj.DynamicProperties[valueA.Value] = valueB;

            output.ObjectEncoding = AMFObjectEncoding.AMF3;
            output.BeginObjectStream();
            output.WriteObject(empty); // empty strings are not cached
            output.WriteObject(valueA); // will get string ref #0
            output.WriteObject(empty); // empty strings are not cached
            output.WriteObject(valueB); // will get string ref #1
            output.WriteObject(valueA); // will use string ref #0
            output.WriteObject(xml); // XML contents are same as valueB, will use ref #1
            output.WriteObject(array); // Array contains valueA and valueB and mixed values with key valueB and value valueA
            output.WriteObject(obj); // Object has class name valueB contains member with key valueC and value valueA dynamic property with key valueA and value valueB
            output.EndObjectStream();

            CollectionAssert.AreElementsEqual(
                new byte[] { (byte)AMF0ObjectTypeCode.AMF3Data,
                    (byte)AMF3ObjectTypeCode.String, 0x01, // ""
                    (byte)AMF3ObjectTypeCode.String, 0x03, 0x61, // valueA
                    (byte)AMF3ObjectTypeCode.String, 0x01, // ""
                    (byte)AMF3ObjectTypeCode.String, 0x03, 0x62, // valueB
                    (byte)AMF3ObjectTypeCode.String, 0x00, // valueA (by ref)
                    (byte)AMF3ObjectTypeCode.Xml, 0x02, // valueB (by ref)
                    (byte)AMF3ObjectTypeCode.Array, 0x05, 0x02, (byte)AMF3ObjectTypeCode.String, 0x00, 0x01, (byte)AMF3ObjectTypeCode.String, 0x00, (byte)AMF3ObjectTypeCode.String, 0x02, // array
                    (byte)AMF3ObjectTypeCode.Object, 0x1b, 0x02, 0x03, 0x63, (byte)AMF3ObjectTypeCode.String, 0x04, 0x00, (byte)AMF3ObjectTypeCode.String, 0x02, 0x01 // object
                }, stream.ToArray());
        }
Esempio n. 6
0
        public void WriteObject_XmlDocuments(AMFObjectEncoding objectEncoding, byte[] expected, string value)
        {
            ASXmlDocument xmlDocument = new ASXmlDocument(value);

            output.ObjectEncoding = objectEncoding;
            output.BeginObjectStream();
            output.WriteObject(xmlDocument);
            output.EndObjectStream();

            CollectionAssert.AreElementsEqual(expected, stream.ToArray());
        }
Esempio n. 7
0
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            ASXmlDocument other = obj as ASXmlDocument;

            return(other != null && XmlString == other.XmlString);
        }