public void SetupMocks() { _fixture = new Fixture() .Customize(new AutoMoqCustomization()); _jobQueueFactory = new FakeJobQueueFactory(_fixture); _mockListenerConfiguration = _fixture.Freeze <Mock <ListenerConfiguration> >(); _mockStatusProvider = _fixture.Freeze <Mock <IStatusProvider> >(); _sut = new JobQueueListener(_jobQueueFactory, _mockListenerConfiguration.Object); }
public static Mock <JobHandler> AddMockHandler(this JobQueueListener listener, IFixture fixture) { var mockHandler = fixture.Freeze <Mock <JobHandler> >(); mockHandler.Setup(m => m.CanProcess(It.IsAny <ProcessingRequest>())).Returns(true); mockHandler.SetupGet(p => p.Configuration).Returns(fixture.Create <HandlerConfiguration>()); listener.AddHandler(mockHandler.Object); return(mockHandler); }
public static Fakes.FakeJobHandler AddFakeHandler( this JobQueueListener listener, HandlerConfiguration handlerConfiguration, bool canProcess, bool hangOnProcessing = false, bool throwOnProcessing = false) { var fakeHandler = new Fakes.FakeJobHandler(handlerConfiguration, canProcess, hangOnProcessing, throwOnProcessing); listener.AddHandler(fakeHandler); return(fakeHandler); }
public void ProcessingTimedOut_Raised_On_Hung_Job() { var config = new ListenerConfiguration { JobTimeout = 2000 }; var sut = new JobQueueListener(_jobQueueFactory, config); var mockHandler = sut.AddFakeHandler(_fixture.Create <HandlerConfiguration>(), true, true); var tcs = new TaskCompletionSource <ProcessingFailedEventArgs>(); sut.ProcessingTimedOut += (s, e) => { tcs.SetResult(e); }; _jobQueueFactory.MockMessageQueueFactory.MockQueues[mockHandler.Configuration.QueueId] .Raise(m => m.ReceivedMessage += null, new ReceivedMessageEventArgs(_fixture.Create <IMessage>())); tcs.Task.Wait(); Assert.IsNotNull(tcs.Task.Result); }
public void Contructor_Gaurds_Against_Null_JobQueueFactory() { var sut = new JobQueueListener(null, null); }