Esempio n. 1
0
 public void Setup()
 {
     DeleteTables("carts", "cart_items");
     user = new User(UserId.New());
     domainEventPubSub = new DomainEventPubSub();
     cartRepository    = new SqlCartRepository(ConnectionString, domainEventPubSub);
     orderRepository   = new SqlOrderRepository(ConnectionString, domainEventPubSub);
     productsReadModel = new InMemoryProductsReadModel(domainEventPubSub);
     orderReadModel    = new InMemoryOrderReadModel();
 }
Esempio n. 2
0
        static async Task <int> Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            MigrateDb();
            var domainEventPubSub = new DomainEventPubSub();

            using (var policies = StartupPolicies())
            {
                if (args.Length == 1 && args[0] == "createCart")
                {
                    var cartService = CreateCartService(ConnectionString, domainEventPubSub);
                    var cart        = await cartService.CreateAsync();

                    Console.WriteLine($"Created new cart {cart.Id}");
                    return(0);
                }
                if (args.Length == 4 && args[0] == "addProduct")
                {
                    var cartService = CreateCartService(ConnectionString, domainEventPubSub);
                    var cartId      = args[1];
                    var productId   = args[2];
                    var quantity    = Int32.Parse(args[3]);
                    var cart        = await cartService.GetAsync(cartId);

                    if (cart == null)
                    {
                        System.Console.WriteLine("Cart not Found!!!");
                        cart = await cartService.CreateAsync();
                    }
                    await cartService.AddProductAsync(cartId, productId, quantity);

                    Console.WriteLine($"Product added!!!");
                    return(0);
                }
                if (args.Length == 2 && args[0] == "checkout")
                {
                    var cartId       = args[1];
                    var orderService = CreateOrderService();
                    orderService.Checkout(cartId);
                    return(0);
                }
                Console.WriteLine("No command to execute!!! Call:");
                Console.WriteLine("addProduct <cartId> <productId> <quantity>");
                Console.WriteLine("checkout <cartId>");
                return(-1);
            }
        }