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 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); }
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)); }
[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); } }
[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); }
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]"); }
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); }
[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); } }
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); }
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"])); }
[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)); }
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(); }
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); }
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); }
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(); }
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); }
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); }
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); }
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]); } }
[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])); } }
[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)); }
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); }
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); }
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(); }
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>(); }
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); }
[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)); }
[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); } }
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(); }
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"); }