public void TriggerEvent1() { if (Event1 != null) { Event1.Invoke(this, new Event1Args($"Total subscribers: ${Event1.GetInvocationList().Length}")); } }
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))))); }
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); }
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))); }
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); }
public Task <Event1> DoSomething(Event1 input) { return(Task.FromResult(new Event1() { Quantity = 100 })); }
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(); }
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(); }
public void HandleEvent_InvokesHandle() { var sut = Substitute.ForPartsOf <Saga1>(Guid.NewGuid()); var event1 = new Event1().ToMessageDraft(); sut.HandleEvent(event1); sut.Received(1).Handle(event1); }
public void PushEvent_AddsToEvents() { var ev1 = new Event1().ToMessageDraft(); sut.PushEvent(ev1); sut.Events.Should().HaveCount(1); sut.Events.Should().Contain(ev1); }
public void RaiseEvents() { Event1.Invoke(); // have difference of 20 ms between both events Thread.Sleep(20); Event2.Invoke(); }
public static void Registe(string key, Event1 e) { if (m_Event1.ContainsKey(key)) { m_Event1[key] += e; } else { m_Event1.Add(key, e); } }
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); }
// 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; }
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)); }
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(); } }
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>(); }
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); }
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); }
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() }); }
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(); }
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]); }
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(); }
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); }
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); }
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); }
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); }
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))); }
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++; }
public bool Handle(Event1 x) { return true; }
private void OnFire(Event1 e) { fireCount++; }
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(); }