public void Should_not_store_the_message_if_handle_current_message_later_was_called()
        {
            var incomingTransportMessage = new TransportMessage();

            var context = new IncomingContext(null, incomingTransportMessage)
            {
                handleCurrentMessageLaterWasCalled = true
            };

            context.Set(new OutboxMessage("SomeId"));

            Invoke(context);

            Assert.Null(fakeOutbox.StoredMessage);
        }
Beispiel #2
0
        private void ProcessMessagesFromBridge()
        {
            using (SqlConnection conn = new SqlConnection(Context.BridgeConnectionString.Invoke()))
            {
                conn.Open();
                string     sql = "SELECT MessageId, Source, Destination, Intent, Processed, Headers, Body FROM [dbo].[Bridge] WHERE Processed = 0 AND (Destination = @Destination OR Destination IS NULL)";
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.Parameters.AddWithValue("@Destination", Settings.EndpointName());
                var reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    string id        = reader.GetString(reader.GetOrdinal("MessageId"));
                    string source    = reader.GetString(reader.GetOrdinal("Source"));
                    string dest      = reader.IsDBNull(reader.GetOrdinal("Destination")) ? null : reader.GetString(reader.GetOrdinal("Destination"));
                    string intent    = reader.GetString(reader.GetOrdinal("Intent"));
                    var    msgIntent = (MessageIntentEnum)Enum.Parse(typeof(MessageIntentEnum), intent);
                    Dictionary <string, string> headers = JsonConvert.DeserializeObject <Dictionary <string, string> >(reader.GetString(reader.GetOrdinal("Headers")));
                    var messageTypes = headers[Headers.EnclosedMessageTypes].Split(';').Select(i => Type.GetType(i)).ToList();
                    if (ShouldHandleMessage(dest, messageTypes))
                    {
                        var    bodyStream = reader.GetStream(reader.GetOrdinal("Body"));
                        byte[] body       = new byte[bodyStream.Length];
                        body = GetByteArray(bodyStream);


                        //Let's treat this message as a normal incoming message.
                        var transportMessage = new TransportMessage(id, headers);
                        transportMessage.Body          = body;
                        transportMessage.MessageIntent = msgIntent;
                        var incomingContext = new IncomingContext(null, transportMessage);
                        incomingContext.Set <IBuilder>(Builder);
                        PipelineExecutor.InvokePipeline(PipelineExecutor.Incoming.Select(i => i.BehaviorType), incomingContext);

                        var cmd2 = new SqlCommand("UPDATE [dbo].[Bridge] SET Processed = 1 WHERE MessageId = @MessageId", conn);
                        cmd2.Parameters.AddWithValue("@MessageId", id);
                        cmd2.ExecuteNonQuery();
                    }
                }
            }
        }