public async Task TestSimpleSendRecieve()
        {
            // Connect B to A:
            LocalNetworkConnection connectionOnA = null;

            factoryA.OnClientConnected += (sender, connectoin) => { connectionOnA = connectoin; };

            LocalNetworkConnection connectionOnB = await factoryB.ConnectToAsync(0);

            await Task.Delay(100);

            // Send message from B to A:
            INetworkMessage recievedOnA = null;

            connectionOnA.OnRecieve += (sender, message) => { recievedOnA = message; };

            INetworkMessage sendFromB = new DirectNetworkMessage(
                DhtUtils.GeneratePlayerId(),
                DhtUtils.GeneratePlayerId(),
                DhtUtils.GeneratePlayerId(),
                new byte[] { 42 });

            connectionOnB.Send(sendFromB);

            await Task.Delay(100);

            // Assert:
            Assert.IsNotNull(recievedOnA);
            Assert.AreEqual(42, ((DirectNetworkMessage)recievedOnA).Data[0]);
        }
示例#2
0
        public void TestDistance2()
        {
            Guid a = new Guid(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 4, 0 });
            Guid b = new Guid(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 1, 0 });

            var actual   = DhtUtils.XorDistance(a, b);
            var expected = new BigInteger(1280);

            Assert.AreEqual(expected, actual);
        }
示例#3
0
        public void TestDistanceExp3()
        {
            Guid a = new Guid(new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 5, 6, 7, 0, 0, 0, 0, 4 });
            Guid b = new Guid(new byte[] { 128, 0, 0, 0, 0, 0, 0, 0, 8, 7, 245, 0, 0, 0, 0, 8 });

            var actual   = DhtUtils.DistanceExp(a, b);
            var expected = 0;

            Assert.AreEqual(expected, actual);
        }
示例#4
0
        public void TestDistanceExp2()
        {
            Guid a = new Guid(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 });
            Guid b = new Guid(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 });

            var actual   = DhtUtils.DistanceExp(a, b);
            var expected = 124;

            Assert.AreEqual(expected, actual);
        }
示例#5
0
        public void TestMergeLeaderboards()
        {
            var a = new Dictionary <string, string>
            {
                { "player1", "42.5" },
                { "player5", "11.2" }
            };
            var b = new Dictionary <string, string>
            {
                { "player2", "18.3" },
                { "player5", "35" }
            };

            NetworkFile fileA = new NetworkFile(DhtUtils.GenerateFileId(), Guid.Empty, a.ToImmutableDictionary());
            NetworkFile fileB = new NetworkFile(DhtUtils.GenerateFileId(), Guid.Empty, b.ToImmutableDictionary());

            //FilesMerger.MergeFiles();
        }
示例#6
0
        public async Task TestGetNotExistingFile()
        {
            await relay1.ConnectToNodeAsync(0);

            await relay1.ConnectToNodeAsync(2);

            await Task.Delay(100);

            // Get not existing file on node 1:
            NetworkFile file           = null;
            bool        callbackCalled = false;

            relay1.GetFile(DhtUtils.GenerateFileId(), (s, f) =>
            {
                file           = f;
                callbackCalled = true;
            });

            await Task.Delay(100);

            Assert.IsNull(file);
            Assert.IsTrue(callbackCalled);
        }