当前位置: 首页>>代码示例>>C#>>正文


C# MessageBus.Handle方法代码示例

本文整理汇总了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);
        }
开发者ID:ashic,项目名称:RoughingItCanaryWharf,代码行数:15,代码来源:TestingInfra.cs

示例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);
            }
        }
开发者ID:rlasjunies,项目名称:CQRS_trial,代码行数:39,代码来源:TestingInfra.cs

示例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;
        }
开发者ID:rlasjunies,项目名称:CQRS_trial,代码行数:44,代码来源:Program.cs


注:本文中的MessageBus.Handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。