示例#1
0
        public void AddsItemToItems()
        {
            var _testItem = new Item
            {
                Title       = "title",
                Description = "description"
            };

            _testShoppingList.AddItem(_testItem);

            Assert.Contains(_testItem, _testShoppingList.Items);
        }
示例#2
0
        public static void PopulateTestData(AppDbContext dbContext)
        {
            foreach (var item in dbContext.Items)
            {
                dbContext.Remove(item);
            }
            dbContext.SaveChanges();

            TestShoppingList.AddItem(Item1);
            TestShoppingList.AddItem(Item2);
            TestShoppingList.AddItem(Item3);
            dbContext.ShoppingLists.Add(TestShoppingList);

            dbContext.SaveChanges();
        }
示例#3
0
    public void TestSerialization()
    {
        ShoppingList myList = new ShoppingList();

        myList.AddItem(new Item("eggs", 1.49));
        myList.AddItem(new Item("ground beef", 3.69));
        myList.AddItem(new Item("bread", 0.89));

// Serialization
        XmlSerializer s = new XmlSerializer(typeof(ShoppingList));
        TextWriter    w = new StreamWriter(@"c:\list.xml");

        s.Serialize(w, myList);
        w.Close();

// Deserialization
    }
示例#4
0
        public void GivenShoppingList_WhenAddAnItemwithQuantity_ShoppingListShouldContainNewItemWithQuantity()
        {
            var random   = new Random();
            var quantity = random.Next(int.MaxValue);

            var sut = new ShoppingList();

            sut.AddItem("foo", (uint)quantity);

            sut.Items.Should().Contain(x => x.Name == "foo" && x.Quanity == quantity);
        }
        /// <summary>
        /// Creates a new <c>ShoppingListItem</c>-Object, adds it to the <c>ShoppingLists</c>-Collection (located in the <c>MainPageViewModel</c>).
        /// </summary>
        private void CreateItem()
        {
            ShoppingListItem item = new ShoppingListItem(Name, AmountAndMeasure);

            ShoppingList.AddItem(item);

            // Get old object
            ShoppingList oldShoppingList = ServiceLocator.Current.GetInstance <MainPageViewModel>().GetShoppingListByID(ShoppingList.ID);

            // Update Shoppinglist
            ServiceLocator.Current.GetInstance <MainPageViewModel>().EditShoppingList(oldShoppingList, ShoppingList);

            // Reset all fields
            InitializeFields();
        }
示例#6
0
 public void AddItemToList(ShoppingListItem item, int sectionId)
 {
     ShoppingList.AddItem(item, sectionId);
     StateChanged?.Invoke();
 }
示例#7
0
        public void TestShoppingList()
        {
            var testOwnerId      = 1;
            var shoppingListId   = 1;
            var testDate         = DateTime.Now;
            var finishDate       = DateTime.Now;
            var shoppingListName = (Name)"Vegi List";

            var shoppingList = new ShoppingList(shoppingListId, testOwnerId, shoppingListName, testDate);

            shoppingList.OwnerId.Should().Equals(testOwnerId);
            shoppingList.Name.Should().Equals(shoppingListName);
            shoppingList.CreatedDateTime.Should().Equals(testDate);
            shoppingList.IsCompleted.Should().Equals(false);
            shoppingList.IsEmpty.Should().Equals(true);
            shoppingList.HasAllItemsPicked.Should().Equals(false);
            shoppingList.IsCompleted.Should().Equals(false);

            Action finishEmptyList = () => shoppingList.FinishShopping(finishDate);

            finishEmptyList.Should().Throw <InvalidOperationException>().WithMessage("Shopping list is empty.");

            Action addZeroQuantity = () => shoppingList.AddItem((Name)"Carrot", UnitOfMeasure.Gram, 0);

            addZeroQuantity.Should().Throw <ArgumentException>().WithMessage("Quantity has to be greater than zero.");

            shoppingList.AddItem((Name)"Carrot", UnitOfMeasure.Gram, 500);
            shoppingList.AddItem((Name)"Potato", UnitOfMeasure.Kilogram, 1);
            shoppingList.IsEmpty.Should().Equals(false);
            shoppingList.HasAllItemsPicked.Should().Equals(false);
            shoppingList.Items.Count.Should().Equals(2);
            shoppingList.IsCompleted.Should().Equals(false);

            Action removeItemNotInList = () => shoppingList.RemoveItem((Name)"Onion");

            removeItemNotInList.Should().Throw <ArgumentException>().WithMessage("Product not found.");

            shoppingList.AddItem((Name)"Onion", UnitOfMeasure.Gram, 250);
            shoppingList.Items.Count.Should().Equals(3);

            shoppingList.RemoveItem((Name)"Carrot");
            shoppingList.Items.Count.Should().Equals(2);

            Action pickItemNotInList = () => shoppingList.PickItem((Name)"Beans");

            pickItemNotInList.Should().Throw <ArgumentException>().WithMessage("Product not found.");

            shoppingList.PickItem((Name)"Onion");
            shoppingList.HasAllItemsPicked.Should().Equals(false);

            Action finishListWithUnpickedItems = () => shoppingList.FinishShopping(finishDate);

            finishListWithUnpickedItems.Should().Throw <InvalidOperationException>().WithMessage("Shopping list has unpicked items.");

            shoppingList.PickItem((Name)"Potato");
            shoppingList.HasAllItemsPicked.Should().Equals(true);
            shoppingList.IsCompleted.Should().Equals(false);

            shoppingList.FinishShopping(finishDate);
            shoppingList.HasAllItemsPicked.Should().Equals(true);
            shoppingList.IsCompleted.Should().Equals(true);
            shoppingList.FinishedDateTime.Should().Equals(finishDate);
        }