Exemple #1
0
        public void Add_Item_To_ShoppingList()
        {
            // Arrange
            var item            = new Item("item");
            var shoppingService = new ShoppingService(_sqliteConnection);

            // Act
            shoppingService.AddItem(item);

            // Assert
            Assert.Contains <Item>(shoppingService.Items, x => x == item);
        }
        public static void Run()
        {
            ConsoleColor.Red.WriteLine(nameof(OcpBadExample));

            var shoppingService = new ShoppingService();

            foreach (var item in GetItems())
            {
                shoppingService.AddItem(item);
            }
            var total = shoppingService.GetTotalAmount();

            Console.WriteLine($"Total = {total}");
        }
Exemple #3
0
        public void TryAdd_Adds_Item_Only_If_Not_Present_On_List()
        {
            // Arrange
            var item1           = "item 1";
            var shoppingService = new ShoppingService(_sqliteConnection);

            shoppingService.AddItem(new Item(item1));

            // Act
            shoppingService.TryAddItemToShoppingList(new Item(item1));

            // Assert
            Assert.Equal(1, shoppingService.Items.Count);
        }
Exemple #4
0
        public void Remove_Item_From_ShoppingList()
        {
            // Arrange
            var item            = new Item("item");
            var shoppingService = new ShoppingService(_sqliteConnection);

            shoppingService.AddItem(item);

            // Act
            shoppingService.RemoveItem(item);

            // Assert
            Assert.DoesNotContain <Item>(shoppingService.Items, x => x == item);
            Assert.Contains <BoughtItem>(shoppingService.BoughtItems, x => x.Title == item.Title);
            Assert.Contains <BoughtItem>(shoppingService.BoughtItems, x => x.Title == item.Title && x.BoughtCount == 1);
        }
        public void AddItem()
        {
            if (!string.IsNullOrWhiteSpace(_searchString) && _searchString.Length > 1)
            {
                var newItem = new Item()
                {
                    ListId = _shoppingList.Id,
                    Name   = _searchString.Trim()
                };

                Device.BeginInvokeOnMainThread(async() =>
                {
                    _allItems.Add(newItem);
                    Clear();

                    await Task.Delay(100);

                    ScrollTo?.Invoke(newItem);

                    _shoppingService.AddItem(newItem);
                    //FilterResult();
                });
            }
        }