本文整理汇总了C#中EventAggregator.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# EventAggregator.Publish方法的具体用法?C# EventAggregator.Publish怎么用?C# EventAggregator.Publish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventAggregator
的用法示例。
在下文中一共展示了EventAggregator.Publish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObserverShouldOnlyReceiveSubscribedNotifications
public void ObserverShouldOnlyReceiveSubscribedNotifications()
{
// Arrange
var eventAggregator = new EventAggregator();
var observer1 = new Mock<IObserve<TestEvent>>();
var observer2 = new Mock<IObserve<OtherEvent>>();
eventAggregator.Subscribe(observer1.Object);
eventAggregator.Subscribe(observer2.Object);
var testEvent = new TestEvent();
var otherEvent = new OtherEvent();
// Act
eventAggregator.Publish(testEvent);
eventAggregator.Publish(otherEvent);
// Assert
observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Once);
observer1.Verify(x => x.OnNext(testEvent), Times.Once);
observer2.Verify(x => x.OnNext(otherEvent), Times.Once);
}
示例2: Context
public void Context()
{
_session = MockRepository.GenerateMock<ISession>();
_session.Stub(x => x.Save(Arg<object>.Is.NotNull))
.WhenCalled(x => _saved.Add(x.Arguments.First()));
var container = IoC.Container;
container.Configure(x => x.For<ISession>().Use(_session));
var eventAggregator = new EventAggregator(container);
eventAggregator.Publish(new SubscriptionCreated());
}
示例3: SubscriberShouldReceiveMessage_WhenMessagePublished
public void SubscriberShouldReceiveMessage_WhenMessagePublished()
{
var mock = new Mock<ISubscriber<Message1>>();
var eventAggregator = new EventAggregator();
eventAggregator.Subscribe(mock.Object);
var msg = new Message1();
eventAggregator.Publish(msg);
mock.Verify(s => s.Handle(msg));
}
示例4: SubscriberShouldNotReceiveMessageWhichItIsNotSubscribedTo
public void SubscriberShouldNotReceiveMessageWhichItIsNotSubscribedTo()
{
var mock = new Mock<ISubscriber<Message1>>();
var eventAggregator = new EventAggregator();
eventAggregator.Subscribe(mock.Object);
var msg = new Message2();
eventAggregator.Publish(msg);
mock.Verify(s => s.Handle(It.IsAny<Message1>()), Times.Never());
}
示例5: Subscribe_WhenGivenEvent_ShouldRaiseEvent
public void Subscribe_WhenGivenEvent_ShouldRaiseEvent()
{
var eventWasRaised = false;
var eventBus = new EventAggregator();
eventBus.GetEvent<TestEvent>().Subscribe(new Observer<TestEvent>(x => eventWasRaised = true));
eventBus.Publish(new TestEvent());
Assert.IsTrue(eventWasRaised);
}
示例6: Unsubscribe_WhenGivenEvent_ShouldNotRaiseEvent
public void Unsubscribe_WhenGivenEvent_ShouldNotRaiseEvent()
{
var eventWasRaised = false;
var eventBus = new EventAggregator();
var subscription = eventBus.GetEvent<TestEvent>().Subscribe(new Observer<TestEvent>(x => eventWasRaised = true));
subscription.Dispose();
eventBus.Publish(new TestEvent());
Assert.IsFalse(eventWasRaised);
}
示例7: ObserverStopsReceivingEventsWhenUnsubscribed
public void ObserverStopsReceivingEventsWhenUnsubscribed()
{
// Arrange
var eventAggregator = new EventAggregator();
var observer1 = new Mock<IObserve<TestEvent>>();
var unsubscribe = eventAggregator.Subscribe(observer1.Object);
var testEvent1 = new TestEvent();
var testEvent2 = new TestEvent();
// Act
eventAggregator.Publish(testEvent1);
unsubscribe.Dispose();
eventAggregator.Publish(testEvent2);
// Assert
observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Once);
observer1.Verify(x => x.OnNext(testEvent1), Times.Once);
observer1.Verify(x => x.OnNext(testEvent2), Times.Never);
}
示例8: BaseObserverReceivesAllEvents
public void BaseObserverReceivesAllEvents()
{
// Arrange
var eventAggregator = new EventAggregator();
var observer1 = new Mock<IObserve<IEvent>>();
var observer2 = new Mock<IObserver<IEvent>>();
eventAggregator.Subscribe(observer1.Object);
eventAggregator.Subscribe(observer2.Object);
var testEvent = new TestEvent();
var otherEvent = new OtherEvent();
// Act
eventAggregator.Publish(testEvent);
eventAggregator.Publish(otherEvent);
// Assert
observer1.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Exactly(2));
observer2.Verify(x => x.OnNext(It.IsAny<IEvent>()), Times.Exactly(2));
}
示例9: testing_subscribe
public void testing_subscribe()
{
// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();
// act
eventPublisher.GetEvent<SampleEvent>()
.Subscribe(se => eventWasRaised = true);
eventPublisher.Publish(new SampleEvent());
// assert
eventWasRaised.ShouldBe(true);
}
示例10: A_valid_message_is_published_to_all_handlers
public void A_valid_message_is_published_to_all_handlers() {
var eventAggregator = new EventAggregator();
var handlerMockA = new Mock<IHandle<object>>();
var handlerMockB = new Mock<IHandle<object>>();
eventAggregator.Subscribe(handlerMockA.Object);
eventAggregator.Subscribe(handlerMockB.Object);
eventAggregator.Publish(new object());
handlerMockA.Verify(handlerStub => handlerStub.Handle(It.IsAny<object>()),
Times.AtLeastOnce());
handlerMockB.Verify(handlerStub => handlerStub.Handle(It.IsAny<object>()),
Times.AtLeastOnce());
}
示例11: testing_selective_subscribe_ignored
public void testing_selective_subscribe_ignored()
{
// arrange
var eventWasRaised = false;
var eventPublisher = new EventAggregator();
// act
eventPublisher.GetEvent<SampleEvent>()
.Where(se => se.Status != 1)
.Subscribe(se => eventWasRaised = true);
eventPublisher.Publish(new SampleEvent { Status = 1 });
// assert
eventWasRaised.ShouldBe(false);
}
示例12: ShellViewModel
public ShellViewModel(EventAggregator eventAggregator, IRoutingState router)
{
var logger = NLog.LogManager.GetCurrentClassLogger();
_router = router;
OnCompomentsRegisted = Observable.Create<Unit>(observer => Scheduler.Default.Schedule(() =>
{
logger.Info(string.Format("Starting Compoments Registration on thread {0}.", Thread.CurrentThread));
eventAggregator.Publish(new OpenNewLifetimeScopeCommand(builder =>
{
builder.RegisterType<WelcomeViewModel>().InstancePerLifetimeScope();
builder.RegisterType<Welcome>().As<IViewFor<WelcomeViewModel>>().InstancePerLifetimeScope();
builder.RegisterType<NextPage1ViewModel>().InstancePerLifetimeScope();
builder.RegisterType<NextPage1>().As<IViewFor<NextPage1ViewModel>>().InstancePerLifetimeScope();
}));
observer.OnNext(Unit.Default);
observer.OnCompleted();
}));
}
示例13: RaiseCanExecuteChangedShouldBeInvokedOnStateChangedMessage
public void RaiseCanExecuteChangedShouldBeInvokedOnStateChangedMessage()
{
var notifier = new EventAggregator(true);
bool isInvoked = false;
var relayCommand = CreateCommand(NodoAction, o => true);
relayCommand.CanExecuteMode = ExecutionMode.None;
relayCommand.CanExecuteChanged += (sender, args) =>
{
isInvoked = true;
};
relayCommand.AddNotifier(notifier);
notifier.Publish(notifier, StateChangedMessage.Empty);
isInvoked.ShouldBeTrue();
}
示例14: A_valid_message_invokes_HandlerResultProcessing_when_expected_to
public void A_valid_message_invokes_HandlerResultProcessing_when_expected_to() {
var eventAggregator = new EventAggregator();
var coroutineHandlerMock = new Mock<IHandleWithCoroutine<object>>();
var taskHandlerMock = new Mock<IHandleWithTask<object>>();
var coroutineHandlerProcessed = false;
var taskHandlerProcessed = false;
coroutineHandlerMock.Setup(handlerStub => handlerStub.Handle(It.IsAny<object>()))
.Returns(() => new List<IResult>());
taskHandlerMock.Setup(handlerStub => handlerStub.Handle(It.IsAny<object>()))
.Returns(() => new Task(() => { }));
EventAggregator.HandlerResultProcessing = (target, result) => {
if (target is IHandleWithCoroutine<object>) {
coroutineHandlerProcessed = true;
}
else if (target is IHandleWithTask<object>) {
taskHandlerProcessed = true;
}
};
eventAggregator.Subscribe(coroutineHandlerMock.Object);
eventAggregator.Subscribe(taskHandlerMock.Object);
eventAggregator.Publish(new object());
Assert.True(coroutineHandlerProcessed);
Assert.True(taskHandlerProcessed);
}
示例15: A_valid_message_is_invoked_on_the_supplied_marshaller
public void A_valid_message_is_invoked_on_the_supplied_marshaller() {
var eventAggregator = new EventAggregator();
var handlerMock = new Mock<IHandle<object>>();
var marshallerCalled = false;
eventAggregator.Subscribe(handlerMock.Object);
eventAggregator.Publish(new object(), action => marshallerCalled = true);
Assert.True(marshallerCalled);
}