本文整理汇总了C#中EventSource.EmitEvent方法的典型用法代码示例。如果您正苦于以下问题:C# EventSource.EmitEvent方法的具体用法?C# EventSource.EmitEvent怎么用?C# EventSource.EmitEvent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventSource
的用法示例。
在下文中一共展示了EventSource.EmitEvent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGenericEvents
public void TestGenericEvents()
{
var a = new EventSource();
var e = new IncomingEvent<EventArgs> { Channel = "a", DataObject = new EventArgs { Id = 10 }, EventName = "foo" };
(e as IncomingEvent).Data = "{id:10}";
var events = new List<IIncomingEvent>();
a.EventEmitted += (sender, evt) =>
{
Assert.AreEqual(evt.Channel, e.Channel);
Assert.AreEqual(evt.Data, e.Data);
Assert.AreEqual(evt.EventName, e.EventName);
events.Add(evt);
};
a.GetEventSubscription<EventArgs>().EventEmitted += (sender, evt) =>
{
Assert.AreEqual(evt.Channel, e.Channel);
Assert.AreEqual(evt.Data, e.Data);
Assert.AreEqual(evt.DataObject.Id, e.DataObject.Id);
Assert.AreEqual(evt.EventName, e.EventName);
events.Add(evt);
};
a.EmitEvent(e);
Assert.AreEqual(events.Count, 2, "Event should get through twice when you have two subscriptions");
}
示例2: TestEventsAreTriggered
public void TestEventsAreTriggered()
{
var a = new EventSource();
var e = new IncomingEvent {Channel = "a", Data = "{}", EventName = "foo"};
var events = new List<IIncomingEvent>();
a.EventEmitted += (sender, evt) =>
{
Assert.AreEqual(evt.Channel, e.Channel);
Assert.AreEqual(evt.Data, e.Data);
Assert.AreEqual(evt.EventName, e.EventName);
events.Add(evt);
};
a.EmitEvent(e);
Assert.AreEqual(events.Count, 1);
}