Created
October 14, 2016 05:15
-
-
Save mikeminutillo/fe9a38934099d817b539c908c0d23612 to your computer and use it in GitHub Desktop.
NSB v6 Accept Test Request Tracing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adds a list of all outgoing and incoming messages to the scenario context trace which will be dumped at test completion.