public void TriggerEvent1()
 {
     if (Event1 != null)
     {
         Event1.Invoke(this, new Event1Args($"Total subscribers: ${Event1.GetInvocationList().Length}"));
     }
 }
예제 #2
0
        public void WHEN_throws_THEN_retries()
        {
            var handler = new TestableBuggyEventHandler();

            this.processor.Register(handler);

            // Registering also a generic handler
            var genericHandler = new Mock <IEventHandler>();

            genericHandler.As <IEventHandler <IEvent> >();

            this.processor.Register(genericHandler.Object);

            this.processor.Start();

            var event1 = new Event1 {
                SourceId = Guid.NewGuid()
            };
            var event2 = new Event2 {
                SourceId = Guid.NewGuid()
            };

            this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new MessageForDelivery(Serialize(event1))));
            Assert.Throws(new AggregateException().GetType(), () => this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new MessageForDelivery(Serialize(event2)))));
        }
예제 #3
0
        public async Task sut_supports_multiple_state_types_having_same_stream_id(
            IMessageBus eventBus, Guid streamId, Event1 evt1, Event2 evt2)
        {
            // Arrange
            EntityEventStore <State1> store1 = GenerateEventStore <State1>(eventBus);
            EntityEventStore <State2> store2 = GenerateEventStore <State2>(eventBus);

            int startVersion = 1;

            // Act
            Func <Task> action = async() =>
            {
                await store1.CollectEvents(streamId, startVersion, new[] { evt1 });

                await store2.CollectEvents(streamId, startVersion, new[] { evt2 });
            };

            // Assert
            await action.Should().NotThrowAsync();

            IEnumerable <object> actual1 = await store1.QueryEvents(streamId, fromVersion : 1);

            actual1.Should().BeEquivalentTo(evt1);

            IEnumerable <object> actual2 = await store2.QueryEvents(streamId, fromVersion : 1);

            actual2.Should().BeEquivalentTo(evt2);
        }
예제 #4
0
        public void when_receives_message_then_notifies_registered_handler()
        {
            var handlerAMock = new Mock <IEventHandler>();

            handlerAMock.As <IEventHandler <Event1> >();
            handlerAMock.As <IEventHandler <Event2> >();

            var handlerBMock = new Mock <IEventHandler>();

            handlerBMock.As <IEventHandler <Event2> >();

            processor.Register(handlerAMock.Object);
            processor.Register(handlerBMock.Object);

            processor.Start();

            var event1 = new Event1 {
                SourceId = Guid.NewGuid()
            };
            var event2 = new Event2 {
                SourceId = Guid.NewGuid()
            };

            receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(event1))));
            receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(event2))));

            handlerAMock.As <IEventHandler <Event1> >().Verify(h => h.Handle(It.Is <Event1>(e => e.SourceId == event1.SourceId)));
            handlerAMock.As <IEventHandler <Event2> >().Verify(h => h.Handle(It.Is <Event2>(e => e.SourceId == event2.SourceId)));
            handlerBMock.As <IEventHandler <Event2> >().Verify(h => h.Handle(It.Is <Event2>(e => e.SourceId == event2.SourceId)));
        }
예제 #5
0
        public async Task DispatcherShouldRegisterPipelineForMultipleEventsAsync()
        {
            var actWrapper = ActWrapper <Event> .From(nopAct);

            var eventTypes = new List <Type> {
                typeof(Event1), typeof(Event2)
            };
            var acts = new ActList {
                actWrapper.Act
            };

            dispatcher.RegisterPipeline(eventTypes, acts);

            Event1 event1 = new Event1 {
                Property = "event1"
            };

            dispatcher.Dispatch(event1);
            await actWrapper.ActTask;

            (actWrapper.Event as Event1).Property.ShouldBeEquivalentTo(event1.Property);

            actWrapper.Rearm();
            Event2 event2 = new Event2 {
                Property = "event2"
            };

            dispatcher.Dispatch(event2);
            await actWrapper.ActTask;

            (actWrapper.Event as Event2).Property.ShouldBeEquivalentTo(event2.Property);
        }
예제 #6
0
 public Task <Event1> DoSomething(Event1 input)
 {
     return(Task.FromResult(new Event1()
     {
         Quantity = 100
     }));
 }
