本文整理汇总了C#中MessageBus.Handle方法的典型用法代码示例。如果您正苦于以下问题:C# MessageBus.Handle方法的具体用法?C# MessageBus.Handle怎么用?C# MessageBus.Handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageBus
的用法示例。
在下文中一共展示了MessageBus.Handle方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test()
{
var newMessages = new List<object>();
var bus = new MessageBus();
bus.RegisterHandler<object>(newMessages.Add);
var eventStore = new InMemoryEventStore(bus, GivenTheseEvents());
var repository = new DomainRepository(eventStore);
RegisterHandler(bus, repository);
bus.Handle(WhenThisHappens());
var expected = TheseEventsShouldOccur();
Assert.AreEqual(expected.Count(), newMessages.Count);
}
示例2: Test
public void Test()
{
var newMessages = new List<object>();
var bus = new MessageBus();
bus.RegisterHandler<object>(newMessages.Add);
var eventStore = new InMemoryEventStore(bus, GivenTheseEvents());
var repository = new DomainRepository(eventStore);
RegisterHandler(bus, repository);
try
{
bus.Handle(WhenThisHappens());
}
catch(Exception e)
{
var expectedException = ThisExceptionShouldOccur();
if(expectedException == null)
Assert.Fail(e.Message);
if(expectedException.GetType().IsAssignableFrom(e.GetType()))
{
Assert.AreEqual(expectedException.Message, e.Message);
return;
}
Assert.Fail("Expected exception of type {0} with message {1} but got exception of type {2} with message {3}", expectedException.GetType(), expectedException.Message, e.GetType(), e.Message);
}
var expectedEvents = TheseEventsShouldOccur().ToList();
var comparer = new CompareObjects();
if(!comparer.Compare(expectedEvents, newMessages))
{
Assert.Fail(comparer.DifferencesString);
}
}
示例3: Run
int Run()
{
var testTypes = typeof(AccountShouldBeLockedAfterThreeOverdraws).Assembly.GetTypes().Where(x => typeof(TestBase).IsAssignableFrom(x) && x.IsAbstract == false);
foreach (var type in testTypes)
{
var test = Activator.CreateInstance(type) as TestBase;
var newMessages = new List<object>();
var bus = new MessageBus();
bus.RegisterHandler<object>(newMessages.Add);
var eventStore = new InMemoryEventStore(bus, test.GivenTheseEvents());
var repository = new DomainRepository(eventStore);
test.RegisterHandler(bus, repository);
printGivens(type, test);
var command = test.WhenThisHappens();
Exception exception = null;
var expectedException = test.ThisExceptionShouldOccur();
try
{
bus.Handle(command);
}
catch(Exception e)
{
exception = e;
}
var foundException = printException(expectedException, exception, command);
if(foundException)
continue; ;
printThens(test.TheseEventsShouldOccur().ToList(), newMessages, command);
Console.WriteLine();
Console.WriteLine(new string('=', 40));
Console.WriteLine();
}
return _suuccess ? 0 : -1;
}