Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void ConstructorWithString()
        {
            ASXmlDocument xml = new ASXmlDocument("<root />");

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

            Assert.AreEqual("", xml.XmlString);
            Assert.AreEqual("", xml.XmlDocument.OuterXml);
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public void ReadObject_XmlDocuments(AMFObjectEncoding objectEncoding, byte[] bytes, string expectedValue)
        {
            SetStreamContents(bytes);

            input.BeginObjectStream();
            ASXmlDocument result = (ASXmlDocument)input.ReadObject();

            Assert.AreEqual(objectEncoding, input.ObjectEncoding);
            input.EndObjectStream();

            Assert.AreEqual(expectedValue, result.XmlString);
        }
Ejemplo n.º 7
0
        public void ReadObject_Strings_Caching_AMF3()
        {
            ASString empty  = new ASString("");
            ASString valueA = new ASString("a");
            ASString valueB = new ASString("b");
            ASString valueC = new ASString("c");

            byte[] bytes = 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
            };
            SetStreamContents(bytes);

            input.BeginObjectStream();
            Assert.AreEqual(empty, input.ReadObject());  // empty strings are not cached
            Assert.AreEqual(valueA, input.ReadObject()); // will get string ref #0
            Assert.AreEqual(empty, input.ReadObject());  // empty strings are not cached
            Assert.AreEqual(valueB, input.ReadObject()); // will get string ref #1
            Assert.AreEqual(valueA, input.ReadObject()); // will use string ref #0
            ASXmlDocument xml = (ASXmlDocument)input.ReadObject();

            Assert.AreEqual(valueB.Value, xml.XmlString); // XML contents are same as valueB, will use ref #1
            ASArray array = (ASArray)input.ReadObject();  // Array contains valueA and valueB and mixed values with key valueB and value valueA

            CollectionAssert.AreElementsEqual(new object[] { valueA, valueB }, array.IndexedValues);
            Assert.AreEqual(valueA, array.DynamicProperties[valueB.Value]);
            ASObject obj = (ASObject)input.ReadObject();  // Object has class name valueB contains member with key valueC and value valueA dynamic property with key valueA and value valueB

            CollectionAssert.AreElementsEqual(new object[] { valueC }, obj.MemberValues);
            Assert.AreEqual(valueB, obj.DynamicProperties[valueA.Value]);
            Assert.AreEqual(valueB.Value, obj.Class.ClassAlias);
            Assert.AreEqual(ASClassLayout.Dynamic, obj.Class.Layout);
            CollectionAssert.AreElementsEqual(new string[] { valueC.Value }, obj.Class.MemberNames);

            Assert.AreEqual(AMFObjectEncoding.AMF3, input.ObjectEncoding);
            input.EndObjectStream();
        }
Ejemplo n.º 8
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());
        }