示例#1
0
        public void SpecialConstructorInitializesProperties()
        {
            ASString content = new ASString("abc");
            AMFBody body = new AMFBody("request", "response", content);

            Assert.AreEqual("request", body.RequestTarget);
            Assert.AreEqual("response", body.ResponseTarget);
            Assert.AreSame(content, body.Content);
        }
示例#2
0
        public void SpecialConstructorInitializesProperties()
        {
            ASString content = new ASString("abc");
            AMFHeader header = new AMFHeader("header", true, content);

            Assert.AreEqual("header", header.Name);
            Assert.IsTrue(header.MustUnderstand);
            Assert.AreEqual(content, header.Content);
        }
示例#3
0
        public void CanGetAndSetProperties()
        {
            ASString content = new ASString("abc");
            AMFHeader header = new AMFHeader();

            Assert.IsNull(header.Content);
            header.Content = content;
            Assert.AreSame(content, header.Content);

            Assert.IsFalse(header.MustUnderstand);
            header.MustUnderstand = true;
            Assert.IsTrue(header.MustUnderstand);

            Assert.IsNull(header.Name);
            header.Name = "abc";
            Assert.AreEqual("abc", header.Name);
        }
示例#4
0
        public void CanGetAndSetProperties()
        {
            ASString content = new ASString("abc");

            AMFBody body = new AMFBody();

            Assert.IsNull(body.Content);
            body.Content = content;
            Assert.AreSame(content, body.Content);

            Assert.IsNull(body.RequestTarget);
            body.RequestTarget = "abc";
            Assert.AreEqual("abc", body.RequestTarget);

            Assert.IsNull(body.ResponseTarget);
            body.ResponseTarget = "def";
            Assert.AreEqual("def", body.ResponseTarget);
        }
示例#5
0
        public void IndexedValueIndexer()
        {
            ASArray array = new ASArray(new IASValue[] { null, new ASString("abc"), null });

            Assert.AreEqual(new ASString("abc"), array[1]);
            array[1] = new ASString("def");
            Assert.AreEqual(new ASString("def"), array[1]);
        }
示例#6
0
 public void IndexedValueSetIndexerThrowsIfOutOfRange(int index)
 {
     ASArray array = new ASArray(new IASValue[] { null, null, null });
     array[index] = new ASString("abc");
 }
示例#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();
        }
        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());
        }
        public void WriteObject_Strings_LongFormat_AMF0()
        {
            ASString value = new ASString(new string('a', 100000));

            output.BeginObjectStream();
            output.WriteObject(value);
            output.EndObjectStream();

            Assert.AreEqual(1 /*code*/ + 4 /*length*/ + 100000 /*value*/, stream.Length);
        }
示例#10
0
        /// <inheritdoc />
        public override bool Equals(object obj)
        {
            ASString other = obj as ASString;

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