public static void Test_Chain_Handler_Calls_Handle_Methods_On_Handlers_Multiple() { //arrange var chain = new ChainMessageHandlerStrategy<INetPeer, INetworkMessage>(); Mock<IMessageHandler<INetPeer, INetworkMessage>> handler1 = new Mock<IMessageHandler<INetPeer, INetworkMessage>>(); handler1.Setup(x => x.TryProcessMessage(It.IsAny<INetworkMessage>(), It.IsAny<IMessageParameters>(), It.IsAny<INetPeer>())) .Returns(false); Mock<IMessageHandler<INetPeer, INetworkMessage>> handler2 = new Mock<IMessageHandler<INetPeer, INetworkMessage>>(); handler2.Setup(x => x.TryProcessMessage(It.IsAny<INetworkMessage>(), It.IsAny<IMessageParameters>(), It.IsAny<INetPeer>())) .Returns(false); //act bool result = chain.Register(handler1.Object); Assert.IsTrue(result, "Couldn't add a handler to the chain."); result = chain.Register(handler2.Object); Assert.IsTrue(result, "Couldn't add a handler to the chain."); chain.TryProcessMessage(Mock.Of<INetworkMessage>(), Mock.Of<IMessageParameters>(), Mock.Of<INetPeer>()); //assert handler1.Verify(x => x.TryProcessMessage(It.IsAny<INetworkMessage>(), It.IsAny<IMessageParameters>(), It.IsAny<INetPeer>()), Times.Once()); handler2.Verify(x => x.TryProcessMessage(It.IsAny<INetworkMessage>(), It.IsAny<IMessageParameters>(), It.IsAny<INetPeer>()), Times.Once()); }
public override void Register(IServiceRegister register) { //Chain handling semantics are preferable on the client. //No reason multiple handlers should be consuming the same packets, complications things //Put it infront of the handling process if you want that functionality ChainMessageHandlerStrategy <InstanceClientSession, IRequestMessage> chainHandler = new ChainMessageHandlerStrategy <InstanceClientSession, IRequestMessage>(FindHandlersInScene()); //generics are semi-limited in .Net when trying to construct an instance of the type so we put the requirement for inheritors to create the instance. register.Register <RequestMessageHandlerService <InstanceClientSession> >(new RequestMessageHandlerService <InstanceClientSession>(chainHandler), getFlags(), typeof(IRequestMessageHandlerService <InstanceClientSession>)); }
public override void Register(IServiceRegister register) { //Chain handling semantics are preferable on the client. //No reason multiple handlers should be consuming the same packets, complications things //Put it infront of the handling process if you want that functionality ChainMessageHandlerStrategy<TPeerType, TNetworkMessageType> chainHandler = new ChainMessageHandlerStrategy<TPeerType, TNetworkMessageType>(FindHandlersInScene()); //generics are semi-limited in .Net when trying to construct an instance of the type so we put the requirement for inheritors to create the instance. register.Register<THandlerServiceTypeConcrete>(CreateConcreteService(chainHandler), ComputeFlags(), typeof(THandlerServiceTypeServiceInterface)); }
public static void Test_Can_Add_New_Handler() { //arrange var chain = new ChainMessageHandlerStrategy<INetPeer, INetworkMessage>(); Mock<IMessageHandler<INetPeer, INetworkMessage>> handler = new Mock<IMessageHandler<INetPeer, INetworkMessage>>(); //act bool result = chain.Register(handler.Object); //assert Assert.IsTrue(result, "Couldn't add a handler to the chain."); }
public static void Test_Indicates_Add_Failure_On_Null() { //arrange var chain = new ChainMessageHandlerStrategy<INetPeer, INetworkMessage>(); //act bool result = chain.Register(null); //assert Assert.IsFalse(result, "Was able to add a null handler."); }