コード例 #1
0
        public void Server_Object_Client()
        {
            string   name   = "Cloet";
            string   text   = "This is the text of a custom object send to a client from the server.";
            DateTime date   = new DateTime(2000, 1, 1);
            double   number = 50.5989;

            var customObject = new DataObject(name, text, number, date);

            SimpleSockets.Client.ObjectReceivedDelegate msgRec = (client, obj, objType) => {
                if (objType == typeof(DataObject))
                {
                    var rec = (DataObject)Convert.ChangeType(obj, objType);
                    Assert.AreEqual(name, rec.Name);
                    Assert.AreEqual(text, rec.Text);
                    Assert.AreEqual(date, rec.Date);
                    Assert.AreEqual(number, rec.Number);
                }
                else
                {
                    Assert.IsTrue(false);
                }
            };

            using (var monitor = new EventMonitor(_client, "ObjectReceived", msgRec, Mode.MANUAL))
            {
                _server.SendObject(_clientid, customObject);
                monitor.Verify();
            }
        }
コード例 #2
0
ファイル: TcpSslTests.cs プロジェクト: hnjm/SimpleSockets
        public void Client_Message_Server()
        {
            string message = "This is a test message.";

            SimpleSockets.Server.MessageReceivedDelegate msgRec = (client, msg) => {
                Assert.AreEqual(message, msg);
            };

            using (var monitor = new EventMonitor(_server, "MessageReceived", msgRec, Mode.MANUAL))
            {
                _client.SendMessage(message);
                monitor.Verify();
            }
        }
コード例 #3
0
ファイル: TcpSslTests.cs プロジェクト: hnjm/SimpleSockets
        public void Server_MessageContract_Client()
        {
            string message = "This is a test message contract message server->client.";

            _contract.Message = message;

            Action <SimpleSocket, IClientInfo, object, string> msgRec = (socket, client, msg, head) => {
                Assert.AreEqual(message, msg);
            };

            using (var monitor = new EventMonitor(_contract, "OnMessageReceived", msgRec, Mode.MANUAL))
            {
                _server.SendMessageContract(_clientid, _contract);
                monitor.Verify();
            }
        }
コード例 #4
0
        public void Client_CustomMessage_Server()
        {
            string message    = "This is a test custom header message.";
            var    dictionary = new Dictionary <object, object>();

            dictionary.Add("Test", "This is a test");

            SimpleSockets.Server.MessageWithMetadataReceivedDelegate msgRec = (client, msg, head, type) => {
                Assert.AreEqual(message, msg);
                Assert.AreEqual(dictionary, head);
            };

            using (var monitor = new EventMonitor(_server, "MessageWithMetaDataReceived", msgRec, Mode.MANUAL)) {
                _client.SendMessageWithMetadata(message, dictionary);
                monitor.Verify();
            }
        }