예제 #1
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();
        }
예제 #2
0
        public void Map2_ReadStrongType_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <DateTime>(bsfm.IndexOf("[" + nameof(_class1.A) + "]")).Is(val.A);
            bsfm.ReadValue <Guid>(bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]")).Is(val.B123123123);
            bsfm.ReadValue <int>(bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]")).Is(val.B1231231VV);
            bsfm.ReadValue <int>(bsfm.IndexOf("[" + nameof(_class1.C) + "]")).Is(val.C);
        }
예제 #3
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));
        }
예제 #4
0
        [InlineData(typeof(DateTime), typeof(List <DateTime>))] //Array1
        public void Array1_WriteField_TypeAndTypeLengthIsSame_IsCorrectly(Type eleType, Type arrayType)
        {
            var val = RandomHelper.RandomValue(arrayType);
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var list = (IList)val;

            for (int i = 0; i < list.Count; i++)
            {
                var ran = RandomHelper.RandomValue(eleType);
                bsfm.TryWrite(bsfm.IndexOf($"${i}"), ran).IsTrue();
                bsfm.ReadValue <object>(bsfm.IndexOf($"${i}")).Is(ran);
            }
        }
예제 #5
0
        [InlineData(typeof(List <object>))]   //Array2
        public void Array_IndexOf_FunctionIsCorrectly(Type t)
        {
            var val = RandomHelper.RandomValue(t);
            var buf = BssomSerializer.Serialize(val);

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

            for (int i = 0; i < count; i++)
            {
                bsfm.IndexOf($"${i}").IsExists.IsTrue();
            }

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf($"${count}"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.ArrayTypeIndexOutOfBounds);
        }
예제 #6
0
 static BssomSerialize_MyImage()
 {
     Input                = RandomHelper.RandomValueWithOutStringEmpty <MyImage>();
     Input.Binary         = new byte[4096 * 200];
     OutPut               = Serializer.BssomSerializer.Serialize(Input);
     UpdateDateOffsetInfo = BssomFieldMarshaller.IndexOf(OutPut, 0, OutPut.Length, "[UpdateTime]");
 }
예제 #7
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);
        }
예제 #8
0
        [InlineData(BssomValueType.Map, BssomType.Map2, false, typeof(List <_class1>), false)]                    //Array2
        public void Array_ReadValueTypeAndTypeCode_IsCorrectly(BssomValueType valueType, byte typeCode, bool isNativeType, Type arrayType, bool isUseStantDateTime)
        {
            var val = RandomHelper.RandomValue(arrayType);
            var buf = BssomSerializer.Serialize(val, BssomSerializerOptions.Default.WithIsUseStandardDateTime(isUseStantDateTime));

            var bsfm = new BssomFieldMarshaller(buf);

            var list = (IList)val;

            for (int i = 0; i < list.Count; i++)
            {
                bsfm.ReadValueTypeCode(bsfm.IndexOf($"${i}"), out bool isNative).Is(typeCode);
                isNative.Is(isNativeType);

                bsfm.ReadValueType(bsfm.IndexOf($"${i}")).Is(valueType);
            }
        }
예제 #9
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);
        }
예제 #10
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"]));
        }
예제 #11
0
        [InlineData(typeof(int), typeof(List <DateTime>))] //Array1
        public void Array1_WriteField_ElementTypeMustCompleteConsistency_IsRequiredToWrite(Type eleType, Type arrayType)
        {
            var val = RandomHelper.RandomValue(arrayType);
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);
            var ran  = RandomHelper.RandomValue(eleType);

            VerifyHelper.Throws <InvalidCastException>(() => bsfm.TryWrite(bsfm.IndexOf("$0"), ran));
        }
예제 #12
0
        public void Map_WriteFieldWithBlankLength_InsufficientLengthWritten_IsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class2>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            long A1 = RandomHelper.RandomValue <long>();

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class2.A) + "]"), A1).IsFalse();
        }
예제 #13
0
        public void ArrayType_IndexOf_ArrayTypeIndexOutOfBoundsException()
        {
            var buf = BssomSerializer.Serialize(new List <object>()
            {
                1
            });
            var bsfm = new BssomFieldMarshaller(buf);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("$1"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.ArrayTypeIndexOutOfBounds);
        }
