public void Should_Credit_On_Order_Cancel() { //Arrange var domainEventDispatcher = new DomainEventDispatcher(); var eventStore = EventStore.Create(domainEventDispatcher); domainEventDispatcher.RegisterHandler <BuyOrderCreatedDomainEvent>(new BuyOrderCreatedHandler(eventStore)); domainEventDispatcher.RegisterHandler <BuyOrderCancelledDomainEvent>(new BuyOrderCancelledHandler(eventStore)); //Act var account = Account.Create(1_000); eventStore.Commit(account); var order = Order.Create(account.Id, OrderSide.Buy, "PETR4", 10, 10M); eventStore.Commit(order); order.Cancel(); eventStore.Commit(order); //Assert var storedAccount = Account.Load(eventStore.GetById(account.Id)); Assert.Equal(3, storedAccount.Version); Assert.Equal(1_000, storedAccount.Ballance); }
public void ShouldUpdateOrderDtoLeavesQuantityAfterExecution() { //Arrange var projectionHost = new ProjectorHost(); var domainEventDispatcher = new DomainEventDispatcher(); var eventStore = EventStore.Create(projectionHost, domainEventDispatcher); var dtoStore = MemoryCache.Create(); domainEventDispatcher.RegisterHandler <BuyOrderCreatedDomainEvent>(new BuyOrderCreatedHandler(eventStore)); projectionHost.Add(new AccountProjector(dtoStore)); projectionHost.Add(new OrderProjector(dtoStore)); //Act var account = Account.Create(10_000); eventStore.Commit(account); var order = Order.Create(account.Id, OrderSide.Buy, "PETR4", 100, 10M); order.Execute(Trade.Create(Guid.NewGuid(), order.Id, 75)); eventStore.Commit(order); //Assert var accountDto = dtoStore.Get <AccountDto>(account.Id); Assert.Equal(9_000, accountDto.Ballance); var orderDto = dtoStore.Get <OrderDto>(order.Id); Assert.Equal(order.Symbol, orderDto.Symbol); Assert.Equal <uint>(75, orderDto.ExecutedQuantity); Assert.Equal <uint>(25, orderDto.LeavesQuantity); }
public void ShouldDebitAccountDtoOnOrderCreation() { //Arrange var projectionHost = new ProjectorHost(); var domainEventDispatcher = new DomainEventDispatcher(); var eventStore = EventStore.Create(projectionHost, domainEventDispatcher); var dtoStore = MemoryCache.Create(); projectionHost.Add(new AccountProjector(dtoStore)); projectionHost.Add(new OrderProjector(dtoStore)); domainEventDispatcher.RegisterHandler <BuyOrderCreatedDomainEvent>(new BuyOrderCreatedHandler(eventStore)); domainEventDispatcher.RegisterHandler <BuyOrderCancelledDomainEvent>(new BuyOrderCancelledHandler(eventStore)); //Act var account = Account.Create(1_000); eventStore.Commit(account); var order = Order.Create(account.Id, OrderSide.Buy, "PETR4", 10, 10M); eventStore.Commit(order); //Assert var orderDto = dtoStore.Get <OrderDto>(order.Id); Assert.Equal(order.Symbol, orderDto.Symbol); Assert.Equal(order.Quantity, orderDto.Quantity); Assert.Equal(order.Price, orderDto.Price); var accountDto = dtoStore.Get <AccountDto>(account.Id); Assert.Equal(900, accountDto.Ballance); }
public void Start() { Log.Assign(new Log4NetLog(LogManager.GetLogger(typeof(Host)))); _container = new WindsorContainer(); var container = new WindsorComponentContainer(_container); container.RegisterSuffixed("Shuttle.Access.Sql"); EventStore.Register(container); _eventStore = EventStore.Create(container); container.Register <UserHandler>(); container.Register <RoleHandler>(); _eventProcessor = container.Resolve <IEventProcessor>(); _eventProcessor.AddProjection( new Recall.Projection("SystemUsers").AddEventHandler(container.Resolve <UserHandler>())); _eventProcessor.AddProjection( new Recall.Projection("SystemRoles").AddEventHandler(container.Resolve <RoleHandler>())); _eventProcessor.Start(); }
public void Should_Persist_Events() { var eventStore = EventStore.Create(); Inventory inventory = Inventory.Create(); eventStore.Commit(inventory); var storedInventory = eventStore.GetById <Inventory>(inventory.Id); Assert.Empty(inventory.PendingEvents); Assert.Equal(inventory.Id, storedInventory.Id); }
public void ExerciseEventStore() { var container = new WindsorComponentContainer(new WindsorContainer()); EventStore.Register(container); using (container.Resolve <IDatabaseContextFactory>().Create(EventStoreConnectionStringName)) { RecallFixture.ExerciseEventStore(EventStore.Create(container), EventProcessor.Create(container)); } }
public void ExerciseStorage() { var container = new WindsorComponentContainer(new WindsorContainer()); container.RegisterInstance(new Mock <IProjectionRepository>().Object); EventStore.Register(container); using (container.Resolve <IDatabaseContextFactory>().Create(EventStoreConnectionStringName)) { RecallFixture.ExerciseStorage(EventStore.Create(container)); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var eventStore = EventStore.Create(); services.AddScoped(x => eventStore); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); }
public void Should_Load_Created_Only() { var eventStore = EventStore.Create(); Inventory inventory = Inventory.Create(); var productId = Guid.NewGuid(); inventory.AddProduct(productId, 10); eventStore.Commit(inventory); var storedInventory = eventStore.GetByVersion <Inventory>(inventory.Id, 1); Assert.Equal(inventory.Id, storedInventory.Id); Assert.Equal(0, storedInventory.GetProductCount(productId)); }
public void Should_Load_All_Events() { var eventStore = EventStore.Create(); Inventory inventory = Inventory.Create(); var productId = Guid.NewGuid(); var productQuantity = 10; inventory.AddProduct(productId, productQuantity); eventStore.Commit(inventory); var storedInventory = eventStore.GetById <Inventory>(inventory.Id); Assert.Equal(inventory.Id, storedInventory.Id); Assert.Equal(productQuantity, storedInventory.GetProductCount(productId)); }
public void ShouldRetrieveAccountDtoWithInitialDeposit() { //Arrange var projectionHost = new ProjectorHost(); var eventStore = EventStore.Create(projectionHost, new DomainEventDispatcher()); var dtoStore = MemoryCache.Create(); projectionHost.Add(new AccountProjector(dtoStore)); //Act var account = Account.Create(1_000); eventStore.Commit(account); //Assert var accountDto = dtoStore.Get <AccountDto>(account.Id); Assert.Equal(account.Ballance, accountDto.Ballance); }
public WhenHandlingPlaceBid() { _subject = CommandHandler.Create(EventStore.Create()); _aggregateId = Guid.NewGuid(); }
public WhenHandlingStartAuction() { _subject = CommandHandler.Create(EventStore.Create()); _aggregateId = Guid.NewGuid(); }