public void ShouldProperlyEscapeOpenBraces() { string template = @"Not a \{namespace}"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); string formatted = formatter.FormatCategory(template); Assert.AreEqual("Not a {namespace}", formatted); }
public void ShouldReplaceTypeName() { string template = "Type {type}"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); Assert.AreEqual("Type CategoryFormatterFixture", formatter.FormatCategory(template)); }
public void ShouldReplaceMethodName() { string template = "Method {method}"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); Assert.AreEqual("Method TargetMethod", formatter.FormatCategory(template)); }
private TraceLogEntry GetLogEntry(IMethodInvocation input) { TraceLogEntry logEntry = new TraceLogEntry(); CategoryFormatter formatter = new CategoryFormatter(input.MethodBase); foreach (string category in categories) { logEntry.Categories.Add(formatter.FormatCategory(category)); } logEntry.EventId = eventId; logEntry.Priority = priority; logEntry.Severity = severity; logEntry.Title = LogCallHandlerDefaults.Title; if (includeParameters) { Dictionary <string, object> parameters = new Dictionary <string, object>(); for (int i = 0; i < input.Arguments.Count; ++i) { parameters[input.Arguments.GetParameterInfo(i).Name] = input.Arguments[i]; } logEntry.ExtendedProperties = parameters; } if (includeCallStack) { logEntry.CallStack = Environment.StackTrace; } logEntry.TypeName = input.Target.GetType().FullName; logEntry.MethodName = input.MethodBase.Name; return(logEntry); }
public void ShouldPropertyEscapeBackslashes() { string template = @"Here's a method: \\{method}"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); string formatted = formatter.FormatCategory(template); Assert.AreEqual(@"Here's a method: \TargetMethod", formatted); }
public void ShouldReplaceAssembly() { string template = "Assembly {assembly}"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); string formatted = formatter.FormatCategory(template); Assert.IsTrue(formatted.StartsWith("Assembly Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.Tests")); }
public void ShouldReplaceNamespace() { string template = "Namespace {namespace}"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); string formatted = formatter.FormatCategory(template); Assert.AreEqual("Namespace Microsoft.Practices.EnterpriseLibrary.Logging.Tests.PolicyInjection", formatted); }
public void ShouldNotReplaceWithoutReplacement() { string template = "No replacements here"; CategoryFormatter formatter = new CategoryFormatter(GetTargetMethod()); Assert.AreEqual(template, formatter.FormatCategory(template)); }
private TraceLogEntry GetLogEntry(IMethodInvocation input) { TraceLogEntry logEntry = new TraceLogEntry(); CategoryFormatter formatter = new CategoryFormatter(input.MethodBase); foreach (string category in categories) { logEntry.Categories.Add(formatter.FormatCategory(category)); } logEntry.EventId = eventId; logEntry.Priority = priority; logEntry.Severity = severity; logEntry.Title = LogCallHandlerDefaults.Title; if (includeParameters) { Dictionary<string, object> parameters = new Dictionary<string, object>(); for (int i = 0; i < input.Arguments.Count; ++i) { parameters[input.Arguments.GetParameterInfo(i).Name] = input.Arguments[i]; } logEntry.ExtendedProperties = parameters; } if (includeCallStack) { logEntry.CallStack = Environment.StackTrace; } logEntry.TypeName = input.Target.GetType().FullName; logEntry.MethodName = input.MethodBase.Name; return logEntry; }