public void FirstInsertedHandlerWithSamePrioWinsTest() { var handlerMock1 = new Mock <SyncEventHandler>() { CallBase = true }; handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(true); handlerMock1.Setup(foo => foo.Priority).Returns(1); var handlerMock2 = new Mock <SyncEventHandler>() { CallBase = true }; handlerMock2.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(true); handlerMock2.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock <ISyncEvent>(); var underTest = new SyncEventManager(); underTest.AddEventHandler(handlerMock1.Object); underTest.AddEventHandler(handlerMock2.Object); underTest.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never()); }
public void DeleteWorksCorrectlyTest() { var handlerMock1 = new Mock <SyncEventHandler>(); handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false); handlerMock1.Setup(foo => foo.Priority).Returns(1); var handlerMock2 = new Mock <SyncEventHandler>(); handlerMock2.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false); handlerMock2.Setup(foo => foo.Priority).Returns(1); var handlerMock3 = new Mock <SyncEventHandler>(); handlerMock3.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false); handlerMock3.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock <ISyncEvent>(); SyncEventManager manager = new SyncEventManager(); manager.AddEventHandler(handlerMock1.Object); manager.AddEventHandler(handlerMock2.Object); manager.AddEventHandler(handlerMock3.Object); manager.RemoveEventHandler(handlerMock2.Object); manager.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never()); handlerMock3.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); }
public void BreaksIfHandlerSucceedsTest([Values(true, false)]bool highestFirst) { var handlerMock1 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(true); handlerMock1.Setup(foo => foo.Priority).Returns(2); var handlerMock2 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock2.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock<ISyncEvent>(); var underTest = new SyncEventManager(); if (highestFirst) { underTest.AddEventHandler(handlerMock1.Object); underTest.AddEventHandler(handlerMock2.Object); } else { underTest.AddEventHandler(handlerMock2.Object); underTest.AddEventHandler(handlerMock1.Object); } underTest.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never()); }
public void AddHandlerTest() { var handlerMock = new Mock<SyncEventHandler>(); var mockedEvent = Mock.Of<ISyncEvent>(); var underTest = new SyncEventManager(); underTest.AddEventHandler(handlerMock.Object); underTest.Handle(mockedEvent); handlerMock.Verify(foo => foo.Handle(mockedEvent), Times.Once()); }
public void AddHandlerTest() { var handlerMock = new Mock <SyncEventHandler>(); var eventMock = new Mock <ISyncEvent>(); SyncEventManager manager = new SyncEventManager(); manager.AddEventHandler(handlerMock.Object); manager.Handle(eventMock.Object); handlerMock.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); }
public void AddHandlerTest() { var handlerMock = new Mock <SyncEventHandler>(); var mockedEvent = Mock.Of <ISyncEvent>(); var underTest = new SyncEventManager(); underTest.AddEventHandler(handlerMock.Object); underTest.Handle(mockedEvent); handlerMock.Verify(foo => foo.Handle(mockedEvent), Times.Once()); }
public void ContinueIfHandlerNotSucceedsTest() { var handlerMock1 = new Mock <SyncEventHandler>(); handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false); handlerMock1.Setup(foo => foo.Priority).Returns(2); var handlerMock2 = new Mock <SyncEventHandler>(); handlerMock2.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock <ISyncEvent>(); SyncEventManager manager = new SyncEventManager(); manager.AddEventHandler(handlerMock1.Object); manager.AddEventHandler(handlerMock2.Object); manager.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); }
public void BreaksIfHandlerSucceedsTest([Values(true, false)] bool highestFirst) { var handlerMock1 = new Mock <SyncEventHandler>() { CallBase = true }; handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(true); handlerMock1.Setup(foo => foo.Priority).Returns(2); var handlerMock2 = new Mock <SyncEventHandler>() { CallBase = true }; handlerMock2.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock <ISyncEvent>(); var underTest = new SyncEventManager(); if (highestFirst) { underTest.AddEventHandler(handlerMock1.Object); underTest.AddEventHandler(handlerMock2.Object); } else { underTest.AddEventHandler(handlerMock2.Object); underTest.AddEventHandler(handlerMock1.Object); } underTest.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never()); }
public void ContinueIfHandlerNotSucceedsTest() { var handlerMock1 = new Mock<SyncEventHandler>(); handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false); handlerMock1.Setup(foo => foo.Priority).Returns(2); var handlerMock2 = new Mock<SyncEventHandler>(); handlerMock2.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock<ISyncEvent>(); SyncEventManager manager = new SyncEventManager(); manager.AddEventHandler(handlerMock1.Object); manager.AddEventHandler(handlerMock2.Object); manager.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); }
public void DeleteWorksCorrectlyTest() { var handlerMock1 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false); handlerMock1.Setup(foo => foo.Priority).Returns(1); var handlerMock2 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock2.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false); handlerMock2.Setup(foo => foo.Priority).Returns(1); var handlerMock3 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock3.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false); handlerMock3.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock<ISyncEvent>(); var underTest = new SyncEventManager(); underTest.AddEventHandler(handlerMock1.Object); underTest.AddEventHandler(handlerMock2.Object); underTest.AddEventHandler(handlerMock3.Object); underTest.RemoveEventHandler(handlerMock2.Object); underTest.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never()); handlerMock3.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); }
public void FirstInsertedHandlerWithSamePrioWinsTest() { var handlerMock1 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(true); handlerMock1.Setup(foo => foo.Priority).Returns(1); var handlerMock2 = new Mock<SyncEventHandler>() { CallBase = true }; handlerMock2.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(true); handlerMock2.Setup(foo => foo.Priority).Returns(1); var eventMock = new Mock<ISyncEvent>(); var underTest = new SyncEventManager(); underTest.AddEventHandler(handlerMock1.Object); underTest.AddEventHandler(handlerMock2.Object); underTest.Handle(eventMock.Object); handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once()); handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never()); }