Exemple #1
0
        public async Task ConnectToPeersTestMethod()
        {
            WebSocketConnection _connection = null;
            List <string>       _log        = new List <string>();
            Task _server = WebSocketServer.Server(3001, x => { _connection = x; x.onMessage = m => _log.Add($"received message by test WS: {m}"); });
            TestRepositoryNetwork _repository = new TestRepositoryNetwork();

            using (CommunicationEngine _new = new CommunicationEngine(_repository, -1, x => _log.Add(x)))
            {
                Assert.AreEqual <int>(2, _log.Count);
                Assert.IsTrue(_repository.IsCosistent);
                Uri[] _peers = new Uri[] { new Uri("ws://localhost:3001") };
                _new.ConnectToPeers(_peers);
                await Task.Delay(200);

                Assert.IsNotNull(_connection);
                Assert.AreEqual <int>(5, _log.Count);
                Message _requestLast = new Message()
                {
                    data = string.Empty, type = Message.MessageType.QUERY_LATEST
                };
                await _connection.SendAsync(_requestLast.Stringify <Message>());

                await Task.Delay(300);

                Assert.AreEqual <int>(8, _log.Count);
                Assert.IsTrue(_log[7].Contains("received message by test"));
            }
            foreach (string _message in _log.ToArray())
            {
                Debug.WriteLine(_message);
            }
        }
Exemple #2
0
        public void ConstructorTestMethod()
        {
            List <string>         _log        = new List <string>();
            TestRepositoryNetwork _repository = new TestRepositoryNetwork();

            using (CommunicationEngine _new = new CommunicationEngine(_repository, -1, x => _log.Add(x)))
            {
                Assert.AreEqual <int>(2, _log.Count);
                Assert.IsTrue(_repository.IsCosistent);
            }
        }