public void CheckSubscribeThenPublishFromAnotherThreadShouldReceiveEvent() { // Arrange var eventAggregator = new EventAggregator(); var source = new EventSource(eventAggregator); var receiver = new EventReceiver(eventAggregator); var data = EventData.Random(); // Act var unsubscriber = receiver.Subscribe(); Task.Run(() => { source.Emit(data); }); receiver.Wait(); // Assert Assert.True(receiver.EventReceived); Assert.Equal(data, receiver.Data); Assert.Equal(data.TestGuid, receiver.Data.TestGuid); Assert.Equal(data.TestInteger, receiver.Data.TestInteger); Assert.Equal(data.TestStr, receiver.Data.TestStr); // Cleanup unsubscriber.Dispose(); eventAggregator.Dispose(); receiver.Dispose(); }
public void CheckSubscribeThenUnsubscribeShouldNotReceivedEvent() { // Arrange var eventAggregator = new EventAggregator(); var source = new EventSource(eventAggregator); var receiver = new EventReceiver(eventAggregator); var data = EventData.Random(); // Act var unsubscriber = receiver.Subscribe(); unsubscriber.Dispose(); source.Emit(data); receiver.Wait(); // Assert Assert.False(receiver.EventReceived); Assert.Null(receiver.Data); // Cleanup eventAggregator.Dispose(); receiver.Dispose(); }
private void UpdateProjectionTrafo() { var l = m_box.Min.X; var r = m_box.Max.X; var b = m_box.Min.Y; var t = m_box.Max.Y; var n = m_box.Min.Z; var f = m_box.Max.Z; m_trafo = Trafo3d.PerspectiveProjectionRH(l, r, b, t, n, f); m_trafoChanges.Emit(m_trafo); }
public void CheckSubscribeWithExceptionInHandlerShouldNotRaiseException() { // Arrange var eventAggregator = new EventAggregator(); var source = new EventSource(eventAggregator); var receiver = new EventReceiver(eventAggregator, () => throw new Exception("Test")); var data = EventData.Random(); // Act var unsubscriber = receiver.Subscribe(); source.Emit(data); // Cleanup unsubscriber.Dispose(); eventAggregator.Dispose(); receiver.Dispose(); }
public void CheckTwoSubscribersShouldReceiveSameEvent() { // Arrange var eventAggregator = new EventAggregator(); var source = new EventSource(eventAggregator); var firstReceiver = new EventReceiver(eventAggregator); var secondReceiver = new EventReceiver(eventAggregator); var data = EventData.Random(); // Act var firstUnsubscriber = firstReceiver.Subscribe(); var secondUnsubscriber = secondReceiver.Subscribe(); source.Emit(data); firstReceiver.Wait(); secondReceiver.Wait(); // Assert Assert.True(firstReceiver.EventReceived); Assert.Equal(data, firstReceiver.Data); Assert.Equal(data.TestGuid, firstReceiver.Data.TestGuid); Assert.Equal(data.TestInteger, firstReceiver.Data.TestInteger); Assert.Equal(data.TestStr, firstReceiver.Data.TestStr); Assert.True(secondReceiver.EventReceived); Assert.Equal(data, secondReceiver.Data); Assert.Equal(data.TestGuid, secondReceiver.Data.TestGuid); Assert.Equal(data.TestInteger, secondReceiver.Data.TestInteger); Assert.Equal(data.TestStr, secondReceiver.Data.TestStr); // Cleanup firstUnsubscriber.Dispose(); secondUnsubscriber.Dispose(); eventAggregator.Dispose(); firstReceiver.Dispose(); secondReceiver.Dispose(); }
/// <summary> /// Sets location and axes in a single transaction. /// </summary> public void Set(V3d location, V3d right, V3d up, V3d forward) { m_trafo = Trafo3d.ViewTrafo(location, right, up, -forward); m_trafoChanges.Emit(m_trafo); }
public void CheckLongRunningHandlerShouldNotBlockOtherHandler() { // Arrange var timerElapsed = new ManualResetEventSlim(false); var timer = new Timer( _ => { timerElapsed.Set(); }, null, 1000, 0); var eventAggregator = new EventAggregator(); var source = new EventSource(eventAggregator); var firstReceiver = new EventReceiver(eventAggregator, () => { timerElapsed.Wait(); }); var secondReceiver = new EventReceiver(eventAggregator); var data = EventData.Random(); // Act var firstUnsubscriber = firstReceiver.Subscribe(); var secondUnsubscriber = secondReceiver.Subscribe(); source.Emit(data); firstReceiver.Wait(); secondReceiver.Wait(); // Assert Assert.False(firstReceiver.EventReceived); Assert.True(secondReceiver.EventReceived); Assert.Null(firstReceiver.Data); Assert.Equal(data, secondReceiver.Data); Assert.Equal(data.TestGuid, secondReceiver.Data.TestGuid); Assert.Equal(data.TestInteger, secondReceiver.Data.TestInteger); Assert.Equal(data.TestStr, secondReceiver.Data.TestStr); firstReceiver.Wait(1000); Assert.True(firstReceiver.EventReceived); Assert.Equal(data, firstReceiver.Data); Assert.Equal(data.TestGuid, firstReceiver.Data.TestGuid); Assert.Equal(data.TestInteger, firstReceiver.Data.TestInteger); Assert.Equal(data.TestStr, firstReceiver.Data.TestStr); // Cleanup firstUnsubscriber.Dispose(); secondUnsubscriber.Dispose(); eventAggregator.Dispose(); firstReceiver.Dispose(); secondReceiver.Dispose(); timer.Dispose(); timerElapsed.Dispose(); }