예제 #14
0
        public void ArrayType_IndexOf_InputFormatAndBufTypeFormatNotMatch_IsException()
        {
            var buf = BssomSerializer.Serialize(new List <object>()
            {
                1
            });
            var bsfm = new BssomFieldMarshaller(buf);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("$0$3"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.UnsupportedOperation);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("[r]"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.InputDataUnmatch);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("[r]$1"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.InputDataUnmatch);

            VerifyHelper.Throws <BssomSerializationArgumentException>(() => bsfm.IndexOf("rrr"),
                                                                      ex => ex.ErrorCode == BssomSerializationArgumentException.SerializationErrorCode.InvalidFormatOfMembers);
        }
예제 #15
0
        public void Map1_IndexOf_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.IndexOf("[A]").IsExists.IsTrue();
            bsfm.IndexOf("[B]").IsExists.IsTrue();
            bsfm.IndexOf("[C]").IsExists.IsTrue();

            bsfm.IndexOf("[H]").IsExists.IsFalse();
            bsfm.IndexOf("[H123123123]").IsExists.IsFalse();
        }
예제 #16
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);
        }
예제 #17
0
        public void Map_WriteField_TypeAndTypeLengthIsSame_IsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var val2 = RandomHelper.RandomValue <_class1>();

            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.A) + "]"), val2.A).IsTrue();
            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]"), val2.B123123123).IsTrue();
            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]"), val2.B1231231VV).IsTrue();
            bsfm.TryWrite(bsfm.IndexOf("[" + nameof(_class1.C) + "]"), val2.C).IsTrue();

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

            val3.A.Is(val2.A);
            val3.B123123123.Is(val2.B123123123);
            val3.B1231231VV.Is(val2.B1231231VV);
            val3.C.Is(val2.C);
        }
예제 #18
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);
        }
예제 #19
0
        public void Array1_ReadStrongType_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <List <byte> >();
            var buf = BssomSerializer.Serialize(val);

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

            for (int i = 0; i < count; i++)
            {
                bsfm.ReadValue <byte>(bsfm.IndexOf($"${i}")).Is(val[i]);
            }
        }
예제 #20
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]));
            }
        }
예제 #21
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));
        }
예제 #22
0
        public void MixtureType_FirstMapType_IndexOf_InputFormatAndBufTypeFormatNotMatch_IsException()
        {
            var buf = BssomSerializer.Serialize(new Dictionary <object, List <object> >()
            {
                { "r", new List <object>()
                  {
                      3
                  } }
            });
            var bsfm = new BssomFieldMarshaller(buf);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("[r]$1[h]"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.ArrayTypeIndexOutOfBounds);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("$1[r]"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.InputDataUnmatch);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("$1$3"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.InputDataUnmatch);

            VerifyHelper.Throws <BssomSerializationArgumentException>(() => bsfm.IndexOf("rrr"),
                                                                      ex => ex.ErrorCode == BssomSerializationArgumentException.SerializationErrorCode.InvalidFormatOfMembers);
        }
예제 #23
0
        public void MixtureType_FirstArrayType_IndexOf_InputFormatAndBufTypeFormatNotMatch_IsException()
        {
            var buf = BssomSerializer.Serialize(new List <Dictionary <object, string> >()
            {
                new Dictionary <object, string>()
                {
                    { "r", "f" }
                }
            });
            var bsfm = new BssomFieldMarshaller(buf);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("$0[r][h]"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.UnsupportedOperation);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("[r]$1"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.InputDataUnmatch);

            VerifyHelper.Throws <BssomSerializationOperationException>(() => bsfm.IndexOf("[r][h]"),
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.InputDataUnmatch);

            VerifyHelper.Throws <BssomSerializationArgumentException>(() => bsfm.IndexOf("rrr"),
                                                                      ex => ex.ErrorCode == BssomSerializationArgumentException.SerializationErrorCode.InvalidFormatOfMembers);
        }
예제 #24
0
        public void Test()
        {
            var val2 = RandomHelper.RandomValue <_Attribute_Class_1>();

            VerifyHelper.VerifyEntityWithMap2(val2);

            var buf    = BssomSerializer.Serialize(val2);
            var helper = new BssomFieldMarshaller(buf);

            helper.IndexOf("[AAA]").IsExists.IsTrue();
            helper.IndexOf("[A1]").IsExists.IsFalse();

            //-------

            var val3 = RandomHelper.RandomValue <_Attribute_Class_2>();

            VerifyHelper.VerifyEntityWithMap2(val3);

            var buf2    = BssomSerializer.Serialize(val3);
            var helper2 = new BssomFieldMarshaller(buf2);

            helper2.IndexOf("[AAA]").IsExists.IsFalse();
            helper2.IndexOf("[A1]").IsExists.IsTrue();
        }
