Esempio n. 1
0
        static async Task Main(string[] args)
        {
            // create and configure the service container
            IServiceCollection serviceCollection = ConfigureServices();

            // build the service provider
            IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            IUnitOfWork uow = serviceProvider.GetService <IUnitOfWork>();

            // get all users
            var users = await uow.GetUserRepository().GetAllAsync();

            PrintUsers(users);

            // get all products
            var prods = await uow.GetProductRepository().GetAllAsync();

            PrintProducts(prods);

            Command cmd;
            Command saveCommand = new SaveCommand(uow);

            // create carts for users[0] & users[1]
            cmd = new CreateCartCommand(users[0]);
            cmd.Execute();

            cmd = new CreateCartCommand(users[1]);
            cmd.Execute();

            var cart1 = users[0].Carts.Last();
            var cart2 = users[1].Carts.Last();

            saveCommand.Execute();

            // some operation on npaul's cart
            cmd = new AddProductToCartCommand(cart1, prods[0], 5);
            cmd.Execute();

            cmd = new AddProductToCartCommand(cart1, prods[1], 3);
            cmd.Execute();

            cmd = new UpdateCartItemQuantityCommand(cart1, prods[0], 6);
            cmd.Execute();

            saveCommand.Execute();

            PrintCart(cart1);

            // some operation on jdoe's cart
            cmd = new AddProductToCartCommand(cart2, prods[0], 1);
            cmd.Execute();

            cmd = new AddProductToCartCommand(cart2, prods[1], 3);
            cmd.Execute();

            cmd = new AddProductToCartCommand(cart2, prods[2], 2);
            cmd.Execute();

            cmd = new AddProductToCartCommand(cart2, prods[3], 2);
            cmd.Execute();

            saveCommand.Execute();

            PrintCart(cart2);

            cmd = new UpdateProductPriceCommand(prods[1], 15);
            cmd.Execute();

            saveCommand.Execute();

            PrintCart(cart1);
            PrintCart(cart2);

            // cleaning
            cmd = new DeleteCartCommand(cart1, uow.GetCartRepository());
            cmd.Execute();

            cmd = new DeleteCartCommand(cart2, uow.GetCartRepository());
            cmd.Execute();

            saveCommand.Execute();

            cmd = new UpdateProductPriceCommand(prods[1], 17.50);
            cmd.Execute();

            saveCommand.Execute();
        }