Skip to content

Commit

Permalink
Adding a Guid extension to messages that are copied to the log endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawnSpooner committed Apr 13, 2010
1 parent ebbde3f commit b6f8aa2
Show file tree
Hide file tree
Showing 17 changed files with 37,103 additions and 37,102 deletions.
308 changes: 154 additions & 154 deletions Rhino.ServiceBus.Tests/MessageLoggingTests.cs
@@ -1,155 +1,155 @@
using System;
using System.Transactions;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Rhino.Mocks;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.MessageModules;
using Rhino.ServiceBus.Messages;
using Xunit;

namespace Rhino.ServiceBus.Tests
{
public class MessageLoggingTests : MsmqTestBase
{
private readonly IWindsorContainer container;
private readonly ITransport transport;
private readonly IMessageSerializer messageSerializer;

public MessageLoggingTests()
{
container = new WindsorContainer(new XmlInterpreter());
container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());
container.AddComponent<MessageLoggingModule>();

messageSerializer = container.Resolve<IMessageSerializer>();

transport = MockRepository.GenerateStub<ITransport>();
}

[Fact]
public void Will_send_message_about_serialization_failure()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageSerializationException += null,
new CurrentMessageInformation { MessageId = Guid.NewGuid() },
new InvalidOperationException("Operation is not valid due to the current state of the object."));

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var serializationError = (SerializationErrorMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.Equal("System.InvalidOperationException: Operation is not valid due to the current state of the object.", serializationError.Error);
Assert.NotEqual(Guid.Empty, serializationError.MessageId);
}

[Fact]
public void Will_send_message_about_message_arrived()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageArrived += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
});

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var messageArrivedMessage = (MessageArrivedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, messageArrivedMessage.MessageId);
Assert.Equal("tst", messageArrivedMessage.Message);
}

[Fact]
public void Will_send_message_about_message_processing_completed()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageProcessingCompleted += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
},
new Exception());

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var processingCompletedMessage = (MessageProcessingCompletedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, processingCompletedMessage.MessageId);
}

[Fact]
public void Will_send_message_about_message_processing_failed()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageProcessingFailure += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
},
new IndexOutOfRangeException("Index was outside the bounds of the array."));

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var failedMessage = (MessageProcessingFailedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, failedMessage.MessageId);
Assert.Equal("System.IndexOutOfRangeException: Index was outside the bounds of the array.", failedMessage.ErrorText);
Assert.Equal("tst",failedMessage.Message);
}

[Fact]
public void Will_send_message_about_message_sent()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageSent += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
AllMessages = new[]{"test"}
});

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var failedMessage = (MessageSentMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, failedMessage.MessageId);
Assert.Equal(new[] { "test" }, failedMessage.Message);
}

[Fact]
public void Will_send_message_about_message_processing_failed_even_when_rolling_back_tx()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

using(new TransactionScope())
{
transport.Raise(x => x.MessageProcessingFailure += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
},
new IndexOutOfRangeException("Index was outside the bounds of the array."));
}

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var failedMessage = (MessageProcessingFailedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, failedMessage.MessageId);
Assert.Equal("System.IndexOutOfRangeException: Index was outside the bounds of the array.", failedMessage.ErrorText);
Assert.Equal("tst", failedMessage.Message);
}
}
using System;
using System.Transactions;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Rhino.Mocks;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.MessageModules;
using Rhino.ServiceBus.Messages;
using Xunit;

namespace Rhino.ServiceBus.Tests
{
public class MessageLoggingTests : MsmqTestBase
{
private readonly IWindsorContainer container;
private readonly ITransport transport;
private readonly IMessageSerializer messageSerializer;

public MessageLoggingTests()
{
container = new WindsorContainer(new XmlInterpreter());
container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());
container.AddComponent<MessageLoggingModule>();

messageSerializer = container.Resolve<IMessageSerializer>();

transport = MockRepository.GenerateStub<ITransport>();
}

[Fact]
public void Will_send_message_about_serialization_failure()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageSerializationException += null,
new CurrentMessageInformation { MessageId = Guid.NewGuid() },
new InvalidOperationException("Operation is not valid due to the current state of the object."));

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var serializationError = (SerializationErrorMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.Equal("System.InvalidOperationException: Operation is not valid due to the current state of the object.", serializationError.Error);
Assert.NotEqual(Guid.Empty, serializationError.MessageId);
}

[Fact]
public void Will_send_message_about_message_arrived()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageArrived += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
});

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var messageArrivedMessage = (MessageArrivedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, messageArrivedMessage.MessageId);
Assert.Equal("tst", messageArrivedMessage.Message);
}

[Fact]
public void Will_send_message_about_message_processing_completed()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageProcessingCompleted += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
},
new Exception());

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var processingCompletedMessage = (MessageProcessingCompletedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, processingCompletedMessage.MessageId);
}

[Fact]
public void Will_send_message_about_message_processing_failed()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageProcessingFailure += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
},
new IndexOutOfRangeException("Index was outside the bounds of the array."));

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var failedMessage = (MessageProcessingFailedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, failedMessage.MessageId);
Assert.Equal("System.IndexOutOfRangeException: Index was outside the bounds of the array.", failedMessage.ErrorText);
Assert.Equal("tst",failedMessage.Message);
}

[Fact]
public void Will_send_message_about_message_sent()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

transport.Raise(x => x.MessageSent += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
AllMessages = new[]{"test"}
});

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var failedMessage = (MessageSentMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, failedMessage.MessageId);
Assert.Equal(new[] { "test" }, failedMessage.Message);
}

[Fact]
public void Will_send_message_about_message_processing_failed_even_when_rolling_back_tx()
{
var module = container.Resolve<MessageLoggingModule>(new { logQueue = TestQueueUri.Uri });
module.Init(transport, null);

using(new TransactionScope())
{
transport.Raise(x => x.MessageProcessingFailure += null,
new CurrentMessageInformation
{
MessageId = Guid.NewGuid(),
Message = "tst"
},
new IndexOutOfRangeException("Index was outside the bounds of the array."));
}

var msg = queue.Receive(TimeSpan.FromSeconds(30));

var failedMessage = (MessageProcessingFailedMessage)messageSerializer.Deserialize(msg.BodyStream)[0];
Assert.NotEqual(Guid.Empty, failedMessage.MessageId);
Assert.Equal("System.IndexOutOfRangeException: Index was outside the bounds of the array.", failedMessage.ErrorText);
Assert.Equal("tst", failedMessage.Message);
}
}
}

0 comments on commit b6f8aa2

Please sign in to comment.