public void TestLoggingDecorator() { // register services var registrar = new ContainerRegistrar(); registrar.RegisterConcrete<TotalFailure>(Lifetime.Transient); var container = registrar.Build(); // only log transient services var filter = new DelegateDecoratorFilter(ctx => ctx.Lifetime == Lifetime.Transient); var decorator = new ExceptionLoggerDecorator(this, filter); container.AddDecorator(decorator); // exception will be logged. var tmp = container.Resolve<TotalFailure>(); Assert.Throws<InvalidOperationException>(() => tmp.Fail("Big!")); Assert.IsType<InvalidOperationException>(_exception); }
public void TestDecorateHiearchy() { // register services var registrar = new ContainerRegistrar(); registrar.RegisterConcrete<Decorated1>(Lifetime.Transient); registrar.RegisterConcrete<Decorated2>(Lifetime.Transient); registrar.RegisterConcrete<Decorated3>(Lifetime.Transient); var container = registrar.Build(); // only log transient services var filter = new DelegateDecoratorFilter(ctx => ctx.Lifetime == Lifetime.Transient); var decorator = new ExceptionLoggerDecorator(this, filter); container.AddDecorator(decorator); // exception will be logged. var all = container.ResolveAll<IShouldBeDecorated>(); Assert.True(all.All(x => x.GetType().Name.Contains("Proxy"))); }