public void ConfigurationRegistersHookPointsCorrectly() { var configuration = new ApiConfiguration(); Assert.Null(configuration.GetHookHandler <IHookA>()); Assert.Null(configuration.GetHookHandler <IHookB>()); var singletonHookPoint = new HookA(); configuration.AddHookHandler <IHookA>(singletonHookPoint); Assert.Same(singletonHookPoint, configuration.GetHookHandler <IHookA>()); Assert.Null(configuration.GetHookHandler <IHookB>()); var multiCastHookPoint1 = new HookB(); configuration.AddHookHandler <IHookB>(multiCastHookPoint1); Assert.Same(singletonHookPoint, configuration.GetHookHandler <IHookA>()); Assert.Equal(multiCastHookPoint1, configuration.GetHookHandler <IHookB>()); var multiCastHookPoint2 = new HookB(); configuration.AddHookHandler <IHookB>(multiCastHookPoint2); var handler = configuration.GetHookHandler <IHookB>(); Assert.Equal(multiCastHookPoint2, handler); var delegateHandler = handler as IDelegateHookHandler <IHookB>; Assert.NotNull(delegateHandler); Assert.Equal(multiCastHookPoint1, delegateHandler.InnerHandler); }
public void hookHandlerChainTest() { var q1 = new HookB("q1Pre", "q1Post"); var q2 = new HookB("q2Pre", "q2Post"); var configuration = new ApiConfiguration() .AddHookHandler <IHookB>(q1) .AddHookHandler <IHookB>(q2); var handler = configuration.GetHookHandler <IHookB>(); Assert.Equal("q2Pre_q1Pre_q1Post_q2Post_", handler.GetStr()); }