예제 #7
0
        public async Task CreateMessageAsync_CreatesCorrectMessageType()
        {
            IEvent             @event  = new Event1();
            IEventMessageDraft message = await sut.CreateMessageAsync(@event);

            message.Should().BeOfType <EventMessageDraft <Event1> >();
            message.Event.Should().Be(@event);
        }
        public void SafeInvoke_WhenNullArgs()
        {
            bool invoked = false;

            Event1 += (sender, args) => invoked = true;
            Event1.SafeInvoke(null, null);
            invoked.Should().BeTrue();
        }
예제 #9
0
 public void DisallowUnpersistEventWithSets()
 {
     Session.BeginUpdate();
     Event1 = QueryHelper.Read <Event>(Event1SimpleKey, Location1, Session);
     Assert.Throws <ConstraintException>(() =>
                                         Event1.Unpersist(Session));
     Session.Commit();
 }
        public void SafeInvoke_WhenExplicitArgs()
        {
            bool invoked = false;

            Event1 += (sender, args) => invoked = true;
            Event1.SafeInvoke(this, new EventArgs());
            invoked.Should().BeTrue();
        }
예제 #11
0
        public void HandleEvent_InvokesHandle()
        {
            var sut    = Substitute.ForPartsOf <Saga1>(Guid.NewGuid());
            var event1 = new Event1().ToMessageDraft();

            sut.HandleEvent(event1);

            sut.Received(1).Handle(event1);
        }
예제 #12
0
        public void PushEvent_AddsToEvents()
        {
            var ev1 = new Event1().ToMessageDraft();

            sut.PushEvent(ev1);

            sut.Events.Should().HaveCount(1);
            sut.Events.Should().Contain(ev1);
        }
예제 #13
0
        public void RaiseEvents()
        {
            Event1.Invoke();

            // have difference of 20 ms between both events
            Thread.Sleep(20);

            Event2.Invoke();
        }
예제 #14
0
 public static void Registe(string key, Event1 e)
 {
     if (m_Event1.ContainsKey(key))
     {
         m_Event1[key] += e;
     }
     else
     {
         m_Event1.Add(key, e);
     }
 }
예제 #15
0
        public void ReplayEvents_ExecutesHandlers()
        {
            List <DomainAggregateEvent> events = new List <DomainAggregateEvent>();

            var ev1 = new Event1();

            sut.Register <Event1>(ev => events.Add(ev));
            sut.Publish(ev1);

            Assert.Equal(events[0], ev1);
        }
        public void Show()
        {
            var sut    = new HasRoutesDiscoveredByConvention();
            var event1 = new Event1();
            var event2 = new Event2();

            sut.InvokeApply(event1);
            sut.InvokeApply(event2);
            Assert.Equal(event1, sut.RouteForEvent1.Captured);
            Assert.Equal(event2, sut.RouteForEvent2.Captured);
        }
예제 #17
0
    // Start is called before the first frame update
    void Start()
    {
        //subscribe
        GameObject go     = GameObject.Find("Event1");//gameobject with attached script
        Event1     event1 = go.GetComponent <Event1>();

        Event1.onSpacePressedSecond += localFunctionSecond;
        event1.onSpacePressed       += localFunction;

        //event1.onSpacePressedSecond += localFunctionSecond;
    }
예제 #18
0
        public void Publish_PushesEventToUncomittedEvents()
        {
            var ev1 = new Event1();
            var ev2 = new Event2();

            sut.Publish(ev1);
            sut.Publish(ev2);

            Assert.Equal(2, sut.UncommitedEvents.Count());
            Assert.Equal(ev1, sut.UncommitedEvents.ElementAt(0));
            Assert.Equal(ev2, sut.UncommitedEvents.ElementAt(1));
        }
예제 #19
0
파일: EventTest.cs 프로젝트: kkomler/Test-1
    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 150, 50), "send eve1"))
        {
            Event1 eve = new Event1(1, 2, "123");
            eve.Send();
        }

        if (GUI.Button(new Rect(10, 70, 150, 50), "send eve2"))
        {
            EventData.CreateEvent(EventID.EVENT_2).Send();
        }
    }
예제 #20
0
            public void CommittingAtPreviewObservationStageThrows()
            {
                var event1 = new Event1
                {
                    ShouldCommit             = true,
                    CommitAtStage            = ObservationStage.Preview,
                    CommitAtEventProcesserId = EventProcessor1Id,
                };

                _router.PublishEvent(_model1.Id, event1);
                _terminalErrorHandler.Errors.Count.ShouldBe(1);
                _terminalErrorHandler.Errors[0].ShouldBeOfType <InvalidOperationException>();
            }
