protected void TestFieldWithValues <TEnumType>(MessageSerializedClassInfo classInfo, string propertyName, TEnumType[] valuesToUse) where TEnumType : struct, IConvertible { foreach (TEnumType value in valuesToUse) { TestField(classInfo, propertyName, value); } }
protected void TestField(MessageSerializedClassInfo classInfo, string propertyName, int valueToUse, byte[] expectedArray) { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerThreeByteNumeric typeSerializer = new TypeSerializerThreeByteNumeric(propertyInfo); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
protected void TestFieldWithValues(MessageSerializedClassInfo classInfo, string propertyName, string[] valuesToUse) { foreach (string value in valuesToUse) { TestField(classInfo, propertyName, value); } }
protected void TestFieldWithValues <TNumericType>(MessageSerializedClassInfo classInfo, string propertyName, TNumericType[] valuesToUse) where TNumericType : struct { foreach (TNumericType value in valuesToUse) { TestField(classInfo, propertyName, value); } }
protected void TestField(MessageSerializedClassInfo classInfo, string propertyName, TestSubClass valueToUse, byte[] expectedArray) { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerSerializableClass <TestSubClass> typeSerializer = new TypeSerializerSerializableClass <TestSubClass>(propertyInfo); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
protected void TestFieldWithValues(MessageSerializedClassInfo classInfo, string propertyName, byte[][] valuesToUse, int[] expectedOutputLengths) { for (int index = 0; index < valuesToUse.Length; ++index) { TestField(classInfo, propertyName, valuesToUse[index], expectedOutputLengths[index]); } }
protected void TestFieldWithValues <TNumericType>(MessageSerializedClassInfo classInfo, string propertyName, TNumericType[] valuesToUse, byte[][] expectedByteArrays) where TNumericType : struct, IComparable <TNumericType>, IConvertible { Assert.That(valuesToUse.Length, Is.EqualTo(expectedByteArrays.Length), "TestValuesLength"); for (int index = 0; index < valuesToUse.Length; ++index) { TestField(classInfo, propertyName, valuesToUse[index], expectedByteArrays[index]); } }
protected void TestField <TNumericType>(MessageSerializedClassInfo classInfo, string propertyName, TNumericType valueToUse, byte[] expectedArray) where TNumericType : struct, IComparable <TNumericType>, IConvertible { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerBcd <TNumericType> typeSerializer = new TypeSerializerBcd <TNumericType>(propertyInfo); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
protected void TestField(MessageSerializedClassInfo classInfo, string propertyName, int valueToUse) { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerJunk typeSerializer = new TypeSerializerJunk(propertyInfo); byte[] expectedArray = new byte[] { 0x33, 0x44, 0x55 }; TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
public TestSampleTypeSerializerThreeByteNumeric() { var serializationDefaults = new SerializationDefaults(); // We need to put our TypeSelector first, otherwise a property that matches will get matched by TypeSelectorNumeric first serializationDefaults.TypeSelectors.Insert(0, new TypeSelectorThreeByteNumeric()); _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass), serializationDefaults); }
protected void TestListField <TNumericType>(MessageSerializedClassInfo classInfo, string propertyName, List <TNumericType> valueToUse) where TNumericType : struct { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerNumeric <TNumericType> typeSerializer = new TypeSerializerNumeric <TNumericType>(propertyInfo); byte[] expectedArray = GetExpectedByteArray(valueToUse); TestListField <TypeSerializerNumeric <TNumericType>, List <TNumericType>, TNumericType>(typeSerializer, propertyInfo, valueToUse, expectedArray); }
protected void TestField <TEnumType>(MessageSerializedClassInfo classInfo, string propertyName, TEnumType valueToUse) where TEnumType : struct, IConvertible { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerEnum <TEnumType> typeSerializer = new TypeSerializerEnum <TEnumType>(propertyInfo); byte[] expectedArray = GetExpectedByteArray(valueToUse); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
protected void TestField(MessageSerializedClassInfo classInfo, string propertyName, byte[] valueToUse, int expectedOutputLength) { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerByteArray typeSerializer = new TypeSerializerByteArray(propertyInfo); //int outputLength = CalculateOutputLength(propertyInfo, valueToUse); byte[] expectedArray = (byte[])valueToUse.Clone(); Array.Resize(ref expectedArray, expectedOutputLength); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
protected MessageSerializedPropertyInfo GetPropertyInfo(MessageSerializedClassInfo classInfo, string propertyName) { foreach (MessageSerializedPropertyInfo propertyInfo in classInfo.Properties) { if (propertyInfo.PropertyInfo.Name == propertyName) { return(propertyInfo); } } throw new Exception($"Couldn't find property {propertyName} in {classInfo.ClassType.FullName}"); }
protected void TestField(MessageSerializedClassInfo classInfo, string propertyName, DateTime valueToUse) { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerDateTime typeSerializer = new TypeSerializerDateTime(propertyInfo); string format = propertyInfo.MessagePropertyAttribute.Format; string formattedValue = valueToUse.ToString(format); // TODO: This uses the same method as the class which is not really what we want byte[] expectedArray = ArrayOps.GetBcdBytes(Convert.ToUInt64(formattedValue), GetOutputLength(format)); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
public TestTypeSerializerByteArray() { _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass)); _testArrays = new byte[][] { new byte[] { 0x01 }, new byte[] { 0x01, 0x02, 0x03, 0x04 }, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B }, new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, }; }
protected void TestField(MessageSerializedClassInfo classInfo, string propertyName, string valueToUse) { MessageSerializedPropertyInfo propertyInfo = GetPropertyInfo(classInfo, propertyName); TypeSerializerString typeSerializer = new TypeSerializerString(propertyInfo); List <byte> list = new List <byte>(); foreach (char character in valueToUse) { list.Add((byte)character); } int outputLength = CalculateOutputLength(propertyInfo, valueToUse); if (outputLength < list.Count) { list.RemoveRange(outputLength, list.Count - outputLength); } else if (outputLength > list.Count && propertyInfo.MessagePropertyAttribute.Prepad) { while (outputLength > list.Count) { list.Insert(0, (byte)propertyInfo.MessagePropertyAttribute.PrepadCharacter); } } else if (outputLength > list.Count) { while (outputLength > list.Count) { list.Add((byte)0); } } byte[] expectedArray = list.ToArray(); TestField(typeSerializer, propertyInfo, valueToUse, expectedArray); }
public TestTypeSerializerDateTime() { _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass)); }
public TestTypeSerializerUserSpecified() { _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass)); }
public TestTypeSerializerString() { _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass)); }