Exemplo n.º 1
0
        public void TestIssue124_AotForComplexValueType()
        {
            MessagePackSerializer.PrepareType <TestValueType>();
            var context =
                PreGeneratedSerializerActivator.CreateContext(
                    SerializationMethod.Array,
                    PackerCompatibilityOptions.None
                    );

            context.Serializers.RegisterOverride(new TestValueTypeWrapperSerializer(context));
            var serializer = MessagePackSerializer.Get <TestValueTypeWrapper>(context);
            var target     = new TestValueTypeWrapper {
                Value = new TestValueType {
                    StringField = String.Empty
                }
            };

            using (var buffer = new MemoryStream())
            {
                serializer.Pack(buffer, target);
                buffer.Position = 0;
                var result = serializer.Unpack(buffer);
                Assert.That(result, Is.Not.Null);
                Assert.That(result.Value.StringField, Is.EqualTo(String.Empty));
                Assert.That(result.Value.Int32ArrayField, Is.Null);
                Assert.That(result.Value.DictionaryField, Is.Null);
            }
        }
Exemplo n.º 2
0
 public static void SetupFixture()
 {
     MessagePackSerializer.PrepareType <Timestamp>();
     MessagePackSerializer.PrepareCollectionType <byte>();
     MessagePackSerializer.PrepareCollectionType <char>();
     MessagePackSerializer.PrepareCollectionType <int>();
     MessagePackSerializer.PrepareCollectionType <float>();
     MessagePackSerializer.PrepareCollectionType <double>();
     MessagePackSerializer.PrepareCollectionType <short>();
     MessagePackSerializer.PrepareCollectionType <uint>();
     MessagePackSerializer.PrepareCollectionType <ulong>();
     MessagePackSerializer.PrepareCollectionType <sbyte>();
     MessagePackSerializer.PrepareDictionaryType <string, int>();
     new ArraySegmentEqualityComparer <byte>().Equals(default(ArraySegment <byte>), default(ArraySegment <byte>));
     new ArraySegmentEqualityComparer <char>().Equals(default(ArraySegment <char>), default(ArraySegment <char>));
     new ArraySegmentEqualityComparer <int>().Equals(default(ArraySegment <int>), default(ArraySegment <int>));
 }
Exemplo n.º 3
0
        public void TestIssue99_HoGyuLee_AotForEnumKeyDictionary()
        {
            MessagePackSerializer.PrepareType <FileMode>();
            using (var buffer = new MemoryStream(new byte[] { 0x81, 0x01, 0x00 }))
            {
                var serializer =
                    MessagePackSerializer.Get <Dictionary <FileMode, int> >(
                        PreGeneratedSerializerActivator.CreateContext(
                            SerializationMethod.Array,
                            PackerCompatibilityOptions.None
                            )
                        );
                var result = serializer.Unpack(buffer);
                Assert.That(result.Count, Is.EqualTo(1));
                var singleResult = default(KeyValuePair <FileMode, int>);
                foreach (var kv in result)
                {
                    singleResult = kv;
                }

                Assert.That(singleResult.Key, Is.EqualTo(( FileMode )1));
                Assert.That(singleResult.Value, Is.EqualTo(0));
            }
        }