public void Handler_UseFallback_Test() { Byt3Handler handler = GetHandler(Byt3HandlerLookupType.UseFallback, null); //handler.AddHandler(new HandlerA()); //handler.AddHandler(new HandlerB()); //handler.AddHandler(new HandlerC()); //handler.AddHandler(new HandlerD()); handler.Handle(new A(), null); //Works because of fallback handler.Handle(new B(), null); //Works because of fallback handler.Handle(new C_B(), null); //Works because of fallback handler.Handle(new D_C(), null); //Works because of fallback Assert.False(ACalled && BCalled && CCalled && DCalled); }
public void Handler_TraverseUp_Test() { Byt3Handler handler = GetHandler(Byt3HandlerLookupType.TraverseUp, null); handler.AddHandler(new HandlerA { TestInstance = this }); handler.AddHandler(new HandlerB { TestInstance = this }); //handler.AddHandler(new HandlerC()); //handler.AddHandler(new HandlerD()); handler.Handle(new A(), null); //Works handler.Handle(new B(), null); //Works handler.Handle(new C_B(), null); //Works because traverse up handler.Handle(new D_C(), null); //Works because traverse up Assert.True(ACalled && BCalled); Assert.False(CCalled && DCalled); }
public void Handler_ExactOnly_Test() { Byt3Handler handler = GetHandler(Byt3HandlerLookupType.None, null); //handler.AddHandler(new HandlerA()); handler.AddHandler(new HandlerB { TestInstance = this }); handler.AddHandler(new HandlerC { TestInstance = this }); //handler.AddHandler(new HandlerD()); Assert.Throws <HandlerNotFoundException>(() => handler.Handle(new A(), null)); //Crash because of Exact only and A is missing handler.Handle(new B(), null); //Works handler.Handle(new C_B(), null); //Works Assert.Throws <HandlerNotFoundException>(() => handler.Handle(new D_C(), null)); //Crash because no traversal up Assert.True(BCalled && CCalled); Assert.False(ACalled && DCalled); }