示例#1
0
        public void GenericIReadOnlyCollection_DeserializeTypeIsGenericList()
        {
            IReadOnlyCollection <int> val = RandomHelper.RandomValue <List <int> >();
            var buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <IReadOnlyCollection <int> >(buf).IsType <List <int> >();
        }
示例#2
0
        public void IEnumerableType_DeserializeTypeIsListObject()
        {
            IEnumerable val = RandomHelper.RandomValue <List <int> >();
            var         buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <IEnumerable>(buf).IsType <List <object> >();
        }
示例#3
0
        public void GenericISetType_DeserializeTypeIsHashSet()
        {
            ISet <int> val = RandomHelper.RandomValue <HashSet <int> >();
            var        buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <ISet <int> >(buf).IsType <HashSet <int> >();
        }
示例#4
0
        public void ObjectType_FormatterValueType_IsNull()
        {
            var buf = BssomSerializer.Serialize <object>(null);

            BssomSerializer.Deserialize <object>(buf, BssomSerializerOptions.Default.WithIsPriorityToDeserializeObjectAsBssomValue(false)).IsNull();
            BssomSerializer.Deserialize <object>(buf, BssomSerializerOptions.Default.WithIsPriorityToDeserializeObjectAsBssomValue(true)).Is(BssomNull.Value);
        }
示例#5
0
        public void ICollectionType_DeserializeTypeIsListObject()
        {
            ICollection val = RandomHelper.RandomValue <List <int> >();
            var         buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <ICollection>(buf).IsType <List <object> >();
        }
示例#6
0
        public static void VerifyNullableIsNull <T>(BssomSerializerOptions option = null) where T : struct
        {
            var buf = BssomSerializer.Serialize <Nullable <T> >(null, option);

            BssomSerializer.Size <Nullable <T> >(null, option).Is(1).Is(buf.Length);
            BssomSerializer.Deserialize <Nullable <T> >(buf, option).IsNull();
        }
        public void IReadOnlyDictionaryType_DeserializeTypeIsReadOnlyDictionaryDictionary()
        {
            IReadOnlyDictionary <int, int> val = RandomHelper.RandomValue <Dictionary <int, int> >();
            var buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <IReadOnlyDictionary <int, int> >(buf).IsType <ReadOnlyDictionary <int, int> >();
        }
示例#8
0
        public static void VerifyTypeNull <T>(BssomSerializerOptions option = null) where T : class
        {
            var buf = BssomSerializer.Serialize <T>(null, option);

            BssomSerializer.Size <T>(null, option).Is(1).Is(buf.Length);
            BssomSerializer.Deserialize <T>(buf, option).IsNull();
        }
示例#9
0
        public void PipeStreamSerializeAndDeserialize_MultipleValues_ConsecutiveReadsAndWrites_IsCorrect()
        {
            var obj1 = new List <int>()
            {
                1
            };
            var obj2 = new Dictionary <string, object>()
            {
                { "A", DateTime.MinValue }
            };
            var obj3 = double.MaxValue;

            FakePipeStream stream = new FakePipeStream();

            BssomSerializer.Serialize(stream, obj1);
            BssomSerializer.Serialize(stream, obj2);
            BssomSerializer.Serialize(stream, obj3);

            stream.ResetCursor();
            var oobj1 = BssomSerializer.Deserialize <List <int> >(stream);
            var oobj2 = BssomSerializer.Deserialize <Dictionary <string, object> >(stream);
            var oobj3 = BssomSerializer.Deserialize <double>(stream);

            oobj1.Count.Is(obj1.Count);
            oobj1[0].Is(oobj1[0]);
            oobj2.Count.Is(obj2.Count);
            oobj2["A"].Is(oobj2["A"]);
            oobj3.Is(obj3);
        }
        public void IGenericDictionaryType_DeserializeTypeIsGenericDictionary()
        {
            IDictionary <int, int> val = RandomHelper.RandomValue <Dictionary <int, int> >();
            var buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <IDictionary <int, int> >(buf).IsType <Dictionary <int, int> >();
        }
示例#11
0
        public static void VerifySimpleType <T>(T value, int size, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(size).Is(buf.Length);
            BssomSerializer.Deserialize <T>(buf, option).Is(value);
        }
示例#12
0
        public void MixtureType_ReadStrongType_FunctionIsCorrectly()
        {
            var val = new List <Dictionary <string, int[]> >()
            {
                new Dictionary <string, int[]>()
                {
                    { "A", new int[] { 1, 2, 3 } },
                    { "B", new int[] { 4, 5, 6 } }
                },
                new Dictionary <string, int[]>()
                {
                    { "A2", new int[] { 1, 2, 3 } },
                    { "B2", new int[] { 4, 5, 6 } }
                }
            };
            var buf  = BssomSerializer.Serialize(val);
            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <int>(bsfm.IndexOf("$0[A]$0")).Is(1);
            bsfm.ReadValue <int>(bsfm.IndexOf("$0[A]$1")).Is(2);
            bsfm.ReadValue <int>(bsfm.IndexOf("$0[B]$2")).Is(6);

            bsfm.ReadValue <int>(bsfm.IndexOf("$1[A2]$0")).Is(1);
            bsfm.ReadValue <int>(bsfm.IndexOf("$1[A2]$1")).Is(2);
            bsfm.ReadValue <int>(bsfm.IndexOf("$1[B2]$2")).Is(6);
        }
示例#13
0
        public static void VerifySpecific <T>(Lazy <T> value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <Lazy <T> >(buf, option).Value.Is(value.Value);
        }
