Ejemplo n.º 1
0
        [InlineData(typeof(List <object>))]   //Array2
        public void Array_ReadBssomValue_FunctionIsCorrectly(Type type)
        {
            var val = RandomHelper.RandomValue(type);
            var buf = BssomSerializer.Serialize(val);

            var bsfm  = new BssomFieldMarshaller(buf);
            int count = ((ICollection)val).Count;

            for (int i = 0; i < count; i++)
            {
                bsfm.ReadValue <BssomValue>(bsfm.IndexOf($"${i}")).Is(BssomValue.Create(((IList)val)[i]));
            }
        }
Ejemplo n.º 2
0
        [InlineData("12345678901234567")]//17size-> Blank0 critical value
        public void Array2_WriteFieldWithBlankLength_MultipleWritesOfInconsistentLength_IsCorrectly(object fieldValue)
        {
            var val = new List <string>();//18size

            val.Add("123456789012345678");
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var cOffset = bsfm.IndexOf("$0");

            bsfm.TryWrite(cOffset, fieldValue).IsTrue();
            bsfm.ReadValue <BssomValue>(cOffset).Is(BssomValue.Create(fieldValue));
        }
Ejemplo n.º 3
0
        [InlineData("12345678901234567")]//17size-> Blank0 critical value
        public void Map_WriteFieldWithBlankLength_MultipleWritesOfInconsistentLength_IsCorrectly(object fieldValue)
        {
            var val = new _class2()
            {
                C = "123456789012345678"
            };                                                   //18size
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var cOffset = bsfm.IndexOf("[" + nameof(_class2.C) + "]");

            bsfm.TryWrite(cOffset, fieldValue).IsTrue();
            bsfm.ReadValue <BssomValue>(cOffset).Is(BssomValue.Create(fieldValue));
        }
Ejemplo n.º 4
0
        public void Map_WriteFieldWithBlankLength_IsExtraLengthWriting_FixTypeSize_IsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class2>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);


            int B1 = RandomHelper.RandomValue <int>();

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class2.B) + "]"), B1).IsTrue();

            var val3 = BssomSerializer.Deserialize <BssomMap>(buf);

            val3["B"].Is(BssomValue.Create(B1));
            bsfm.ReadValue <int>(bsfm.IndexOf("[" + nameof(_class2.B) + "]")).Is(B1);
        }
Ejemplo n.º 5
0
        public void Map1_ReadBssomValue_FunctionIsCorrectly()
        {
            var val = new Dictionary <string, object>()
            {
                { "A", (int)3 },
                { "B", (DateTime)DateTime.MaxValue },
                { "C", (string)"1234567" }
            };

            var option = BssomSerializerOptions.Default.WithIDictionaryIsSerializeMap1Type(true);
            var buf    = BssomSerializer.Serialize(val, option);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[A]")).Is(BssomValue.Create(val["A"]));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[B]")).Is(BssomValue.Create(val["B"]));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[C]")).Is(BssomValue.Create(val["C"]));
        }
Ejemplo n.º 6
0
        public static BssomValueType ConvertObjectAndVerifyBssomMapType <TKey, TValue>(object value, BssomSerializerOptions option = null)
        {
            if (option == null)
            {
                option = BssomSerializerOptions.Default;
            }

            var buf = BssomSerializer.Serialize <object>(value, option);

            BssomSerializer.Size <object>(value, option).Is(buf.Length);

            var dicObj = ((IEnumerable <KeyValuePair <object, object> >)BssomSerializer.Deserialize <object>(buf, option.WithIsPriorityToDeserializeObjectAsBssomValue(false))).Select(e => new KeyValuePair <TKey, TValue>((TKey)e.Key, (TValue)e.Value));

            dicObj.IsDict((IEnumerable <KeyValuePair <TKey, TValue> >)value);
            var dicObj2 = ((IEnumerable <KeyValuePair <object, object> >)BssomSerializer.Deserialize <object>(buf, option.WithIsPriorityToDeserializeObjectAsBssomValue(true)));

            dicObj2.IsDict((IDictionary <object, object>)BssomValue.Create(value));
            return(new BssomFieldMarshaller(buf).ReadValueType(BssomFieldOffsetInfo.Zero));
        }
Ejemplo n.º 7
0
        public static BssomValueType ConvertArrayObjectAndVerifyBssomValueType <T>(T value, BssomSerializerOptions option = null)
        {
            var buf = BssomSerializer.Serialize <object>(value, option);

            BssomSerializer.Size <object>(value, option).Is(buf.Length);
            var ary = (BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(false)));

            ary.Is(value);
            var ary2 = (BssomArray)(BssomSerializer.Deserialize <object>(buf, (option ?? BssomSerializerOptions.Default).WithIsPriorityToDeserializeObjectAsBssomValue(true)));

            var _ary2 = (BssomArray)BssomValue.Create(value);

            ary2.Count.Is(_ary2.Count);
            for (int i = 0; i < ary2.Count; i++)
            {
                ary2[i].Is(_ary2[i]);
            }
            //ary2.Is((IList<object>)BssomValue.Create(value));
            return(new BssomFieldMarshaller(buf).ReadValueType(BssomFieldOffsetInfo.Zero));
        }
Ejemplo n.º 8
0
        public void Map_WriteFieldWithBlankLength_IsExtraLengthWriting_VariableTypeSize_IsCorrectly()
        {
            var val = new _class2()
            {
                C = "123456789"
            };
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);


            string C1 = "123";

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class2.C) + "]"), C1).IsTrue();

            var val3 = BssomSerializer.Deserialize <BssomMap>(buf);

            val3["C"].Is(BssomValue.Create(C1));
            bsfm.ReadValue <string>(bsfm.IndexOf("[" + nameof(_class2.C) + "]")).Is(C1);
        }
Ejemplo n.º 9
0
 BssomDecimal IArray1ElementWriter <BssomDecimal> .ReadElement(ref BssomReader reader, BssomSerializerOptions option, BssomFieldOffsetInfo offsetInfo)
 {
     return((BssomDecimal)BssomValue.Create(ReadElement(ref reader, option, offsetInfo)));
 }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        public void Map2_ReadBssomValue_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.A) + "]")).Is(BssomValue.Create(val.A));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]")).Is(BssomValue.Create(val.B123123123));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]")).Is(BssomValue.Create(val.B1231231VV));
            bsfm.ReadValue <BssomValue>(bsfm.IndexOf("[" + nameof(_class1.C) + "]")).Is(BssomValue.Create(val.C));
        }