Exemple #1
0
 protected void TestFieldWithValues <TEnumType>(MessageSerializedClassInfo classInfo, string propertyName, TEnumType[] valuesToUse) where TEnumType : struct, IConvertible
 {
     foreach (TEnumType value in valuesToUse)
     {
         TestField(classInfo, propertyName, value);
     }
 }
Exemple #2
0
        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);
        }
Exemple #3
0
 protected void TestFieldWithValues(MessageSerializedClassInfo classInfo, string propertyName, string[] valuesToUse)
 {
     foreach (string value in valuesToUse)
     {
         TestField(classInfo, propertyName, value);
     }
 }
Exemple #4
0
 protected void TestFieldWithValues <TNumericType>(MessageSerializedClassInfo classInfo, string propertyName, TNumericType[] valuesToUse) where TNumericType : struct
 {
     foreach (TNumericType value in valuesToUse)
     {
         TestField(classInfo, propertyName, value);
     }
 }
Exemple #5
0
        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);
        }
Exemple #6
0
 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]);
     }
 }
Exemple #7
0
 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]);
     }
 }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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}");
        }
Exemple #15
0
        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);
        }
Exemple #16
0
 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 },
     };
 }
Exemple #17
0
        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);
        }
Exemple #18
0
 public TestTypeSerializerDateTime()
 {
     _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass));
 }
Exemple #19
0
 public TestTypeSerializerUserSpecified()
 {
     _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass));
 }
Exemple #20
0
 public TestTypeSerializerString()
 {
     _classInfo = Serializer.Instance.GetClassInfo(typeof(TestClass));
 }