示例#1
0
        public void CreateAccountEventIsPublishedToBus()
        {
            using (MassTransitDispatcher massTransitDispatcher = new MassTransitDispatcher(bus))
            {
                PollingClient   pollingClient  = new PollingClient(store.Advanced, 100);
                IObserveCommits commitObserver = pollingClient.ObserveFrom(null);

                IEventHandler <SimpleAggregateCreated> denormalizer = A.Fake <IEventHandler <SimpleAggregateCreated> >();
                AutoResetEvent are = new AutoResetEvent(false);
                A.CallTo(() => denormalizer.Handle(A <SimpleAggregateCreated> .Ignored)).Invokes(() => are.Set());

                bus.Subscribe(denormalizer);

                using (PollingHook pollingHook = new PollingHook(commitObserver))
                {
                    using (var subscription = commitObserver.Subscribe(massTransitDispatcher))
                    {
                        commitObserver.PollNow();
                        commitObserver.Start();

                        Guid aggregateID = Guid.NewGuid();

                        SimpleAggregate aggregate = new SimpleAggregate(aggregateID, DateTime.Now);
                        repository.Save(aggregate, Guid.NewGuid(), (o) => { });

                        are.WaitOne(10000).Should().BeTrue("event should be dispatched and recieved within timeout");
                    }
                }
            }
        }
        public async Task CreateAccountEventIsPublishedToBus()
        {
            MassTransitDispatcher massTransitDispatcher = new MassTransitDispatcher(bus);
            PollingClient         pollingClient         = new PollingClient(store.Advanced, 100);
            IObserveCommits       commitObserver        = pollingClient.ObserveFrom(null);

            AccountDenormalizer denormalizer = new AccountDenormalizer();

            bus.Subscribe(denormalizer);

            using (PollingHook pollingHook = new PollingHook(commitObserver))
            {
                using (var subscription = commitObserver.Subscribe(massTransitDispatcher))
                {
                    commitObserver.PollNow();
                    commitObserver.Start();

                    Guid   accountID = Guid.NewGuid();
                    string name      = Guid.NewGuid().ToString();
                    string twitter   = Guid.NewGuid().ToString();

                    System.Diagnostics.Debug.Print(string.Format("Creating account {0}", accountID));
                    client.CreateNewAccount(accountID, name, twitter);

                    DateTime timeoutEnd = DateTime.Now.AddSeconds(10);
                    while (denormalizer.AccountName != name && DateTime.Now < timeoutEnd)
                    {
                        await Task.Delay(100);
                    }

                    denormalizer.AccountName.Should().Be(name);
                }
            }
        }
示例#3
0
 private static IStoreEvents WireupEventStore(IBus bus)
 {
     return(Wireup.Init()
            ////.LogToOutputWindow()
            ////.LogToConsoleWindow()
            .UsingInMemoryPersistence()
            .UsingJsonSerialization()
            .Compress()
            .UsingSynchronousDispatchScheduler()
            .DispatchTo(new DelegateMessageDispatcher(c => MassTransitDispatcher.DispatchCommit(bus, c)))
            .Build());
 }
        // Here, I'm wiring up my MemBus instance and telling it how to resolve my subscribers
        // MemBus also has an awesome way to resolve subscribers from an IoC container. In prod,
        // I'll wire my subscribers into StructureMap and have MemBus resolve them from there.
        // I'm also initializing my awesome test client UI which, if you'll recall from way back at the start
        // simply publishes commands to my MemBus instance (and, again, it could be whatever)
        public SynchronousDispatchTests()
        {
            this.bus = new InProcessBus(DispatchStrategy.Synchronous);

      #pragma warning disable 0618
            this.store = Wireup.Init()
                         .UsingInMemoryPersistence()
                         .UsingSynchronousDispatchScheduler()
                         .DispatchTo(new DelegateMessageDispatcher(c => MassTransitDispatcher.DispatchCommit(this.bus, c)))
                         .Build();
      #pragma warning restore 0618

            this.repository = new EventStoreRepository(this.store, new AggregateFactory(), new ConflictDetector());
            var handler = new CreateAccountCommandHandler(this.repository);

            this.bus.Subscribe(handler);

            this.client = new SomeAwesomeUi(this.bus);
        }
        public async Task TyingItTogether()
        {
            var denormalizer = new AccountDenormalizer();

            bus.Subscribe(denormalizer);
            bus.Subscribe(new KaChingNotifier());
            bus.Subscribe(new OmgSadnessNotifier());

            var massTransitDispatcher = new MassTransitDispatcher(bus);
            var pollingClient         = new PollingClient(store.Advanced, 100);
            var commitObserver        = pollingClient.ObserveFrom(null);

            using (PollingHook pollingHook = new PollingHook(commitObserver))
            {
                using (var subscription = commitObserver.Subscribe(massTransitDispatcher))
                {
                    commitObserver.PollNow();
                    commitObserver.Start();

                    Guid   accountID = Guid.NewGuid();
                    string name      = Guid.NewGuid().ToString();
                    string twitter   = Guid.NewGuid().ToString();

                    client.CreateNewAccount(accountID, name, twitter);
                    client.CloseAccount(accountID);

                    DateTime timeoutEnd = DateTime.Now.AddSeconds(10);
                    while ((denormalizer.AccountName != name ||
                            denormalizer.IsActive) &&
                           DateTime.Now < timeoutEnd)
                    {
                        await Task.Delay(100);
                    }

                    denormalizer.AccountName.Should().Be(name);
                    denormalizer.IsActive.Should().Be(false);
                    store.OpenStream(accountID, 0, int.MaxValue).CommittedEvents.Count.Should().Be(2);
                }
            }
        }