Exemplo n.º 1
0
        public void ConvertManyTest()
        {
            var count     = 100000;
            var testItems = Enumerable.Range(0, 10).Select(i => CreateTestDataItem($"item-{i}", i)).ToArray();
            var testData  = CreateTestData(Guid.NewGuid().ToString(), 1, testItems);

            var serializer = new Serializer();

            serializer.LoadFromReference <SerializerTests>();

            var bytes = new byte[1024];
            var index = 0;

            var watch = Stopwatch.StartNew();

            for (int i = 0; i < count; i++)
            {
                index = 0;
                serializer.AddBytes(testData, bytes, ref index);
            }

            watch.Stop();

            // 100k 2.3s
            // po perdarymo
            // 100k 2.0s
        }
Exemplo n.º 2
0
        public void ConvertTest()
        {
            var testItems = Enumerable.Range(0, 10).Select(i => CreateTestDataItem($"item-{i}", i)).ToList();
            var inhItem   = new InheritTestDataItem()
            {
                Id       = ByteArray.New(32),
                Name     = "Inh",
                Number   = 197452374654985980.596417987646462946M,
                Value    = 5,
                Type     = TestType.InhItem,
                NulValue = 19
            };

            testItems.Add(inhItem);
            var testData = CreateTestData(Guid.NewGuid().ToString(), 1, testItems.ToArray());

            var serializer = new Serializer();

            serializer.LoadFromReference <SerializerTests>();

            var bytes = new byte[1024];
            var index = 0;

            serializer.AddBytes(testData, bytes, ref index);

            index = 0;
            var back = (TestData)serializer.GetObject(bytes, ref index);

            Assert.AreEqual(testData.Id, back.Id);
            Assert.IsNotNull(back.Items);
            Assert.AreEqual(testData.Values[0], back.Values[0]);
            Assert.AreEqual(testData.Values[1], back.Values[1]);
            Assert.AreEqual(testData.Date.Year, back.Date.Year);
            Assert.AreEqual(testData.Date.Day, back.Date.Day);
            Assert.AreEqual(testData.Date.Millisecond, back.Date.Millisecond);
            Assert.AreEqual(testData.Dates[0].Year, back.Dates[0].Year);
            Assert.AreEqual(testData.Dates[0].Day, back.Dates[0].Day);
            Assert.AreEqual(testData.Dates[0].Millisecond, back.Dates[0].Millisecond);
            Assert.AreEqual(testData.Items.Length, back.Items.Length);
            Assert.AreEqual(testData.Items[testItems.Count - 1].Name, back.Items[testItems.Count - 1].Name);
            Assert.IsInstanceOfType(back.Items[0], typeof(TestDataItem));
            Assert.AreEqual(testData.Items[0].NulValue, back.Items[0].NulValue);
            Assert.AreEqual(19, back.Items[testItems.Count - 1].NulValue);
            Assert.IsInstanceOfType(back.Items[testItems.Count - 1], typeof(InheritTestDataItem));

            var backInhItem = (InheritTestDataItem)back.Items[testItems.Count - 1];

            Assert.AreEqual(inhItem.Number, backInhItem.Number);
        }
Exemplo n.º 3
0
        public void GuidTest()
        {
            var serializer = new Serializer();

            serializer.LoadFromReference <SerializerTests>();

            var obj = Guid.NewGuid();

            var bytes = new byte[64];
            var index = 0;

            serializer.AddBytes(obj, bytes, ref index);

            index = 0;
            var back = (Guid)serializer.GetObject(bytes, ref index);

            Assert.AreEqual(obj, back);
        }
Exemplo n.º 4
0
        public void DateTimeTest()
        {
            var serializer = new Serializer();

            serializer.LoadFromReference <SerializerTests>();

            var obj = DateTime.Now.AddYears(-3).AddDays(-2).AddMilliseconds(-100);

            var bytes = new byte[64];
            var index = 0;

            serializer.AddBytes(obj, bytes, ref index);

            index = 0;
            var back = (DateTime)serializer.GetObject(bytes, ref index);

            Assert.AreEqual(obj.Date.Year, back.Date.Year);
            Assert.AreEqual(obj.Date.Day, back.Date.Day);
            Assert.AreEqual(obj.Date.Millisecond, back.Date.Millisecond);
        }
Exemplo n.º 5
0
        public void IArrayConverterTest()
        {
            var serializer = new Serializer();

            serializer.LoadFromReference <SerializerTests>();

            var obj = new byte[] { 5, 7, 20 };

            var bytes = new byte[64];
            var index = 0;

            serializer.AddBytes(obj, bytes, ref index);

            index = 0;
            var back = serializer.GetObject(bytes, ref index) as byte[];

            Assert.IsNotNull(back);
            Assert.AreEqual(obj.Length, back.Length);
            Assert.IsTrue(obj.ContainsSequence32(back));
        }
Exemplo n.º 6
0
        public void ConvertArrayTest()
        {
            var testItems = Enumerable.Range(0, 10).Select(i => CreateTestDataItem($"item-{i}", i)).ToArray();
            //var testData = CreateTestData(Guid.NewGuid().ToString(), 1, testItems);

            var serializer = new Serializer();

            serializer.LoadFromReference <SerializerTests>();

            var bytes = new byte[1024];
            var index = 0;

            serializer.AddBytes(testItems, bytes, ref index);

            index = 0;
            var back = (TestDataItem[])serializer.GetObject(bytes, ref index);

            Assert.IsNotNull(back);
            Assert.AreEqual(testItems.Length, back.Length);
            Assert.AreEqual(testItems[0].Id, back[0].Id);
            Assert.AreEqual(testItems[0].Name, back[0].Name);
            Assert.AreEqual(testItems[testItems.Length - 1].Id, back[testItems.Length - 1].Id);
            Assert.AreEqual(testItems[testItems.Length - 1].Name, back[testItems.Length - 1].Name);
        }