コード例 #1
0
        public void UserCanEnterSeveralShoppingItems()
        {
            // Arrange
            var items = new List <Item>()
            {
                new Item("a", 10M),
                new Item("b", 20M),
                new Item("c", 30M),
                new Item("d", 40M),
                new Item("e", 50M)
            };

            var shop = new Shop();
            var user = new User();

            // Act
            shop.AddItems(items);
            user.AddShoppingItems(shop.Items);

            // Assert
            Assert.Equal(5, user.ShoppingItems.Count);
        }
コード例 #2
0
        public void ReturnsTotalCost()
        {
            // Arrange
            var items = new List <Item>()
            {
                new Item("a", 10M),
                new Item("b", 20M),
                new Item("c", 30M),
                new Item("d", 40M),
                new Item("e", 50M)
            };

            var shop = new Shop();
            var user = new User();

            // Act
            shop.AddItems(items);
            user.AddShoppingItems(shop.Items);

            // Assert
            Assert.Equal(150M, user.TotalCost);
        }
コード例 #3
0
        public void ShopContainsNumberOfItems()
        {
            // Arrange
            var items = new List <Item>()
            {
                new Item("a", 10M),
                new Item("b", 20M),
                new Item("c", 30M),
                new Item("d", 40M),
                new Item("e", 50M),
                new Item("f", 60M),
                new Item("g", 70M),
                new Item("h", 80M),
                new Item("i", 90M),
                new Item("j", 100M),
            };
            var shop = new Shop();

            // Act
            shop.AddItems(items);

            // Assert
            Assert.Equal(10, shop.Items.Count);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            ILogger       logger       = new ConsoleLogger();
            IAddUserMoney addUserMoney = new AddUserMoneyService();
            var           shop         = new Shop(logger)
            {
                Name = "Maxima"
            };
            var user = new User(addUserMoney);

            FirstData.FirstDataCreation(shop, user);
            bool commandExit = true;

            while (commandExit)
            {
                logger.Write($"This is shop {shop.Name}.\nBalance - Displays user balance\nTopup - Increase balance by .. EUR\nList - Displays available items\nBuy - Buy wanted amount of the item\nAdd - Increases amount of items\nExit - Exits the program.\n");

                try
                {
                    string command = logger.Read();

                    switch (command)
                    {
                    case "add":
                        logger.Write("Please, enter what type of item you want to add : cup, candy or book and amount.e g 'cup 10' ");
                        string[] addItemType = logger.Read().Split(' ');
                        var      addItem     = addItemType[0];
                        var      addAmount   = int.Parse(addItemType[1]);
                        shop.AddItems(addItem, addAmount);
                        break;

                    case "buy":
                        logger.Write("Please, enter what type of item you want to buy : cup, candy or book and amount.e g 'cup 10' ");
                        string[] addItemTypeAndAmount = logger.Read().Split(' ');
                        var      buyItem   = addItemTypeAndAmount[0];
                        var      buyAmount = int.Parse(addItemTypeAndAmount[1]);
                        shop.Buy(user, buyItem, buyAmount);
                        break;

                    case "list":
                        shop.ListItems();
                        break;

                    case "balance":
                        logger.Write($"User balance: { user.Balance}");
                        break;

                    case "topup":
                        logger.Write("Please, enter amount");
                        var amount = decimal.Parse(logger.Read());
                        user.AddMoney(user, amount);
                        logger.Write($"New balance {user.Balance}");
                        break;

                    case "exit":
                        commandExit = false;
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
                catch (InvalidOperationException)
                {
                    logger.Write("error");
                }
                catch (Exception e)
                {
                    logger.Write(e.Message);
                }
            }
        }