public void DoSomething(string text)
        {
            FakeEventHandler tmp = currentHandler;

            if (tmp != null)
            {
                tmp.Invoke(text);
            }
        }
Exemple #2
0
        public void DOSomething()
        {
            FakeEventHandler tmp = currentHandler;

            if (tmp != null)
            {
                tmp.Invoke("This is the reason");
            }
        }
Exemple #3
0
        public void DoSomething(string message)
        {
            FakeEventHandler tmp = currentHandler;

            if (tmp != null)
            {
                tmp.Invoke(message);
            }
        }
            public void CanTolerateTransientExceptions()
            {
                var execution = 0;
                var e = new FakeEvent();
                var eventHandler = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { if (++execution == 1) { throw new ConcurrencyException(); } }, () => new Object());
                var envelope = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler });

                Processor.Process(message);
            }
Exemple #5
0
            public void WillTimeoutEventuallyIfCannotExecuteHandler()
            {
                var e            = new FakeEvent();
                var eventHandler = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { throw new ConcurrencyException(); }, () => new Object());
                var envelope     = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message      = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                SystemTime.ClearOverride();

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler });

                Assert.Throws <TimeoutException>(() => Processor.Process(message));
            }
            public void RetrieveEventHandlersBasedOnEventType()
            {
                var e = new FakeEvent();
                var eventHandler1 = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { }, () => new Object());
                var eventHandler2 = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { }, () => new Object());
                var envelope = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler1, eventHandler2 });

                Processor.Process(message);

                Assert.True(eventHandler1.Handled);
                Assert.True(eventHandler2.Handled);
            }
Exemple #7
0
            public void RetrieveEventHandlersBasedOnEventType()
            {
                var e             = new FakeEvent();
                var eventHandler1 = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { }, () => new Object());
                var eventHandler2 = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { }, () => new Object());
                var envelope      = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message       = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler1, eventHandler2 });

                Processor.Process(message);

                Assert.True(eventHandler1.Handled);
                Assert.True(eventHandler2.Handled);
            }
Exemple #8
0
        public static void injectNewHandler()
        {
            ClientManager clientManager = ClientManager.Obj;

            FakeEventHandler fakeHandler = new FakeEventHandler();

            fakeHandler.registerOldManager(clientManager);

            var field = typeof(NetObject).GetField("eventHandler", BindingFlags.NonPublic | BindingFlags.Static);

            if (field == null)
            {
                Console.WriteLine(prefix + "Can't find the injection field");
            }
            field.SetValue(null, fakeHandler);
        }
Exemple #9
0
            public void CanTolerateTransientExceptions()
            {
                var execution    = 0;
                var e            = new FakeEvent();
                var eventHandler = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { if (++execution == 1)
                                                                                                       {
                                                                                                           throw new ConcurrencyException();
                                                                                                       }
                                                        }, () => new Object());
                var envelope = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message  = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler });

                Processor.Process(message);
            }
        public void Delegate_Can_Invoke_Private_Method()
        {
            FakeEventHandler handler = ReportToConsole;

            var raiser = new FakeEventRaiser();

            raiser.DoSomething("Not subscribed.");

            raiser.AddHandler(handler);
            raiser.DoSomething("Subscribed.");

            raiser.AddHandler(handler);
            raiser.DoSomething("Subscribed twice.");

            raiser.RemoveHandler(handler);
            raiser.RemoveHandler(handler);
            raiser.DoSomething("Unbscribed.");
        }
Exemple #11
0
        public void RaiseEvents()
        {
            FakeEventHandler handler = ReportToConsole;

            FakeEventRaiser raiser = new FakeEventRaiser();

            raiser.DoSomething("Not subscribed!");

            raiser.AddHandler(handler);
            raiser.DoSomething("Subscribed!");

            raiser.AddHandler(handler);
            raiser.DoSomething("Subscribed twice!");

            raiser.RemoveHandler(handler);
            raiser.RemoveHandler(handler);
            raiser.DoSomething("Unsubscribed!");
        }
		public void Should_be_able_to_create_projections()
		{
			var serviceMock = new Mock<IProjectionService>();
			var processor = new EventProcessor(new EventProcessorConfiguration
			{
				ProjectionService = serviceMock.Object,
			});
			var eventProjection = new EventProjection("Test");
			var handler = new FakeEventHandler();

			serviceMock.Setup(m => m.GetEvent(0)).Returns(FakeEvent(new FakeEvent1 {PropertyOne = "value0"}, 0));
			serviceMock.Setup(m => m.GetEvent(1)).Returns(FakeEvent(new FakeEvent1 {PropertyOne = "value1"}, 1));
			serviceMock.Setup(m => m.GetEvent(2)).Returns(FakeEvent(new FakeEvent2 {PropertyTwo = "value2"}, 2));
			serviceMock.Setup(m => m.GetEvent(3)).Returns(FakeEvent(new FakeEvent1 {PropertyOne = "value3"}, 3));
			serviceMock.Setup(m => m.GetEvent(4)).Returns(FakeEvent(new FakeEvent2 {PropertyTwo = "value4"}, 4));
			serviceMock.Setup(m => m.GetEvent(5)).Returns(FakeEvent(new FakeEvent1 {PropertyOne = "[done]"}, 5));
			serviceMock.Setup(m => m.GetEvent(6)).Returns((ProjectionEvent) null);

			var position = new Queue<int>();

			for (var i = 0; i < 6; i++)
			{
				position.Enqueue(i);
			}

			serviceMock.Setup(m => m.GetSequenceNumber("Test")).Returns(() => position.Count > 0 ? position.Dequeue() : 6);

			eventProjection.AddEventHandler(handler);

			processor.AddEventProjection(eventProjection);

			processor.Start();

			while (!handler.HasValue("[done]"))
			{
				Thread.Sleep(250);
			}

			processor.Stop();
		}
Exemple #13
0
 public void RemoveHandler(FakeEventHandler handler)
 {
     currentHandler = currentHandler - handler;
 }
Exemple #14
0
 public void AddHandler(FakeEventHandler handler)
 {
     currentHandler = currentHandler + handler;
 }
Exemple #15
0
 public void RemoveHandler(FakeEventHandler handler)
 {
     currentHandler = currentHandler - handler;
 }
            public void WillTimeoutEventuallyIfCannotExecuteHandler()
            {
                var e = new FakeEvent();
                var eventHandler = new FakeEventHandler(typeof(Object), typeof(FakeEvent), (a, b) => { throw new ConcurrencyException(); }, () => new Object());
                var envelope = new EventEnvelope(GuidStrategy.NewGuid(), GuidStrategy.NewGuid(), new EventVersion(1, 1, 1), e);
                var message = Message.Create(GuidStrategy.NewGuid(), HeaderCollection.Empty, envelope);

                SystemTime.ClearOverride();

                HandlerRegistry.Setup(mock => mock.GetHandlersFor(e)).Returns(new EventHandler[] { eventHandler });

                Assert.Throws<TimeoutException>(() => Processor.Process(message));
            }
Exemple #17
0
 public void AddHandler(FakeEventHandler handler)
 {
     currentHandler = currentHandler + handler;
 }