Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            var bus = BusSetup.StartWith <Conservative>()
                      .Apply <FlexibleSubscribeAdapter>(a =>
            {
                a.ByInterface(typeof(IEventHandler <>));
                a.ByInterface(typeof(ICommandHandler <>));
            }).Construct();

            var someAwesomeUi = new SomeAwesomeUi(bus);

            using (store = WireupEventStore(bus))
            {
                var repository = new EventStoreRepository(store, new AggregateFactory(), new ConflictDetector());

                var handler  = new CreateAccountCommandHandler(repository);
                var handler2 = new CloseAccountCommandHandler(repository);
                bus.Subscribe(handler);
                bus.Subscribe(handler2);
                bus.Subscribe(new KaChingNotifier());
                bus.Subscribe(new OmgSadnessNotifier());

                someAwesomeUi.CreateNewAccount(AggregateId, "Luiz", "@luizdamim");
                someAwesomeUi.CloseAccount(AggregateId);
            }

            Console.ReadLine();
        }
        public void When_close_account_command_is_triggered_on_a_closed_account_it_should_not_raise_events()
        {
            // Arrange
            var account = new Account(Guid.NewGuid(), "Thomas");
            account.Close();

            var eventStore = new InMemoryEventRepositoryBuilder().WithAggregates(account).Build();
            var handler = new CloseAccountCommandHandler(eventStore);

            // Act
            handler.Handle(new CloseAccountCommand(account.Id));

            // Assert
            eventStore.Events.OfType<AccountClosedEvent>().Should().BeEmpty();
        }
        public static void ClassInitialise(TestContext context)
        {
            bus = new InProcessBus(DispatchStrategy.Asynchronous);

            store = Wireup.Init()
                    .UsingInMemoryPersistence()
                    .Build();
            repository = new EventStoreRepository(store, new AggregateFactory(), new ConflictDetector());

            var createHandler     = new CreateAccountCommandHandler(repository);
            var deactivateHandler = new CloseAccountCommandHandler(repository);

            bus.Subscribe(createHandler);
            bus.Subscribe(deactivateHandler);

            client = new SomeAwesomeUi(bus);
        }
        public void When_close_account_command_is_triggered_it_should_raise_the_appropriate_events()
        {
            // Arrange
            var account = new Account(Guid.NewGuid(), "Thomas");

            var eventStore = new InMemoryEventRepositoryBuilder().WithAggregates(account).Build();
            var handler = new CloseAccountCommandHandler(eventStore);

            // Act
            handler.Handle(new CloseAccountCommand(account.Id));

            // Assert
            eventStore.Events.Should().HaveCount(1);
            eventStore.Events.OfType<AccountClosedEvent>().Should().HaveCount(1);

            account = eventStore.GetById<Account>(account.Id);
            account.IsActive.Should().BeFalse();
        }
        public void DeactivingAccountDoesntRetriggerInitialCreate()
        {
            var deactivateHandler = new CloseAccountCommandHandler(new EventStoreRepository(this.store, new AggregateFactory(), new ConflictDetector()));
            var denormalizer      = new AccountDenormalizer();

            this.bus.Subscribe(deactivateHandler);
            this.bus.Subscribe(denormalizer);

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

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

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