예제 #25
0
        public void IndexOf_MustBe_Is_ArrayAndMapType_CanCall(object value)
        {
            VerifyHelper.Throws <BssomSerializationOperationException>(() =>
            {
                var buf = BssomSerializer.Serialize(value);
                BssomFieldMarshaller.IndexOf(buf, 0, buf.Length, "[A]");
            },
                                                                       ex => ex.ErrorCode == BssomSerializationOperationException.SerializationErrorCode.UnsupportedOperation);

            var buf2 = BssomSerializer.Serialize(RandomHelper.RandomValueWithOutStringEmpty <Dictionary <string, object> >());

            BssomFieldMarshaller.IndexOf(buf2, 0, buf2.Length, "[A]").IsType <BssomFieldOffsetInfo>();
            buf2 = BssomSerializer.Serialize(RandomHelper.RandomValueWithOutStringEmpty <List <object> >());
            BssomFieldMarshaller.IndexOf(buf2, 0, buf2.Length, "$1").IsType <BssomFieldOffsetInfo>();
        }
예제 #26
0
        public void Array2_WriteFieldWithBlankLength_EmptyInt32Code_Test()
        {
            var val = new List <byte[]> {
                new byte[short.MaxValue + 1]
            };
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            int num = 3;
            var of  = bsfm.IndexOf("$0");

            bsfm.TryWrite(of, num).IsTrue();
            bsfm.ReadValue <int>(of).Is(num);
        }
예제 #27
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));
        }
예제 #28
0
        [InlineData(typeof(byte), typeof(List <List <object> >))] //Array2
        public void Array2_WriteFieldWithBlankLength_IsExtraLengthWriting_IsCorrectly(Type eleType, Type arrayType)
        {
            var val = RandomHelper.RandomValueWithOutStringEmpty(arrayType);
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            var list = (IList)val;

            for (int i = 0; i < list.Count; i++)
            {
                var ran   = RandomHelper.RandomValue(eleType);
                var index = bsfm.IndexOf($"${i}");
                bsfm.TryWrite(index, ran).IsTrue();
                bsfm.ReadValue <object>(index).Is(ran);
            }
        }
예제 #29
0
        public void Map2_IndexOf_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_class1>();
            var buf = BssomSerializer.Serialize(val);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.IndexOf("[" + nameof(_class1.A) + "]").IsExists.IsTrue();
            bsfm.IndexOf("[" + nameof(_class1.B123123123) + "]").IsExists.IsTrue();
            bsfm.IndexOf("[" + nameof(_class1.B1231231VV) + "]").IsExists.IsTrue();
            bsfm.IndexOf("[" + nameof(_class1.C) + "]").IsExists.IsTrue();

            bsfm.IndexOf("[H]").IsExists.IsFalse();
            bsfm.IndexOf("[H123123123]").IsExists.IsFalse();
        }
예제 #30
0
        public void Array3_IndexOf_FunctionIsCorrectly()
        {
            var val = RandomHelper.RandomValue <_spacingValuesClass>();

            val.D = new Dictionary <string, string>()
            {
                { "_1", "1" }, { "_2", "2" }
            };
            var buf = BssomSerializer.Serialize(val, BssomSerializerOptions.IntKeyCompositedResolverOption);

            var bsfm = new BssomFieldMarshaller(buf);

            bsfm.ReadValue <Int32>(bsfm.IndexOf("$0")).Is(val.A);
            bsfm.ReadValue <object>(bsfm.IndexOf("$1")).Is(null);
            bsfm.ReadValue <object>(bsfm.IndexOf("$2")).Is(null);
            bsfm.ReadValue <Int32>(bsfm.IndexOf("$3")).Is(val.B);
            bsfm.ReadValue <object>(bsfm.IndexOf("$4")).Is(null);
            bsfm.ReadValue <Int32>(bsfm.IndexOf("$5")).Is(val.C);
            bsfm.ReadValue <string>(bsfm.IndexOf("$6[_2]")).Is("2");
        }