Beispiel #1
0
        static void Main(string[] args)
        {
            int option = 0;

            Console.WriteLine("ShoppingList List v 0.1");
            Console.WriteLine("Menu:");
            Console.WriteLine("1. Add Item");
            Console.WriteLine("2. Remove Item");
            Console.WriteLine("3. Update Item");
            Console.WriteLine("4. Show All");
            Console.WriteLine("5. exit");

            ShoppingListRepository repository = new ShoppingListRepository();

            while (option != 5)
            {
                Console.Write("Choose option: ");
                option = int.Parse(Console.ReadLine());

                switch (option)
                {
                case 1:
                    Item newItem = new Item {
                        Name = "Pomidor"
                    };
                    repository.AddItem(newItem);
                    break;

                case 2:
                    repository.DeleteItem(0);
                    break;

                case 3:
                    Item updateItem = new Item();
                    repository.UpdateItem(0, updateItem);
                    break;

                case 4:
                    repository.GetItems();
                    break;

                default:
                    break;
                }
            }
        }
        public void should_get_shopping_list_from_data_store()
        {
            _dataStore.Add(new ShoppingListItem {
                ItemName = "Item1", Quantity = 1
            });
            _dataStore.Add(new ShoppingListItem {
                ItemName = "Item2", Quantity = 2
            });

            var repository = new ShoppingListRepository();
            var items      = repository.GetItems();

            Assert.AreEqual(items.Count, 2);
            Assert.AreEqual(items[0].ItemName, "Item1");
            Assert.AreEqual(items[0].Quantity, 1);
            Assert.AreEqual(items[1].ItemName, "Item2");
            Assert.AreEqual(items[1].Quantity, 2);
        }
        public void should_not_use_paging_if_page_size_is_invalid(int pageSize)
        {
            for (int i = 1; i <= 20; i++)
            {
                _dataStore.Add(new ShoppingListItem {
                    ItemName = $"Item{i}", Quantity = 1
                });
            }

            var getListOptions = new ShoppingListItemGetList {
                PageNumber = 10, PageSize = pageSize
            };

            var repository = new ShoppingListRepository();
            var items      = repository.GetItems(getListOptions);

            Assert.AreEqual(items.Count, 20);
        }
        public void should_get_shopping_list_from_data_store_with_paging_when_not_first_page()
        {
            var pageSize = 10;

            for (int i = 1; i <= 50; i++)
            {
                _dataStore.Add(new ShoppingListItem {
                    ItemName = $"Item{i}", Quantity = 1
                });
            }

            var getListOptions = new ShoppingListItemGetList {
                PageNumber = 3, PageSize = pageSize
            };

            var repository = new ShoppingListRepository();
            var items      = repository.GetItems(getListOptions);

            Assert.AreEqual(items.Count, 10);
            Assert.AreEqual(items[0].ItemName, "Item21");
            Assert.AreEqual(items[0].Quantity, 1);
            Assert.AreEqual(items[pageSize - 1].ItemName, "Item30");
            Assert.AreEqual(items[pageSize - 1].Quantity, 1);
        }