Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created October 14, 2016 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeminutillo/fe9a38934099d817b539c908c0d23612 to your computer and use it in GitHub Desktop.
Save mikeminutillo/fe9a38934099d817b539c908c0d23612 to your computer and use it in GitHub Desktop.
NSB v6 Accept Test Request Tracing
static class RequestTracing
{
public static void EnableRequestTracing(this EndpointConfiguration cfg)
{
cfg.Pipeline.Register(typeof(LogIncomingBehavior), "Log incoming messages");
cfg.Pipeline.Register(typeof(LogOutgoingBehavior), "Log outgoing messages");
}
class LogOutgoingBehavior : Behavior<IDispatchContext>
{
public ScenarioContext TestContext { get; set; }
public ReadOnlySettings Settings { get; set; }
public override Task Invoke(IDispatchContext context, Func<Task> next)
{
foreach (var operation in context.Operations)
{
TestContext.AddTrace($"{Settings.LocalAddress()} sent message {operation.Message.Headers[Headers.EnclosedMessageTypes]} to {Read((dynamic)operation.AddressTag)}");
}
return next();
}
static string Read(UnicastAddressTag addressTag) => $"UNICAST: {addressTag.Destination}";
static string Read(MulticastAddressTag addressTag) => $"MULTICAST: {addressTag.MessageType.FullName}";
}
class LogIncomingBehavior : Behavior<ITransportReceiveContext>
{
public ScenarioContext TestContext { get; set; }
public ReadOnlySettings Settings { get; set; }
public override Task Invoke(ITransportReceiveContext context, Func<Task> next)
{
TestContext.AddTrace($"{Settings.LocalAddress()} received message {context.Message.Headers[Headers.EnclosedMessageTypes]} from {context.Message.Headers[Headers.OriginatingEndpoint]}");
return next();
}
}
}
@mikeminutillo
Copy link
Author

Adds a list of all outgoing and incoming messages to the scenario context trace which will be dumped at test completion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment