Example #1
0
        public void GetContextForMessageBody_ValidMessageContent_ShouldBeAbleToHandleMultipleParallelMessages()
        {
            // Arrange
            var mcp = new MessageContextProvider();

            var messages = new List <Mock <IMessage <object> > >();

            for (int i = 0; i < 500; i++)
            {
                var messageMock    = new Mock <IMessage <object> >();
                var messageContent = new object();
                messageMock.Setup(mc => mc.Content).Returns(messageContent);
                messages.Add(messageMock);
            }

            Parallel.ForEach(messages, message =>
            {
                mcp.StoreMessageContext(message.Object);

                // Act
                var messageContext1 = mcp.GetContextForMessageBody(message.Object.Content);
                var messageContext2 = mcp.GetContextForMessageBody(message.Object.Content);

                // Assert
                Assert.AreEqual(message.Object.Content, messageContext1.MessageContent);
                Assert.AreEqual(messageContext1, messageContext2);
            });
        }
Example #2
0
        public void GetContextForMessageBody_ValidMessageContent_ShouldBeSameInstanceRetrievedWithEachCallForTheSameContent()
        {
            // Arrange
            var mcp            = new MessageContextProvider();
            var message        = new Mock <IMessage <object> >();
            var messageContent = new object();

            message.Setup(mc => mc.Content).Returns(messageContent);
            mcp.StoreMessageContext(message.Object);

            // Act
            var messageContext1 = mcp.GetContextForMessageBody(messageContent);
            var messageContext2 = mcp.GetContextForMessageBody(messageContent);

            // Assert
            Assert.AreEqual(messageContext1, messageContext2);
        }
Example #3
0
        public void GetContextForMessageBody_ValidMessageContent_ShouldBeAvailableAfterStore()
        {
            // Arrange
            var mcp            = new MessageContextProvider();
            var message        = new Mock <IMessage <object> >();
            var messageContent = new object();

            message.Setup(mc => mc.Content).Returns(messageContent);
            mcp.StoreMessageContext(message.Object);

            // Act
            var messageContext = mcp.GetContextForMessageBody(messageContent);

            // Assert
            Assert.IsNotNull(messageContext);
        }