Beispiel #1
0
        public void CanBeSerialized()
        {
            var peerSetDelta = new PeerSetDelta(
                new Peer(
                    new PrivateKey().PublicKey,
                    new[] { new Uri("inproc://a") }
                    ),
                DateTimeOffset.UtcNow,
                new[]
            {
                new Peer(
                    new PrivateKey().PublicKey,
                    new[] { new Uri("inproc://added") }),
            }.ToImmutableHashSet(),
                new[]
            {
                new Peer(
                    new PrivateKey().PublicKey,
                    new[] { new Uri("inproc://removed") }),
            }.ToImmutableHashSet(),
                null
                );
            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, peerSetDelta);
                stream.Seek(0, SeekOrigin.Begin);

                var deserialized = (PeerSetDelta)formatter.Deserialize(stream);
                Assert.Equal(peerSetDelta, deserialized);
            }
        }
Beispiel #2
0
        public void Serialize()
        {
            var peerSetDelta = new PeerSetDelta(
                new Peer(
                    new PrivateKey().PublicKey,
                    new DnsEndPoint("0.0.0.0", 1234)
                    ),
                DateTimeOffset.UtcNow,
                new[]
            {
                new Peer(
                    new PrivateKey().PublicKey,
                    new DnsEndPoint("1.2.3.4", 1234)),
            }.ToImmutableHashSet(),
                new[]
            {
                new Peer(
                    new PrivateKey().PublicKey,
                    new DnsEndPoint("2.3.4.5", 1234)),
            }.ToImmutableHashSet(),
                null
                );
            var formatter = new BinaryFormatter();

            using (var stream = new MemoryStream())
            {
                formatter.Serialize(stream, peerSetDelta);
                stream.Seek(0, SeekOrigin.Begin);

                var deserialized = (PeerSetDelta)formatter.Deserialize(stream);
                Assert.Equal(peerSetDelta, deserialized);
            }
        }