示例#1
0
        public void RoundTripTest(bool dynamicallyCompact, int expectedLength, params object[] items)
        {
            MpRoot root = MsgPackItem.PackMultiple(dynamicallyCompact, items);

            byte[] bytes = root.ToBytes();

            Assert.AreEqual(expectedLength, bytes.Length, string.Concat("Expected ", expectedLength, " serialized bytes items but got ", bytes.Length, " bytes."));

            MpRoot result = MsgPackItem.UnpackMultiple(bytes, dynamicallyCompact);

            Assert.AreEqual(items.Length, result.Count, string.Concat("Expected ", items.Length, " items but got ", result.Count, " items after round trip."));

            for (int t = 0; t < result.Count; t++)
            {
                object expected = items[t];
                object actual   = result[t].Value;
                if (!dynamicallyCompact && !(expected is null))
                {
                    Type expectedType = expected.GetType();
                    Type foundType    = actual.GetType();
                    Assert.True(foundType == expectedType, string.Concat("Expected type of ", expectedType.ToString(), " but received the type ", foundType.ToString()));
                }

                Assert.AreEqual(expected, actual, "The returned value ", actual, " differs from the input value ", expected);
            }
        }
示例#2
0
        public void RoundTripTest(int expectedLength, params object[] items)
        {
            MpRoot root = MsgPackItem.PackMultiple(items);

            byte[] bytes = root.ToBytes();

            Assert.AreEqual(expectedLength, bytes.Length, string.Concat("Expected ", expectedLength, " serialized bytes items but got ", bytes.Length, " bytes."));

            MpRoot result = MsgPackItem.UnpackMultiple(bytes);

            Assert.AreEqual(items.Length, result.Count, string.Concat("Expected ", items.Length, " items but got ", result.Count, " items after round trip."));

            for (int t = 0; t < result.Count; t++)
            {
                object expected = items[t];
                object actual   = result[t].Value;

                Assert.AreEqual(expected, actual, "The returned value ", actual, " differs from the input value ", expected);
            }
        }