示例#14
0
        public void GenericIEnumerableType_DeserializeTypeIsGenericList()
        {
            IEnumerable <int> val = RandomHelper.RandomValue <List <int> >();
            var buf = BssomSerializer.Serialize(val);

            BssomSerializer.Deserialize <IEnumerable <int> >(buf).IsType <List <int> >();
        }
示例#15
0
        public void DeserializeTestWithT_IBssomBuffer_Type()
        {
            int val  = int.MaxValue;
            var buf  = BssomSerializer.Serialize(val);
            var sbuf = new SimpleBuffer(buf);

            ((int)BssomSerializer.Deserialize(sbuf, typeof(int))).Is(int.MaxValue);
        }
示例#16
0
        public static void VerifyIDictWithMap2Type(IDictionary value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <IDictionary>(buf, option).GetGetEnumerator().IsDict(value.GetGetEnumerator());
            buf.IsMap2();
        }
示例#17
0
        public static byte[] VerifyIDictAndReturnSerializeBytes(IDictionary value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <IDictionary>(buf, option).GetGetEnumerator().IsDict(value.GetGetEnumerator());
            return(buf);
        }
示例#18
0
        public void NullType_IndexOf_NullExceptionToAnyInput()
        {
            var buf  = BssomSerializer.Serialize <Dictionary <string, string> >(null);
            var bsfm = new BssomFieldMarshaller(buf);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("[r]"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.OperationObjectIsNull);
        }
示例#19
0
        public void ExpentdTypeTest()
        {
            var val  = new _sub().Init();
            var buf  = BssomSerializer.Serialize(val, BssomSerializerOptions.DefaultAllowPrivate);
            var val2 = BssomSerializer.Deserialize <_sub>(buf, BssomSerializerOptions.DefaultAllowPrivate);

            val.Equals(val2).IsTrue();
        }
示例#20
0
        public void CompositedResolverAllowPrivateTest()
        {
            var val  = new _PrivateMembersClass().Init();
            var buf  = BssomSerializer.Serialize(val, BssomSerializerOptions.DefaultAllowPrivate);
            var val2 = BssomSerializer.Deserialize <_PrivateMembersClass>(buf, BssomSerializerOptions.DefaultAllowPrivate);

            val.Equals(val2).IsTrue();
        }
示例#21
0
        public void DeserializeTestWithT_IBssomBuffer()
        {
            int val  = int.MaxValue;
            var buf  = BssomSerializer.Serialize(val);
            var sbuf = new SimpleBuffer(buf);

            BssomSerializer.Deserialize <int>(sbuf).Is(int.MaxValue);
        }
示例#22
0
        public static byte[] VerifyIDictAndReturnSerializeBytes <T, TKey, TValue>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            ((IEnumerable <KeyValuePair <TKey, TValue> >)BssomSerializer.Deserialize <T>(buf, option)).IsDict((IEnumerable <KeyValuePair <TKey, TValue> >)value);
            return(buf);
        }
示例#23
0
        private static byte[] SimplicityVerify <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            BssomSerializer.Deserialize <T>(buf, option).Is(value);
            return(buf);
        }
示例#24
0
        public void Test()
        {
            var val2 = RandomHelper.RandomValue <_Attribute_Class_1>();
            var buf  = BssomSerializer.Serialize(val2);
            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.IndexOf("[Name]").IsExists.IsFalse();
            bsfm.IndexOf("[Sex]").IsExists.IsTrue();
        }
        public void Map1StringKey_Cannot_Empty()
        {
            var val = new Dictionary <string, int>()
            {
                { string.Empty, 1 }
            };

            VerifyHelper.Throws <BssomSerializationArgumentException>(() => BssomSerializer.Serialize(val, BssomSerializerOptions.Default.WithIDictionaryIsSerializeMap1Type(false)));
        }
示例#26
0
        public void Map1Deserialize_MultipleFieldClassTest()
        {
            var val  = RandomHelper.RandomValueWithOutStringEmpty <MultipleFieldClass>();
            var dict = val.GetPublicMembersWithDynamicObject().ToIDict();
            var buf  = BssomSerializer.Serialize(dict);
            var val2 = BssomSerializer.Deserialize <MultipleFieldClass>(buf);

            VerifyHelper.VerifyWithJson(val, val2);
        }
        public void ReadOneObjectBytesFromStreamIsCorrectly(Type type)
        {
            var obj    = RandomHelper.RandomValueWithOutStringEmpty(type);
            var buf    = BssomSerializer.Serialize(obj);
            var stream = new MemoryStream(buf);

            var      sda      = new StreamDeserializeAux(stream);
            var      bssomBuf = sda.GetBssomBuffer();
            ref byte refb     = ref bssomBuf.ReadRef(buf.Length);
示例#28
0
        public static void VerifyMap(BssomMap value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var map = (BssomMap)BssomSerializer.Deserialize <object>(buf, option);

            value.IsMap(map);
        }
示例#29
0
        public static BssomValueType ConvertObjectAndVerifyBssomValueType <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize <object>(value, option);

            BssomSerializer.Size <object>(value, option).Is(buf.Length);
            ((T)BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(false))).Is(value);
            (BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(true))).Is(BssomValue.Create(value));
            return(new BssomFieldMarshaller(buf).ReadValueType(BssomFieldOffsetInfo.Zero));
        }
示例#30
0
        public static void VerifyArray(BssomArray value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize(value, option);

            BssomSerializer.Size(value, option).Is(buf.Length);
            var ary = (BssomArray)BssomSerializer.Deserialize <object>(buf, option);

            ary.IsArray(value);
        }