public void ShouldCreateWithEveryOtherSetting() { LogCallHandlerAttribute attribute = new LogCallHandlerAttribute(); attribute.EventId = 67; attribute.LogBeforeCall = false; attribute.LogAfterCall = false; attribute.BeforeMessage = "Before call log"; attribute.AfterMessage = "After call log"; attribute.Categories = new string[] { "Lots", "of", "categories", "here" }; attribute.IncludeParameters = false; attribute.IncludeCallStack = true; attribute.IncludeCallTime = false; attribute.Priority = 762; attribute.Severity = TraceEventType.Critical; LogCallHandler handler = GetHandlerFromAttribute(attribute); Assert.AreEqual(attribute.EventId, handler.EventId); Assert.AreEqual(attribute.LogBeforeCall, handler.LogBeforeCall); Assert.AreEqual(attribute.LogAfterCall, handler.LogAfterCall); Assert.AreEqual(attribute.BeforeMessage, handler.BeforeMessage); Assert.AreEqual(attribute.AfterMessage, handler.AfterMessage); Assert.AreEqual(attribute.Categories.Length, handler.Categories.Count); for (int i = 0; i < attribute.Categories.Length; ++i) { Assert.AreEqual(attribute.Categories[i], handler.Categories[i], "Category mismatch at index {0}", i); } Assert.AreEqual(attribute.IncludeParameters, handler.IncludeParameters); Assert.AreEqual(attribute.IncludeCallStack, handler.IncludeCallStack); Assert.AreEqual(attribute.IncludeCallTime, handler.IncludeCallTime); Assert.AreEqual(attribute.Priority, handler.Priority); Assert.AreEqual(attribute.Severity, handler.Severity); }
public void ShouldCreateWithMultipleCategories() { LogCallHandlerAttribute attribute = new LogCallHandlerAttribute(); attribute.Categories = new string[] { "This", "That", "The Other" }; LogCallHandler handler = GetHandlerFromAttribute(attribute); Assert.AreEqual(attribute.Categories.Length, handler.Categories.Count); for (int i = 0; i < attribute.Categories.Length; ++i) { Assert.AreEqual(attribute.Categories[i], handler.Categories[i]); } }
private PolicySet GetLoggingPolicies() { RuleDrivenPolicy p = new RuleDrivenPolicy("Logging"); p.RuleSet.Add(new TypeMatchingRule("LoggingTarget")); callHandler = new LogCallHandler(log); callHandler.LogBeforeCall = callHandler.LogAfterCall = true; callHandler.BeforeMessage = beforeMessage; callHandler.AfterMessage = afterMessage; callHandler.Categories.Add("General"); callHandler.Categories.Add("PIAB"); p.Handlers.Add(callHandler); return(new PolicySet(p)); }
public void ShouldCreateDefaultLogHandler() { LogCallHandlerAttribute attribute = new LogCallHandlerAttribute(); LogCallHandler handler = GetHandlerFromAttribute(attribute); Assert.AreEqual(LogCallHandlerDefaults.EventId, handler.EventId); Assert.AreEqual(LogCallHandlerDefaults.AfterMessage, handler.AfterMessage); Assert.AreEqual(LogCallHandlerDefaults.BeforeMessage, handler.BeforeMessage); Assert.AreEqual(0, handler.Categories.Count); Assert.AreEqual(LogCallHandlerDefaults.IncludeCallStack, handler.IncludeCallStack); Assert.AreEqual(LogCallHandlerDefaults.IncludeCallTime, handler.IncludeCallTime); Assert.AreEqual(LogCallHandlerDefaults.IncludeParameters, handler.IncludeParameters); Assert.AreEqual(LogCallHandlerDefaults.LogAfterCall, handler.LogAfterCall); Assert.AreEqual(LogCallHandlerDefaults.LogBeforeCall, handler.LogBeforeCall); Assert.AreEqual(LogCallHandlerDefaults.Priority, handler.Priority); Assert.AreEqual(LogCallHandlerDefaults.Severity, handler.Severity); }
/// <summary> /// Builds an instance of the subtype of <typeparamref name="TObject"/> type the receiver knows how to build, based on /// an a configuration object. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of the <typeparamref name="TObject"/> subtype.</returns> public ICallHandler Assemble(IBuilderContext context, CallHandlerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { LogCallHandlerData handlerData = (LogCallHandlerData)objectConfiguration; LogCallHandler callHandler = new LogCallHandler(configurationSource); switch (handlerData.LogBehavior) { case HandlerLogBehavior.Before: callHandler.LogBeforeCall = true; callHandler.LogAfterCall = false; break; case HandlerLogBehavior.After: callHandler.LogBeforeCall = false; callHandler.LogAfterCall = true; break; case HandlerLogBehavior.BeforeAndAfter: callHandler.LogBeforeCall = true; callHandler.LogAfterCall = true; break; } callHandler.BeforeMessage = handlerData.BeforeMessage; callHandler.AfterMessage = handlerData.AfterMessage; callHandler.EventId = handlerData.EventId; callHandler.IncludeCallStack = handlerData.IncludeCallStack; callHandler.IncludeCallTime = handlerData.IncludeCallTime; callHandler.IncludeParameters = handlerData.IncludeParameterValues; callHandler.Priority = handlerData.Priority; callHandler.Severity = handlerData.Severity; callHandler.Categories.Clear(); handlerData.Categories.ForEach( delegate(LogCallHandlerCategoryEntry entry) { callHandler.Categories.Add(entry.Name); } ); return(callHandler); }
LoggingTarget CreateTarget() { callHandler = new LogCallHandler(); callHandler.LogBeforeCall = callHandler.LogAfterCall = true; callHandler.BeforeMessage = beforeMessage; callHandler.AfterMessage = afterMessage; callHandler.Categories.Add("General"); callHandler.Categories.Add("PIAB"); IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); container.Configure <Interception>() .SetDefaultInterceptorFor <LoggingTarget>(new TransparentProxyInterceptor()) .AddPolicy("Logging") .AddMatchingRule(new TypeMatchingRule("LoggingTarget")) .AddCallHandler(callHandler); return(container.Resolve <LoggingTarget>()); }
public void AssembledCorrectlyLogCallHandler() { using (var configSource = new FileConfigurationSource("LogCallHandler.config", false)) { Logger.SetLogWriter(new LogWriterFactory(configSource.GetSection).Create(), false); PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData("policy"); LogCallHandlerData data = new LogCallHandlerData("fooHandler", 66); data.BeforeMessage = "before"; data.AfterMessage = "after"; data.IncludeCallTime = true; data.EventId = 100; data.Categories.Add(new LogCallHandlerCategoryEntry("category1")); data.Categories.Add(new LogCallHandlerCategoryEntry("category2")); policyData.MatchingRules.Add(new CustomMatchingRuleData("matchesEverything", typeof(AlwaysMatchingRule))); policyData.Handlers.Add(data); settings.Policies.Add(policyData); using (var container = new UnityContainer().AddNewExtension <Interception>()) { settings.ConfigureContainer(container); var policy = container.Resolve <InjectionPolicy>("policy"); LogCallHandler handler = (LogCallHandler) (policy.GetHandlersFor(GetMethodImpl(MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(handler); Assert.AreEqual(66, handler.Order); Assert.AreEqual("before", handler.BeforeMessage); Assert.AreEqual("after", handler.AfterMessage); Assert.AreEqual(true, handler.IncludeCallTime); Assert.AreEqual(100, handler.EventId); Assert.AreEqual(2, handler.Categories.Count); CollectionAssert.Contains(handler.Categories, "category1"); CollectionAssert.Contains(handler.Categories, "category2"); } } }