public void AddAndGet_MultipleMessages_ReturnCorrectMessage()
        {
            MessagePool <StringMsg> pool = new MessagePool <StringMsg>();
            const string            firstMessageContents = "first message";
            StringMsg str1 = new StringMsg(firstMessageContents);
            StringMsg str2 = new StringMsg(firstMessageContents);

            pool.AddMessage(str1);
            pool.AddMessage(str2);
            StringMsg str3 = pool.GetOrCreateMessage();
            StringMsg str4 = pool.GetOrCreateMessage();
            StringMsg str5 = pool.GetOrCreateMessage();

            Assert.AreEqual(str1, str3);
            Assert.AreEqual(str2, str4);
            Assert.AreNotEqual(str1, str5);
            Assert.AreNotEqual(str2, str5);
        }
        public void AddAndGet_OneMessage_ReturnsSameMessage()
        {
            MessagePool <StringMsg> pool = new MessagePool <StringMsg>();
            const string            firstMessageContents = "first message";
            StringMsg str1 = new StringMsg(firstMessageContents);

            pool.AddMessage(str1);
            StringMsg str2 = pool.GetOrCreateMessage();
            StringMsg str3 = pool.GetOrCreateMessage();

            Assert.AreEqual(str1, str2);
            Assert.AreNotEqual(str2, str3);
        }
Exemple #3
0
        /// <summary>
        /// Obains a new Message for <code>TMessage</code> this can be a new Message a unused
        /// Message from the internal pool
        /// </summary>
        /// <typeparam name="TMessage">Type of data the message should wrap</typeparam>
        /// <returns>a (new) Message that can be used</returns>
        public static Message <TMessage> GetMessage <TMessage>()
        {
            Message <TMessage> message = MessagePool.GetMessage <TMessage>();

            if (message == null)
            {
                message        = new Message <TMessage>();
                message._inUse = true;
                MessagePool.AddMessage <TMessage>(message);
            }

            return(message);
        }
Exemple #4
0
        public static Message <TMessage> GetMessage <TMessage>(TMessage content)
        {
            Message <TMessage> message = MessagePool.GetMessage <TMessage>();

            if (message == null)
            {
                message        = new Message <TMessage>();
                message._inUse = true;
                MessagePool.AddMessage <TMessage>(message);
            }

            message.Content = content;

            return(message);
        }