Example #1
0
        void RoundtripTest(DagNode a)
        {
            var ms = new MemoryStream();

            a.Write(ms);
            ms.Position = 0;
            var b = new DagNode(ms);

            CollectionAssert.AreEqual(a.DataBytes, b.DataBytes);
            CollectionAssert.AreEqual(a.ToArray(), b.ToArray());
            Assert.AreEqual(a.Links.Count(), b.Links.Count());
            a.Links.Zip(b.Links, (first, second) =>
            {
                Assert.AreEqual(first.Id, second.Id);
                Assert.AreEqual(first.Name, second.Name);
                Assert.AreEqual(first.Size, second.Size);
                return(first);
            }).ToArray();

            using (var first = a.DataStream)
                using (var second = b.DataStream)
                {
                    Assert.AreEqual(first.Length, second.Length);
                    for (int i = 0; i < first.Length; ++i)
                    {
                        Assert.AreEqual(first.ReadByte(), second.ReadByte());
                    }
                }
        }
        void RoundtripTest(DagNode a)
        {
            var ms = new MemoryStream();

            a.Write(ms);
            ms.Position = 0;
            var b = new DagNode(ms);

            CollectionAssert.AreEqual(a.Data, b.Data);
            Assert.AreEqual(a.Links.Count(), b.Links.Count());
            a.Links.Zip(b.Links, (first, second) =>
            {
                Assert.AreEqual(first.Hash, second.Hash);
                Assert.AreEqual(first.Name, second.Name);
                Assert.AreEqual(first.Size, second.Size);
                return(first);
            }).ToArray();
        }