public void GenericIReadOnlyCollection_DeserializeTypeIsGenericList() { IReadOnlyCollection <int> val = RandomHelper.RandomValue <List <int> >(); var buf = BssomSerializer.Serialize(val); BssomSerializer.Deserialize <IReadOnlyCollection <int> >(buf).IsType <List <int> >(); }
public void IEnumerableType_DeserializeTypeIsListObject() { IEnumerable val = RandomHelper.RandomValue <List <int> >(); var buf = BssomSerializer.Serialize(val); BssomSerializer.Deserialize <IEnumerable>(buf).IsType <List <object> >(); }
public void GenericISetType_DeserializeTypeIsHashSet() { ISet <int> val = RandomHelper.RandomValue <HashSet <int> >(); var buf = BssomSerializer.Serialize(val); BssomSerializer.Deserialize <ISet <int> >(buf).IsType <HashSet <int> >(); }
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); }
public void ICollectionType_DeserializeTypeIsListObject() { ICollection val = RandomHelper.RandomValue <List <int> >(); var buf = BssomSerializer.Serialize(val); BssomSerializer.Deserialize <ICollection>(buf).IsType <List <object> >(); }
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> >(); }
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(); }
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> >(); }
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); }
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 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); }
public void GenericIEnumerableType_DeserializeTypeIsGenericList() { IEnumerable <int> val = RandomHelper.RandomValue <List <int> >(); var buf = BssomSerializer.Serialize(val); BssomSerializer.Deserialize <IEnumerable <int> >(buf).IsType <List <int> >(); }
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); }
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(); }
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); }
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); }
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(); }
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(); }
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); }
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); }
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); }
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))); }
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);
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); }
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)); }
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); }