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 ConstructWithArray() { int[] array = new int[] { 1, 2, 3 }; CollectionDomain domain = new CollectionDomain(array); CollectionAssert.AreElementsEqual(array, domain); }
public void TestRemoveEmptyElements() { string[] arrayWithEmpties = new string[] { "", "lorem", "ipsum", null, String.Empty, "xxx" }; string[] expectedArray = new string[] { "lorem", "ipsum", "xxx" }; int expectedLength = 3; string[] returnedArray = LipsumUtilities.RemoveEmptyElements(arrayWithEmpties); CollectionAssert.DoesNotContain(returnedArray, ""); CollectionAssert.AllItemsAreNotNull(returnedArray); CollectionAssert.AllItemsAreInstancesOfType(returnedArray, typeof(String)); #if PORTABLE Assert.AreEqual(expectedLength, returnedArray.Length); CollectionAssert.AreEqual(expectedArray, returnedArray); #else CollectionAssert.AreCountEqual(expectedLength, returnedArray); CollectionAssert.AreElementsEqual(expectedArray, returnedArray); #endif }
public void WriteObject_Objects_Externalizable_AMF3() { IExternalizable externalizableValue = Mocks.CreateMock <IExternalizable>(); externalizableValue.WriteExternal(output); LastCall.Do((WriteExternalDelegate) delegate(IDataOutput outputToUse) { // Note: outputToUse will be the same instance as output which we've already // tested so we don't need to try all combinations here. Just a few as a sanity check. outputToUse.WriteUTF("abc"); outputToUse.WriteInt(10); outputToUse.WriteObject(new ASString("def")); }); ASClass @class = new ASClass("class", ASClassLayout.Externalizable, EmptyArray <string> .Instance); ASExternalizableObject obj = new ASExternalizableObject(@class, externalizableValue); Mocks.ReplayAll(); output.ObjectEncoding = AMFObjectEncoding.AMF3; output.BeginObjectStream(); output.WriteObject(obj); output.EndObjectStream(); byte[] expected = new byte[] { (byte)AMF0ObjectTypeCode.AMF3Data, (byte)AMF3ObjectTypeCode.Object, 0x07, 0x0b, 0x63, 0x6c, 0x61, 0x73, 0x73, // class def 0x00, 0x03, 0x61, 0x62, 0x63, // write utf "abc" 0x00, 0x00, 0x00, 0x0a, // write int 10 (byte)AMF3ObjectTypeCode.String, 0x07, 0x64, 0x65, 0x66 // write object "def" }; CollectionAssert.AreElementsEqual(expected, stream.ToArray()); }
public void WriteObject_Objects_ClassDefinitionCaching_AMF3() { // Write out two untyped dynamic objects and two typed normal // objects and ensure the class definition is reused. ASObject untyped1 = new ASObject(); ASObject untyped2 = new ASObject(); ASClass @class = new ASClass("class", ASClassLayout.Normal, EmptyArray <string> .Instance); ASObject typed1 = new ASObject(@class); ASObject typed2 = new ASObject(@class); Mocks.ReplayAll(); output.ObjectEncoding = AMFObjectEncoding.AMF3; output.BeginObjectStream(); output.WriteObject(untyped1); output.WriteObject(typed1); output.WriteObject(untyped2); output.WriteObject(typed2); output.EndObjectStream(); byte[] expected = new byte[] { (byte)AMF0ObjectTypeCode.AMF3Data, (byte)AMF3ObjectTypeCode.Object, 0x0b, 0x01, 0x01, // untyped1 (byte)AMF3ObjectTypeCode.Object, 0x03, 0x0b, 0x63, 0x6c, 0x61, 0x73, 0x73, // typed1 (byte)AMF3ObjectTypeCode.Object, 0x01, 0x01, // untyped2 using cached class definition (byte)AMF3ObjectTypeCode.Object, 0x05, // typed2 using cached class definition }; 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 Servers_GetterAndSetter() { CollectionAssert.AreElementsEqual(new string[] { }, pool.Servers); pool.Servers = new string[] { "localhost", "192.168.0.1:2001" }; CollectionAssert.AreElementsEqual(new string[] { "127.0.0.1:11211", "192.168.0.1:2001" }, pool.Servers); CollectionAssert.AreElementsEqual(new string[] { "127.0.0.1:11211", "192.168.0.1:2001" }, pool.SockIOPool.Servers); }
public void WriteByte() { output.WriteByte(1); output.WriteByte(0); output.WriteByte(42); CollectionAssert.AreElementsEqual(new byte[] { 1, 0, 42 }, stream.ToArray()); }
public void CanOverrideAttributesSetOnAnotherFile() { EmailSender sender = (EmailSender)_container.Resolve <ISender>("email_sender2"); Assert.AreEqual("example.dot.org", sender.Host); CollectionAssert.AreElementsEqual(new string[] { "Kaitlyn", "Matthew", "Lauren" }, sender.To); }
public void BoundaryOfCollectionWithTwoElement() { int[] array = new int[] { 1, 2 }; CollectionDomain domain = new CollectionDomain(array); IDomain boundary = domain.Boundary; CollectionAssert.AreElementsEqual(array, boundary); }
public void BoundaryOfCollectionWithMoreThanTwoElement() { int[] array = new int[] { 1, 2, 3, 4, 5, 6 }; int[] barray = new int[] { 1, 6 }; CollectionDomain domain = new CollectionDomain(array); IDomain boundary = domain.Boundary; CollectionAssert.AreElementsEqual(barray, boundary); }
public void ReadBytes() { SetStreamContents(new byte[] { 3, 2 }); byte[] bytes = new byte[5]; input.ReadBytes(bytes, 2, 2); CollectionAssert.AreElementsEqual(new byte[] { 0, 0, 3, 2, 0 }, bytes); }
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 TestParameterAlias() { SerializerSettings context = new SerializerSettings(); ITypeData typeData = new TypeData <AliasedConstructor>(context); List <IPropertyData> expected = new List <IPropertyData>(); expected.Add(typeData.FindProperty("IntProp")); CollectionAssert.AreElementsEqual(expected, typeData.ConstructorParameters); }
[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_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 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 TestNamedOnlyIgnoreCase() { SerializerSettings context = new SerializerSettings(); TypeData typeData = new TypeData <NamedOnlyIgnoreCaseConstructor>(context); IList <IPropertyData> propData = typeData.ConstructorParameters; List <IPropertyData> expected = new List <IPropertyData>(); expected.Add(typeData.FindProperty("StringPropA")); expected.Add(typeData.FindProperty("StringPropB")); CollectionAssert.AreElementsEqual(expected, propData); }
public void AreElementsEqualUnequalLengthFail() { ArrayList arr3 = new ArrayList(); arr3.Add("One"); arr3.Add("Two"); arr3.Add("Three"); arr3.Add("Four"); arr3.Add("Five"); CollectionAssert.AreElementsEqual(arr, arr3); }
public void GetMultipleReturnsUpToDateValuesAfterSetOrRemove() { Cache.Set("key1", "abc"); Cache.Set("key3", "def"); CollectionAssert.AreElementsEqual(new object[] { "abc", null, "def" }, Cache.GetMultiple(new string[] { "key1", "key2", "key3" })); Cache.Remove("key1"); Cache.Set("key2", "ghi", new CacheOptions()); Cache.Set("key3", "DEF"); CollectionAssert.AreElementsEqual(new object[] { null, "ghi", "DEF" }, Cache.GetMultiple(new string[] { "key1", "key2", "key3" })); }
public void FlushClearsAllValues() { Cache.Set("key1", "abc"); Cache.Set("key2", "def"); Cache.Set("key3", "ghi"); Cache.Flush(); CollectionAssert.AreElementsEqual(new object[] { null, null, null }, Cache.GetMultiple(new string[] { "key1", "key2", "key3" })); Assert.IsFalse(Cache.ContainsKey("key1")); Assert.IsFalse(Cache.ContainsKey("key2")); Assert.IsFalse(Cache.ContainsKey("key3")); }
public void ServerWeights_GetterAndSetter() { Assert.IsNull(pool.ServerWeights); int[] value = new int[] { 1, 2 }; pool.ServerWeights = value; CollectionAssert.AreElementsEqual(value, pool.ServerWeights); CollectionAssert.AreElementsEqual(value, pool.SockIOPool.Weights); value = null; pool.ServerWeights = value; Assert.IsNull(pool.ServerWeights); Assert.IsNull(pool.SockIOPool.Weights); }
public void ReadObject_ByteArrays_AMF3() { byte[] bytes = new byte[] { (byte)AMF0ObjectTypeCode.AMF3Data, (byte)AMF3ObjectTypeCode.ByteArray, 0x1f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; byte[] expectedValue = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; SetStreamContents(bytes); input.BeginObjectStream(); ASByteArray result = (ASByteArray)input.ReadObject(); Assert.AreEqual(AMFObjectEncoding.AMF3, input.ObjectEncoding); input.EndObjectStream(); CollectionAssert.AreElementsEqual(expectedValue, result.Bytes.Array); }
public void TestPrepareWords() { string rawText = "lorem ipsum dolor sit amet consetetur"; string[] expectedArray = new string[] { "lorem", "ipsum", "dolor", "sit", "amet", "consetetur" }; int wordsInRawText = 6; LipsumGenerator lipsum = new LipsumGenerator(rawText, false); string[] wordsPrepared = lipsum.PreparedWords; Assert.AreEqual(wordsInRawText, wordsPrepared.Length); CollectionAssert.AreElementsEqual(wordsPrepared, expectedArray); }
public void Deserialize_When2CtorsWithSameArgCount_EvaluateCorrectOne() { Serializer s = new Serializer(); ObjectExpression expr = new ObjectExpression(); expr.ResultType = typeof(CtorMock); NumericExpression IDExpr = new NumericExpression("10"); ValueExpression StrExpr = new ValueExpression("name"); expr.ConstructorArguments.Add(IDExpr); expr.ConstructorArguments.Add(StrExpr); CtorArgTypeResolver resolver = new CtorArgTypeResolver(expr, s.Settings); Type[] argTypes = resolver.ResolveTypes(); CollectionAssert.AreElementsEqual(new Type[] { typeof(int), typeof(string) }, argTypes); }
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 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(); }