예제 #21
0
        public void Apply_FiresAllHandlers()
        {
            List <DomainAggregateEvent> events1 = new List <DomainAggregateEvent>();
            List <DomainAggregateEvent> events2 = new List <DomainAggregateEvent>();

            var ev1 = new Event1();

            sut.Register <Event1>(ev => events1.Add(ev));
            sut.Register <Event1>(ev => events2.Add(ev));
            sut.Publish(ev1);

            Assert.Equal(events1[0], ev1);
            Assert.Equal(events2[0], ev1);
        }
예제 #22
0
            public void RemovalAtPreviewStageEndsEventWorkflow()
            {
                var event1 = new Event1
                {
                    ShouldRemove             = true,
                    RemoveAtStage            = ObservationStage.Preview,
                    RemoveAtEventProcesserId = EventProcessor1Id,
                };

                _router.PublishEvent(_model1.Id, event1);
                _model1EventProcessor.Event1Details.PreviewStage.ReceivedEvents.Count.ShouldBe(1);
                _model1EventProcessor.Event1Details.NormalStage.ReceivedEvents.Count.ShouldBe(0);
                _model1Controller.ReceivedModels.Count.ShouldBe(0);
            }
예제 #23
0
 public Trigger Clone()
 {
     return(new Trigger()
     {
         Name = Name,
         PersistantType = PersistantType,
         House = House,
         EventControl = EventControl,
         Event1 = Event1.Clone(),
         Event2 = Event2.Clone(),
         Action1 = Action1.Clone(),
         Action2 = Action2.Clone()
     });
 }
예제 #24
0
        public void Should_not_get_events_not_subscribed_to()
        {
            Event1 capturedEvent = null;

            eventBus.Subscribe <Event1>(@event => capturedEvent = @event);

            var publishedEvent = new Event2
            {
                Text = "Hello World"
            };

            eventBus.Publish(publishedEvent);

            capturedEvent.ShouldBeNull();
        }
예제 #25
0
파일: EventTest.cs 프로젝트: kkomler/Test-1
    public void HandleEvent(EventData data)
    {
        switch (data.eid)
        {
        case EventID.EVENT_1:
            Event1 eve = data as Event1;
            Debug.Log("receive event_1 msg!");
            Debug.Log(string.Format("t1:{0},t2:{1},s1:{2}", eve.t1, eve.t2, eve.s1));
            break;

        case EventID.EVENT_2:
            Debug.Log("receive event_2 msg!");
            break;
        }
    }
        public void RegisterEvents_RegistersAllHandlers()
        {
            var sut = new ConventionEventApplyRegistrator();

            var entity    = new MyEntity();
            var aggregate = Substitute.For <IAggregateRoot>();
            var router    = new AggregateEventRouter(aggregate);

            sut.RegisterEvents(entity, router);
            var ev1 = new Event1();

            router.Publish(ev1);

            Assert.Equal(ev1, entity.Events[0]);
        }
예제 #27
0
        public void ShouldNotGetEventsNotSubscribedTo()
        {
            Event1 capturedEvent = null;

            eventBus.Subscribe <Event1>(@event => capturedEvent = @event);

            var publishedEvent = new Event2
            {
                Text = "Hello World"
            };

            eventBus.Publish(publishedEvent);

            capturedEvent.Should().BeNull();
        }
예제 #28
0
        public async Task FlushAsync_PublishesEvents()
        {
            var ev1 = new Event1().ToMessageDraft();
            var ev2 = new Event1().ToMessageDraft();

            sut.PushEvent(ev1);
            sut.PushEvent(ev2);

            await sut.FlushAsync(CancellationToken.None);

            eventBus.Received(1).PublishAsync(ev1);
            eventBus.Received(1).PublishAsync(ev2);

            sut.Events.Should().HaveCount(0);
        }
예제 #29
0
        public void Should_be_able_to_get_subscribed_to_events()
        {
            Event1 capturedEvent = null;

            eventBus.Subscribe <Event1>(@event => capturedEvent = @event);

            var publishedEvent = new Event1
            {
                Text = "Hello World"
            };

            eventBus.Publish(publishedEvent);

            capturedEvent.ShouldNotBeNull();
            capturedEvent.ShouldBeTheSameAs(publishedEvent);
        }
