public void ShouldForwardPolymorphicMessage() { var handler = new TestEventHandler(); var message = new TestMessage(); EventFns.Forward(handler, message); Assert.IsTrue(handler.IMessageHandled, "Message should have been handled"); }
public void SubscribeNonGeneric() { var eventHandler = new TestEventHandler(); _messageSystem.Subscribe(_source, typeof(TestEvent),x => eventHandler.HandleEvent((TestEvent)x)); _messageSystem.Publish(_source, new TestEvent()); Assert.IsTrue(eventHandler.EventWasHandled); }
public void EventsWriteExpectedOutput(string report, string labels, string expected) { var handler = new TestEventHandler(_writer, labels); handler.OnTestEvent(report); if (Environment.NewLine != "\r\n") expected = expected.Replace("\r\n", Environment.NewLine); Assert.That(Output, Is.EqualTo(expected)); }
public TestRunner( Config config, TestEventHandler report_event ) { this.config = config; this.report_event = report_event; worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; worker.DoWork += new DoWorkEventHandler( DoWork ); worker.ProgressChanged += new ProgressChangedEventHandler( ProgressChanged ); }
public void EventHandler_SubscribeShouldSubscribeOnTheEventBus() { var eventBus = new Mock<IEventBus>(); var eventHandler = new TestEventHandler(eventBus.Object); eventBus.Setup(x => x.Subscribe(eventHandler)).Verifiable(); eventHandler.Subscribe(); eventBus.Verify(x => x.Subscribe(eventHandler), Times.Once); }
public TestRunFailedCommand(ICommandTarget commandTarget) : base(commandTarget, "&Test", "Run &Failed", _menuPosition, true) { Enabled = ! _testSpec.Empty; _onRecipeLoaded = new RecipeEventHandler(OnRecipeLoaded); _onRecipeClosing = new RecipeEventHandler(OnRecipeClosing); _onTestErrorOrFail = new TestEventHandler(OnTestErrorOrFail); Recipe.Loaded += _onRecipeLoaded; Recipe.Closing += _onRecipeClosing; }
public static void ShutUpCompiler() { // Quiet compiler warnings. EventTest e = new EventTest(); TestEventHandler f = new TestEventHandler(e.GenericHandler); ProtectedStaticEvent += f; InternalStaticEvent += f; PrivateStaticEvent += f; e.ProtectedEvent += f; e.InternalEvent += f; e.PrivateEvent += f; }
public void ShouldCallOnTimeout() { var waitStrategy = new TimeoutBlockingWaitStrategy(TimeSpan.FromMilliseconds(1)); var ringBuffer = new RingBuffer <StubEvent>(() => new StubEvent(-1), new SingleProducerSequencer(16, waitStrategy)); var sequenceBarrier = ringBuffer.NewBarrier(); var onTimeoutSignal = new ManualResetEvent(false); var eventHandler = new TestEventHandler <StubEvent> { OnTimeoutAction = () => onTimeoutSignal.Set() }; var eventProcessor = CreateEventProcessor(ringBuffer, sequenceBarrier, eventHandler); ringBuffer.AddGatingSequences(eventProcessor.Sequence); var task = eventProcessor.Start(); Assert.IsTrue(onTimeoutSignal.WaitOne(TimeSpan.FromSeconds(2))); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }
public void PerformanceTest(bool performanceMode) { int iteration = 1000000; var subscriber = new TestEventHandler(); JEventBus.GetDefault().Register(subscriber); JEventBus.GetDefault().PerformanceMode = performanceMode; var testEvent = new TestEvent(); long time = NanoTime(); for (int i = 0; i < iteration; i++) { JEventBus.GetDefault().Post(testEvent); } long executionTime = NanoTime() - time; Console.WriteLine( $"Execution time: {executionTime / 1000000} ms | {executionTime} ns | {executionTime / iteration} ns/event & performance mode: {performanceMode}"); Assert.AreEqual(iteration, subscriber.EventCounter); }
public async Task HandlingCommandWithNoRegisteredHandlerShouldRunNoMatchingRegistrationHandler() { var busSettings = new BusSettings(); var updater = new OuterPipelineDetector(); var dependencyScope = new TestDependencyScope(); var handler = new TestEventHandler(); var handlerShim = new EventHandlerShim <NoMatchingRegistrationEvent, TestEventHandler>(handler); dependencyScope.AddObject(handlerShim); var busBuilder = new BusBuilder() .RegisterEventHandler <NoMatchingRegistrationEvent, TestEventHandler>(); var pipelineBuilder = new PipelineBuilder(busBuilder); var pipelineRunBuilder = new PipelineRunBuilder(busSettings, pipelineBuilder, updater, dependencyScope); var runner = pipelineRunBuilder.GetRunnerForPipeline(typeof(TestCommand), default(CancellationToken)); await runner.Handle(new TestCommand()); handler.CallsToHandle.Should().Be(1); }
public Task ShutdownDoesNotProcessEnqueuedEvents() { // This test is "weird" in the sense that it relies on a "controlled" race condition. We need to check that // the master does not wait for events to finish processing to complete its shutdown. The way we do this is // force an arbitrary delay when processing events, and then make sure that we haven't processed any after // shutdown. // // * If we do it with a cancellation token on shutdown started, then we have a race condition, because the // token will be triggered, and the item could be processed before shutdown finishes. // * If we do it with a separate lock, we'll need some sort of delay which will be equivalent to what we do // now. // * We can't use a cancellation token on shutdown finished, because shutdown awaits for the action blocks // to complete, and this means we have a deadlock. // // By doing things this way, we are relying on the fact that it is unlikely for a thread to not run for a // second. If we assume that's true, then the slowdown will resume after shutdown has started waiting, and // we will do the appropriate fast-return path. var configuration = new SlowedContentLocationEventStoreConfiguration() { Slowdown = TimeSpan.FromSeconds(1) }; var eventHandler = new TestEventHandler(); return(WithContentLocationEventStore(async(tracingContext, clock, fileSystem, eventStore) => { var context = new OperationContext(tracingContext); var sequencePoint = new EventSequencePoint(clock.UtcNow); eventStore.StartProcessing(context, sequencePoint).ShouldBeSuccess(); eventStore.AddLocations(context, MachineId.FromIndex(0), new[] { new ContentHashWithSize(ContentHash.Random(), 1) }).ShouldBeSuccess(); (await eventStore.ShutdownAsync(context)).ShouldBeSuccess(); eventHandler.EventsHandled.Should().Be(0); }, configuration, eventHandler)); }
public void ShouldCallExceptionHandlerOnMultipleUncaughtException() { var processingSignal = new CountdownEvent(5); var exceptionHandler = new TestExceptionHandler <StubEvent>(x => processingSignal.Signal()); var eventHandler = new TestEventHandler <StubEvent>(x => { if (x.Value == 1) { throw new Exception(); } processingSignal.Signal(); }); var eventProcessor = CreateEventProcessor(_ringBuffer, _sequenceBarrier, eventHandler); _ringBuffer.AddGatingSequences(eventProcessor.Sequence); eventProcessor.SetExceptionHandler(exceptionHandler); var task = eventProcessor.Start(); _ringBuffer.PublishStubEvent(0); _ringBuffer.PublishStubEvent(1); _ringBuffer.PublishStubEvent(0); _ringBuffer.PublishStubEvent(1); _ringBuffer.PublishStubEvent(0); Assert.IsTrue(processingSignal.Wait(TimeSpan.FromSeconds(2))); Assert.AreEqual(2, exceptionHandler.EventExceptionCount); Assert.AreEqual(0, exceptionHandler.TimeoutExceptionCount); Assert.AreEqual(0, exceptionHandler.BatchExceptionCount); eventProcessor.Halt(); Assert.IsTrue(task.Wait(TimeSpan.FromSeconds(2))); }
protected override void InvokeEventHandler(Delegate genericHandler, object genericTarget) { TestEventHandler handler = (TestEventHandler)genericHandler; handler(genericTarget, this); }
public void ShouldBeMessageHandler() { var handler = new TestEventHandler(); Assert.IsTrue(EventFns.IsHandler(handler, typeof(string)), "Should be a message handler"); }
private ConsoleTestRunnerResult RunTests(TestPackage package) { var labels = (_options.DisplayTestLabels ?? LabelsOutputMode.On).ToString().ToUpperInvariant(); XmlNode?result = null; NUnitEngineUnloadException?unloadException = null; NUnitEngineException? engineException = null; try { using (new SaveConsoleOutput()) using (var runner = _engine.GetRunner(package)) { var eventHandler = new TestEventHandler(_outWriter, labels); var testFilter = new TestFilterBuilder().GetFilter(); result = runner.Run(eventHandler, testFilter); } } catch (NUnitEngineUnloadException ex) { unloadException = ex; } catch (NUnitEngineException ex) { engineException = ex; } if (result != null) { var reporter = new ResultReporter(result, _outWriter, _options); reporter.ReportResults(); if (engineException != null) { _outWriter.WriteLine(ColorStyle.Error, Environment.NewLine + ExceptionHelper.BuildMessage(engineException)); return(new ConsoleTestRunnerResult(new UnexpectedError(engineException))); } if (unloadException != null) { _outWriter.WriteLine(ColorStyle.Warning, Environment.NewLine + ExceptionHelper.BuildMessage(unloadException)); } if (reporter.Summary.UnexpectedError) { return(new ConsoleTestRunnerResult(default(UnexpectedError))); } if (reporter.Summary.InvalidAssemblies > 0) { return(new ConsoleTestRunnerResult(default(InvalidAssembly))); } if (reporter.Summary.InvalidTestFixtures > 0) { return(new ConsoleTestRunnerResult(default(InvalidTestFixture))); } var failureCount = reporter.Summary.FailureCount + reporter.Summary.ErrorCount + reporter.Summary.InvalidCount; if (failureCount == 0) { return(new ConsoleTestRunnerResult(new SomeFailures(reporter.Summary))); } return(new ConsoleTestRunnerResult(new AllSuccess(reporter.Summary))); } // If we got here, it's because we had an exception, but check anyway if (engineException != null) { _outWriter.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessage(engineException)); _outWriter.WriteLine(); _outWriter.WriteLine(ColorStyle.Error, ExceptionHelper.BuildMessageAndStackTrace(engineException)); } return(new ConsoleTestRunnerResult(new UnexpectedError(engineException))); }
public void it_should_publish_the_command_to_the_event_handler() { TestEventHandler.ShouldRecieve(myEvent).Should().BeTrue(); }
public void ShouldBePolymorphicMessageHandler() { var handler = new TestEventHandler(); Assert.IsTrue(EventFns.IsHandler(handler, typeof(TestMessage)), "Should be a message handler"); }
protected override void Fire(TestEventHandler handler, TestEventArgs e) { if ( handler != null ) InvokeHandler( handler, e ); }
private void Fire( TestEventHandler handler, TestEventArgs e ) { if ( handler != null ) handler( this, e ); }
public void ShoudForwardMessage() { var handler = new TestEventHandler(); EventFns.Forward(handler, "Hello"); Assert.IsTrue(handler.StringHandled, "Message should have been handled"); }
public void OnEventCall(EventArgs args) { TestEventHandler?.Invoke(this, args); }
public IntegrationTests() { //you could move this code here to the test if you want to use a different instance per test testEventHandler = new TestEventHandler(); RegisterTestEventHandlerInstance(testEventHandler); }
protected void RegisterTestEventHandlerInstance(TestEventHandler testEventHandler) { container.AddSingleton(IIntegrationEventHandler <ProcessCompletedIntegrationEvent>, testEventHandler); }
public void ShouldBeMessageHandler() { var handler = new TestEventHandler(); Assert.IsTrue(EventFns.IsHandler(handler, typeof (string)), "Should be a message handler"); }
protected virtual void Fire( TestEventHandler handler, TestEventArgs e ) { if ( handler != null ) handler( this, e ); }
public void ShouldBePolymorphicMessageHandler() { var handler = new TestEventHandler(); Assert.IsTrue(EventFns.IsHandler(handler, typeof (TestMessage)), "Should be a message handler"); }