public void WriteObject_ByteArrays_WrittenInSegments(AMFObjectEncoding objectEncoding, byte[] expected, byte[] bytes) { IASValue byteArray = Mocks.CreateMock <IASValue>(); byteArray.AcceptVisitor(serializer, null); LastCall.IgnoreArguments().Do((AcceptVisitorDelegate) delegate(IActionScriptSerializer theSerializer, IASValueVisitor visitor) { ArraySegment <byte>[] segments = new ArraySegment <byte> [bytes.Length]; for (int i = 0; i < bytes.Length; i++) { segments[i] = new ArraySegment <byte>(bytes, i, 1); } visitor.VisitByteArray(serializer, bytes.Length, segments); }); Mocks.ReplayAll(); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(byteArray); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void BeginAndEndObjectStream(AMFObjectEncoding encoding, byte[] expected) { output.ObjectEncoding = encoding; output.BeginObjectStream(); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
/// <summary> /// Creates an AMF data output writer. /// Initially uses the <see cref="AMFObjectEncoding.AMF0" /> object encoding. /// </summary> /// <param name="stream">The output stream</param> /// <param name="serializer">The ActionScript serializer to use for object serialization</param> public AMFDataOutput(Stream stream, IActionScriptSerializer serializer) { this.stream = stream; this.serializer = serializer; objectEncoding = AMFObjectEncoding.AMF0; utf8Encoding = new UTF8Encoding(false, false); }
/// <summary> /// Creates an AMF data output writer. /// Initially uses the <see cref="AMFObjectEncoding.AMF0" /> object encoding. /// </summary> /// <param name="stream">The output stream</param> /// <param name="serializer">The ActionScript serializer to use for object serialization</param> public AMFDataOutput(Stream stream, IActionScriptSerializer serializer) { this.stream = stream; this.serializer = serializer; objectEncoding = AMFObjectEncoding.AMF0; utf8Encoding = new UTF8Encoding(false, false); }
[Row(AMFObjectEncoding.AMF3, new byte[] { }, ExpectedException = typeof(AMFException))] // Not supported in AMF3 public void WriteObject_UnsupportedValues(AMFObjectEncoding objectEncoding, byte[] expected) { output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(ASUnsupported.Value); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Booleans(AMFObjectEncoding objectEncoding, byte[] expected, bool value) { output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(ASBoolean.ToASBoolean(value)); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Strings(AMFObjectEncoding objectEncoding, byte[] expected, string value) { output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(new ASString(value)); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
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()); }
public void WriteObject_Dates(AMFObjectEncoding objectEncoding, byte[] expected, int millisecondsSinceEpoch) { ASDate date = new ASDate(1, 0); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(date); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_ByteArrays(AMFObjectEncoding objectEncoding, byte[] expected, byte[] bytes) { ASByteArray byteArray = new ASByteArray(bytes); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(byteArray); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void ReadObject_Nulls(AMFObjectEncoding objectEncoding, byte[] bytes) { SetStreamContents(bytes); input.BeginObjectStream(); object result = input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.IsNull(result); }
public void ReadObject_UnsupportedValues(AMFObjectEncoding objectEncoding, byte[] bytes) { SetStreamContents(bytes); input.BeginObjectStream(); ASUnsupported result = (ASUnsupported)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreSame(ASUnsupported.Value, result); }
public void ReadObject_Strings(AMFObjectEncoding objectEncoding, byte[] bytes, string expectedValue) { SetStreamContents(bytes); input.BeginObjectStream(); ASString result = (ASString)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreEqual(expectedValue, result.Value); }
public void ReadObject_Dates(AMFObjectEncoding objectEncoding, byte[] bytes, int millisecondsSinceEpoch, int timezoneOffsetMinutes) { SetStreamContents(bytes); input.BeginObjectStream(); ASDate result = (ASDate)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreEqual(millisecondsSinceEpoch, result.MillisecondsSinceEpoch); Assert.AreEqual(timezoneOffsetMinutes, result.TimeZoneOffsetMinutes); }
public void WriteObject_Arrays(AMFObjectEncoding objectEncoding, byte[] expected, string[] values, string[] mixedKeysAndValues) { ASArray array = new ASArray(WrapStrings(values)); for (int i = 0; i < mixedKeysAndValues.Length; i += 2) { array.DynamicProperties[mixedKeysAndValues[i]] = new ASString(mixedKeysAndValues[i + 1]); } output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(array); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void ReadObject_Arrays(AMFObjectEncoding objectEncoding, byte[] bytes, string[] indexedValues, string[] mixedKeysAndValues) { SetStreamContents(bytes); input.BeginObjectStream(); ASArray result = (ASArray)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); CollectionAssert.AreElementsEqual(WrapStrings(indexedValues), result.IndexedValues); Assert.AreEqual(mixedKeysAndValues.Length / 2, result.DynamicProperties.Count); for (int i = 0; i < mixedKeysAndValues.Length; i += 2) { Assert.AreEqual(new ASString(mixedKeysAndValues[i + 1]), result.DynamicProperties[mixedKeysAndValues[i]]); } }
public void WriteObject_Objects(AMFObjectEncoding objectEncoding, byte[] expected, string className, ASClassLayout classLayout, string[] memberNames, string[] memberValues, string[] dynamicKeysAndValues) { ASClass @class = new ASClass(className, classLayout, memberNames); ASObject obj = new ASObject(@class, WrapStrings(memberValues), new Dictionary <string, IASValue>()); for (int i = 0; i < dynamicKeysAndValues.Length; i += 2) { obj.DynamicProperties[dynamicKeysAndValues[i]] = new ASString(dynamicKeysAndValues[i + 1]); } output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(obj); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Objects_ReferenceCaching(AMFObjectEncoding objectEncoding, byte[] expected) { // Create an array with multiple copies of each kind of object and including a self-reference ASObject obj = new ASObject(); ASByteArray byteArray = new ASByteArray(new byte[0]); ASDate date = new ASDate(1, 0); ASArray array = new ASArray(6); array.IndexedValues[0] = obj; array.IndexedValues[1] = byteArray; array.IndexedValues[2] = date; array.IndexedValues[3] = obj; array.IndexedValues[4] = byteArray; array.IndexedValues[5] = date; array.DynamicProperties["a"] = array; output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(array); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void ReadObject_Objects(AMFObjectEncoding objectEncoding, byte[] bytes, string className, ASClassLayout classLayout, string[] memberNames, string[] memberValues, string[] dynamicKeysAndValues) { SetStreamContents(bytes); input.BeginObjectStream(); ASObject result = (ASObject)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreEqual(classLayout, result.Class.Layout); Assert.AreEqual(className, result.Class.ClassAlias); CollectionAssert.AreElementsEqual(memberNames, result.Class.MemberNames); CollectionAssert.AreElementsEqual(WrapStrings(memberValues), result.MemberValues); Assert.AreEqual(dynamicKeysAndValues.Length / 2, result.DynamicProperties.Count); for (int i = 0; i < dynamicKeysAndValues.Length; i += 2) { Assert.AreEqual(new ASString(dynamicKeysAndValues[i + 1]), result.DynamicProperties[dynamicKeysAndValues[i]]); } }
public void WriteObject_Booleans(AMFObjectEncoding objectEncoding, byte[] expected, bool value) { output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(ASBoolean.ToASBoolean(value)); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void BeginAndEndObjectStream(AMFObjectEncoding encoding, byte[] expected) { output.ObjectEncoding = encoding; output.BeginObjectStream(); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void ReadObject_Arrays(AMFObjectEncoding objectEncoding, byte[] bytes, string[] indexedValues, string[] mixedKeysAndValues) { SetStreamContents(bytes); input.BeginObjectStream(); ASArray result = (ASArray)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); CollectionAssert.AreElementsEqual(WrapStrings(indexedValues), result.IndexedValues); Assert.AreEqual(mixedKeysAndValues.Length / 2, result.DynamicProperties.Count); for (int i = 0; i < mixedKeysAndValues.Length; i += 2) Assert.AreEqual(new ASString(mixedKeysAndValues[i + 1]), result.DynamicProperties[mixedKeysAndValues[i]]); }
public void ReadObject_Objects(AMFObjectEncoding objectEncoding, byte[] bytes, string className, ASClassLayout classLayout, string[] memberNames, string[] memberValues, string[] dynamicKeysAndValues) { SetStreamContents(bytes); input.BeginObjectStream(); ASObject result = (ASObject)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreEqual(classLayout, result.Class.Layout); Assert.AreEqual(className, result.Class.ClassAlias); CollectionAssert.AreElementsEqual(memberNames, result.Class.MemberNames); CollectionAssert.AreElementsEqual(WrapStrings(memberValues), result.MemberValues); Assert.AreEqual(dynamicKeysAndValues.Length / 2, result.DynamicProperties.Count); for (int i = 0; i < dynamicKeysAndValues.Length; i += 2) Assert.AreEqual(new ASString(dynamicKeysAndValues[i + 1]), result.DynamicProperties[dynamicKeysAndValues[i]]); }
public void ReadObject_Strings(AMFObjectEncoding objectEncoding, byte[] bytes, string expectedValue) { SetStreamContents(bytes); input.BeginObjectStream(); ASString result = (ASString)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreEqual(expectedValue, result.Value); }
public void ReadObject_Dates(AMFObjectEncoding objectEncoding, byte[] bytes, int millisecondsSinceEpoch, int timezoneOffsetMinutes) { SetStreamContents(bytes); input.BeginObjectStream(); ASDate result = (ASDate)input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreEqual(millisecondsSinceEpoch, result.MillisecondsSinceEpoch); Assert.AreEqual(timezoneOffsetMinutes, result.TimeZoneOffsetMinutes); }
public void ReadObject_Nulls(AMFObjectEncoding objectEncoding, byte[] bytes) { SetStreamContents(bytes); input.BeginObjectStream(); object result = input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.IsNull(result); }
public void WriteObject_Dates(AMFObjectEncoding objectEncoding, byte[] expected, int millisecondsSinceEpoch) { ASDate date = new ASDate(1, 0); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(date); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Objects(AMFObjectEncoding objectEncoding, byte[] expected, string className, ASClassLayout classLayout, string[] memberNames, string[] memberValues, string[] dynamicKeysAndValues) { ASClass @class = new ASClass(className, classLayout, memberNames); ASObject obj = new ASObject(@class, WrapStrings(memberValues), new Dictionary<string, IASValue>()); for (int i = 0; i < dynamicKeysAndValues.Length; i += 2) obj.DynamicProperties[dynamicKeysAndValues[i]] = new ASString(dynamicKeysAndValues[i + 1]); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(obj); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Objects_ReferenceCaching(AMFObjectEncoding objectEncoding, byte[] expected) { // Create an array with multiple copies of each kind of object and including a self-reference ASObject obj = new ASObject(); ASByteArray byteArray = new ASByteArray(new byte[0]); ASDate date = new ASDate(1, 0); ASArray array = new ASArray(6); array.IndexedValues[0] = obj; array.IndexedValues[1] = byteArray; array.IndexedValues[2] = date; array.IndexedValues[3] = obj; array.IndexedValues[4] = byteArray; array.IndexedValues[5] = date; array.DynamicProperties["a"] = array; output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(array); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Arrays(AMFObjectEncoding objectEncoding, byte[] expected, string[] values, string[] mixedKeysAndValues) { ASArray array = new ASArray(WrapStrings(values)); for (int i = 0; i < mixedKeysAndValues.Length; i += 2) array.DynamicProperties[mixedKeysAndValues[i]] = new ASString(mixedKeysAndValues[i + 1]); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(array); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_ByteArrays_WrittenInSegments(AMFObjectEncoding objectEncoding, byte[] expected, byte[] bytes) { IASValue byteArray = Mocks.CreateMock<IASValue>(); byteArray.AcceptVisitor(serializer, null); LastCall.IgnoreArguments().Do((AcceptVisitorDelegate) delegate(IActionScriptSerializer theSerializer, IASValueVisitor visitor) { ArraySegment<byte>[] segments = new ArraySegment<byte>[bytes.Length]; for (int i = 0; i < bytes.Length; i++) { segments[i] = new ArraySegment<byte>(bytes, i, 1); } visitor.VisitByteArray(serializer, bytes.Length, segments); }); Mocks.ReplayAll(); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(byteArray); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_ByteArrays(AMFObjectEncoding objectEncoding, byte[] expected, byte[] bytes) { ASByteArray byteArray = new ASByteArray(bytes); output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(byteArray); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void Initialize(string destination, AMFObjectEncoding objectEncoding) { externalInterface.InvokeMethod("remoteObjectTestProxy_Initialize", destination, objectEncoding.ToString()); }
public void ReadObject_UnsupportedValues(AMFObjectEncoding objectEncoding, byte[] bytes) { SetStreamContents(bytes); input.BeginObjectStream(); ASUnsupported result = (ASUnsupported) input.ReadObject(); Assert.AreEqual(objectEncoding, input.ObjectEncoding); input.EndObjectStream(); Assert.AreSame(ASUnsupported.Value, result); }
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()); }
[Row(AMFObjectEncoding.AMF3, new byte[] { }, ExpectedException=typeof(AMFException))] // Not supported in AMF3 public void WriteObject_UnsupportedValues(AMFObjectEncoding objectEncoding, byte[] expected) { output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(ASUnsupported.Value); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Strings(AMFObjectEncoding objectEncoding, byte[] expected, string value) { output.ObjectEncoding = objectEncoding; output.BeginObjectStream(); output.WriteObject(new ASString(value)); output.EndObjectStream(); CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void Initialize(string destination, AMFObjectEncoding objectEncoding) { externalInterface.InvokeMethod("remoteObjectTestProxy_Initialize", destination, objectEncoding.ToString()); }