Esempio n. 1
0
        public void TestMessageHandler()
        {
            MockSender sender = new() { Id = 42 };

            TestMessageHandler handler = new();

            MockReceiver receiver = new();

            MessageProcessor processor = new();

            processor.SetMessageReceiver(receiver);

            MessageDictionary dic = MessageDictionary.GetInstance();

            processor.RegisterMessageHandler(handler);

            dic.AddOutgoingMessage(Module, Type, p =>
            {
                return(Tuple.Create(TestValue, 42));
            });

            var msg = dic.CreateMessage(Type);

            receiver.ReceiveMessage(new RawMessage(sender, msg.Serialize()));

            Assert.IsTrue(handler.Tcs.Task.Wait(100));
        }
    }
Esempio n. 2
0
        public Task InitializeModules()
        {
            foreach (var m in Modules.Values)
            {
                log.Debug("initializing " + m.Name);
                m.Logic.Initialize();
            }

            log.Debug("all loaded modules initialized");
            MessageDictionary.GetInstance().CreatePDF("messages.txt");
            return(Task.CompletedTask);
        }
        public void TestMessageDictionary()
        {
            var dic = MessageDictionary.GetInstance();

            //
            // register outgoing message
            //
            dic.AddOutgoingMessage(Module, Type, p =>
            {
                return(Tuple.Create((string)p[0], (int)p[1]));
            }, typeof(Tuple <string, int>), "testString", "testInt");

            //
            // double register message
            //
            Assert.ThrowsException <ArgumentException>(() =>
            {
                dic.AddOutgoingMessage(Module, Type, p =>
                {
                    return(Tuple.Create((string)p[0], (int)p[1]));
                }, typeof(Tuple <string, int>), "testString", "testInt");
            });

            //
            // create registered message
            //
            var msg = dic.CreateMessage(Type, TestValue, 42);

            Assert.IsTrue(msg.Module == Module);
            Assert.IsTrue(msg.Type == Type);
            Assert.IsTrue(msg.Data.GetType() == typeof(Tuple <string, int>));
            Assert.AreEqual(msg.Data, Tuple.Create(TestValue, 42));

            //
            // register and create message with complex type
            //
            dic.AddOutgoingMessage(Module, Type2, p =>
            {
                return(Tuple.Create((string)p[0], (int)p[1]));
            }, "testString", "testInt");

            msg = dic.CreateMessage(Type2, TestValue, 42);

            Assert.IsTrue(msg.Module == Module);
            Assert.IsTrue(msg.Type == Type2);
            Assert.IsTrue(msg.Data.GetType() == typeof(Tuple <string, int>));
            Assert.AreEqual(msg.Data, Tuple.Create(TestValue, 42));

            //
            // create unregistered message
            //
            Assert.ThrowsException <ArgumentException>(() =>
            {
                dic.CreateMessage("abc");
            });

            //
            // register incoming message (type is already used for outgoing message)
            //
            dic.AddIngoingMessage(Module, Type, typeof(string), "testString");

            //
            // double register ingoing message
            //

            Assert.ThrowsException <ArgumentException>(() =>
            {
                dic.AddIngoingMessage(Module, Type, typeof(string), "testString");
            });
        }