public void CanPersistShippingAddressWithOrder() { //Arrange var address = Address.Create("a", "b", "c", "d"); var customer = Customer.Create(1, address, CustomerStatus.New); var items = new List <CartItem> { new CartItem(1, 10, 5), new CartItem(2, 100, 5) }; //Act var order = SalesOrder.Create(items, customer); using (var context = new OrderContext()) { SetupLogging(context); context.Orders.Add(order); context.SaveChanges(); } //Assert using (var context = new OrderContext()) { SetupLogging(context); var databaseOrder = context.Orders.FirstOrDefault(); Assert.AreEqual(address, databaseOrder.ShippingAddress); WriteLog(); } }
public void Handle(CreateSalesOrder command) { using (var t = _context.OpenSession(command)) { var so = new SalesOrder(); so.Create(_id); t.SaveAndPublishEvents(so); } }
public override void Handle(CreateSalesOrderCommand command) { var order = new SalesOrder(); order.Create(command.Id, command.MaxValue); _salesOrderRepository.Save(order); _eventBus.Publish(new SalesOrderCreatedEvent(command.Id, command.MaxValue, DateTimeOffset.Now)); }
public void NewSalesOrderHasCorrectShippingAddress() { //Arrange var customer = Customer.Create(1, Address.Create("a", "b", "c", "d"), CustomerStatus.New); var items = new List <CartItem> { new CartItem(1, 10, 5), new CartItem(2, 100, 5) }; //Act var order = SalesOrder.Create(items, customer); //Assert Assert.AreEqual(Address.Create("a", "b", "c", "d"), order.ShippingAddress); }
public override void Handle(CreateSalesOrderCommand command) { var order = new SalesOrder(); order.Create(command.Id, command.MaxValue); IEnumerable <Event> events = order.GetUncommittedEvents(); _salesOrderRepository.Save(order); order.AcceptUncommittedEvents(); _eventBus.Publish(events); }
public void NewSalesOrderHasCorrectCartItemData() { //Arrange var customer = Customer.Create(1, Address.Create("a", "b", "c", "d"), CustomerStatus.New); var items = new List <CartItem> { new CartItem(1, 10, 5), new CartItem(2, 100, 5) }; //Act var order = SalesOrder.Create(items, customer); //Assert Assert.AreEqual(10, order.LineItems.Sum(i => i.Quantity)); Assert.AreEqual(550, order.LineItems.Sum(i => i.LineTotal)); }
public void Handle(CreateSalesOrderCommand command) { var repository = _container.Resolve <IRepository <SalesOrder> >(); try { var order = new SalesOrder(); order.Create(command.Id, command.MaxValue); IEnumerable <Event> events = order.GetUncommittedEvents(); repository.Save(order); order.AcceptUncommittedEvents(); _eventBus.Send(events); } finally { _container.Release(repository); } }
protected override void Seed(DataAccess.Contexts.ApplicationContext context) { // This method will be called after migrating to the latest version. // You can use the DbSet<T>.AddOrUpdate() helper extension method // to avoid creating duplicate seed data. E.g. // // context.People.AddOrUpdate( // p => p.FullName, // new Person { FullName = "Andrew Peters" }, // new Person { FullName = "Brice Lambson" }, // new Person { FullName = "Rowan Miller" } // ); // var c1 = Customer.Create("Paul", "p@gmail", "(444-555-6666)", "*****@*****.**", "111-222-3333"); var c2 = Customer.Create("Jamie", "j@gmail", "(444-555-777)", "*****@*****.**", "111-222-444"); var c3 = Customer.Create("Gillian", "g@gmail", "(444-555-888)", "*****@*****.**", "111-222-555"); var so1 = SalesOrder.Create(500.00); var so2 = SalesOrder.Create(600.00); var so3 = SalesOrder.Create(800.00); var so4 = SalesOrder.Create(700.00); var so5 = SalesOrder.Create(900.00); var so6 = SalesOrder.Create(1000.00); c1.AddSalesOrder(so1); c1.AddSalesOrder(so2); c2.AddSalesOrder(so3); c2.AddSalesOrder(so4); c3.AddSalesOrder(so5); c3.AddSalesOrder(so6); context.Customers.AddOrUpdate(c => c.HomeEmail, c1, c2, c3); context.SaveChanges(); }