예제 #30
0
        public void Should_be_able_to_get_subscribed_to_events()
        {
            Event1 capturedEvent = null;

            eventBus.Subscribe<Event1>(@event => capturedEvent = @event);

            var publishedEvent = new Event1
                {
                    Text = "Hello World"
                };

            eventBus.Publish(publishedEvent);

            capturedEvent.ShouldNotBeNull();
            capturedEvent.ShouldBeTheSameAs(publishedEvent);
        }
예제 #31
0
        public void TestMultiCodec()
        {
            MultiCodec <BaseEvent> codec = new MultiCodec <BaseEvent>();

            codec.Register(new Event1Codec());
            codec.Register(new Event2Codec());

            byte[] d1Data = codec.Encode(new Event1(42));
            byte[] d2Data = codec.Encode(new Event2("Tony"));

            Event1 e1 = (Event1)codec.Decode(d1Data);
            Event2 e2 = (Event2)codec.Decode(d2Data);

            Assert.Equal(42, e1.Number);
            Assert.Equal("Tony", e2.Name);
        }
예제 #32
0
        public void when_receives_message_then_notifies_generic_handler()
        {
            var handler = new Mock<IEventHandler>();
            handler.As<IEventHandler<IEvent>>();

            this.processor.Register(handler.Object);

            this.processor.Start();

            var event1 = new Event1 { SourceId = Guid.NewGuid() };
            var event2 = new Event2 { SourceId = Guid.NewGuid() };

            this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(event1))));
            this.receiverMock.Raise(r => r.MessageReceived += null, new MessageReceivedEventArgs(new Message(Serialize(event2))));

            handler.As<IEventHandler<IEvent>>().Verify(h => h.Handle(It.Is<Event1>(e => e.SourceId == event1.SourceId)));
            handler.As<IEventHandler<IEvent>>().Verify(h => h.Handle(It.Is<Event2>(e => e.SourceId == event2.SourceId)));
        }
예제 #33
0
        public void Should_handle_resubscription_from_handler()
        {
            Event1 eventFromSubscription = null;

            eventBus.Subscribe<Event1>(@event =>
                {
                    eventFromSubscription = @event;
                    eventBus.Subscribe<Event1>(x => { });
                });

            var publishedEvent1 = new Event1
            {
                Text = "Hello World"
            };

            eventBus.Publish(publishedEvent1);

            eventFromSubscription.ShouldNotBeNull();
        }
        public void ShouldPublishEventSynchronouslyFromMethodParam()
        {
            eventBus.IsAsynchronous.ShouldBe(true);

            Event1 firedArgs = null;
            Action<Event1> handler = e => { firedArgs = e; };
            eventBus.Subscribe(handler);

            // ---

            var publishArgs = new Event1 { Message = "My Message" };
            eventBus.Publish(publishArgs, isAsynchronous: false);

            firedArgs.ShouldBe(publishArgs);
            eventBus.PublishedCount<Event1>().ShouldBe(1L);
            eventBus.IsAsynchronous.ShouldBe(true);
        }
        public void ShouldPublishEventAsynchronouslyFromMethodParam()
        {
            eventBus.IsAsynchronous = false;
            AsyncTest.Start(test =>
                                {
                                    var publishArgs = new Event1 { Message = "My Message" };
                                    var fired = false;
                                    Action<Event1> handler = e =>
                                                    {
                                                        fired = true;
                                                        e.ShouldBe(publishArgs);
                                                        test.Complete();
                                                    };

                                    eventBus.Subscribe(handler);
                                    eventBus.Publish(publishArgs, isAsynchronous:true);
                                    fired.ShouldBe(false);
                                });
        }
 public void OnFire(Event1 e)
 {
     FireCount++;
 }
예제 #37
0
 public bool Handle(Event1 x)
 {
     return true;
 }
 private void OnFire(Event1 e)
 {
     fireCount++;
 }
예제 #39
0
        public void Should_handle_cancelation_from_handler()
        {
            Event1 eventFromSubscription = null;

            CancelSubscription cancelEvent = null;

            cancelEvent = eventBus.Subscribe<Event1>(@event =>
            {
                cancelEvent();
                eventFromSubscription = @event;
            });

            var publishedEvent1 = new Event1
            {
                Text = "Hello World"
            };

            eventBus.Publish(publishedEvent1);

            eventFromSubscription.ShouldNotBeNull();
        }