public async Task SerializationTest(
            [Values(1, 2, 3)] int count,
            [Range(0, 100, 25)] int nullsPercentage)
        {
            var randoms = new Dictionary <ListNode, int?>();

            ListNode cloneNode = null;
            ListNode previous  = null;

            Task Serialize(int?randomId = null, in string data = null)
            {
                var current = new ListNode {
                    Previous = previous, Data = data.DeepCopy()
                };

                if (previous != null)
                {
                    previous.Next = current;
                }
                previous = current;
                randoms.Add(current, randomId);
                cloneNode ??= current;
                return(Task.CompletedTask);
            }

            var sourceNode = TestsHelper.GenerateListNode(count, nullsPercentage);

            await using var stream = Stream.Null;
            var serializer = TestsHelper.CreateSerializer(writer => Serialize);
            await serializer.Serialize(sourceNode, stream);

            RestoreRandoms(randoms);
            TestsHelper.CheckEqual(sourceNode, cloneNode);
        }
Exemplo n.º 2
0
        public Task DeserializationLongRunTest(
            [Values(1000)] int count = 1000,
            [Range(0, 100, 25)] int nullsPercentage = 50,
            [Values(100)] int parallels             = 100,
            [Values(1000)] int repeats      = 1000,
            [Values(30)] int timeoutSeconds = 30)
        {
            return(Task.CompletedTask);

            var sourceNode          = TestsHelper.GenerateListNode(count, nullsPercentage);
            var deserializationInfo = CreateDeserializationInfo(sourceNode);

            Task Deserialize(DeserializeAction deserialize)
            {
                foreach (var nodeInfo in deserializationInfo)
                {
                    deserialize(nodeInfo.RandomId, nodeInfo.Data);
                }
                return(Task.CompletedTask);
            }

            var serializer = TestsHelper.CreateSerializer(reader => Deserialize);

            return(TestsHelper.RunStreamTasks(
                       () => Stream.Null,
                       stream => serializer.Deserialize(stream),
                       parallels, repeats, timeoutSeconds));
        }
Exemplo n.º 3
0
        public async Task DeepCopyTest(
            [Values(1, 2, 3)] int count,
            [Range(0, 100, 25)] int nullsPercentage)
        {
            var sourceNode = TestsHelper.GenerateListNode(count, nullsPercentage);
            var serializer = TestsHelper.CreateSerializer();
            var cloneNode  = await serializer.DeepCopy(sourceNode);

            TestsHelper.CheckEqual(sourceNode, cloneNode);
        }
        public Task SerializationLongRunTest(
            [Values(1000)] int count = 1000,
            [Range(0, 100, 25)] int nullsPercentage = 50,
            [Values(100)] int parallels             = 100,
            [Values(1000)] int repeats      = 1000,
            [Values(30)] int timeoutSeconds = 30)
        {
            return(Task.CompletedTask);

            var sourceNode = TestsHelper.GenerateListNode(count, nullsPercentage);
            var serializer = TestsHelper.CreateSerializer();

            return(TestsHelper.RunStreamTasks(
                       () => Stream.Null,
                       stream => serializer.Serialize(sourceNode, stream),
                       parallels, repeats, timeoutSeconds));
        }
Exemplo n.º 5
0
        public async Task DeserializationTest(
            [Values(1, 2, 3)] int count,
            [Range(0, 100, 25)] int nullsPercentage)
        {
            var sourceNode          = TestsHelper.GenerateListNode(count, nullsPercentage);
            var deserializationInfo = CreateDeserializationInfo(sourceNode);

            Task Deserialize(DeserializeAction deserialize)
            {
                foreach (var nodeInfo in deserializationInfo)
                {
                    deserialize(nodeInfo.RandomId, nodeInfo.Data);
                }
                return(Task.CompletedTask);
            }

            await using var stream = Stream.Null;
            var serializer = TestsHelper.CreateSerializer(reader => Deserialize);
            var cloneNode  = await serializer.Deserialize(stream);

            TestsHelper.CheckEqual(sourceNode, cloneNode);
        }