Esempio n. 1
0
        public void EditItem_AllEditableDetails_ShouldPass()
        {
            using var context = new MarketDbContext(inMemoryConnection);

            List <string> newCategories = new List <string>()
            {
                "newCat"
            };
            List <string> newKeyWords = new List <string>()
            {
                "word1", "word2"
            };
            Item item = SetUpInvetoryWithOneItem(context);

            Dictionary <StoresUtils.ItemEditDetails, object> newDetails = new Dictionary <StoresUtils.ItemEditDetails, object>()
            {
                { StoresUtils.ItemEditDetails.name, "newName" },
                { StoresUtils.ItemEditDetails.amount, 30 },
                { StoresUtils.ItemEditDetails.categories, newCategories },
                { StoresUtils.ItemEditDetails.rank, (double)10 },
                { StoresUtils.ItemEditDetails.price, (double)3 },
                { StoresUtils.ItemEditDetails.keyWords, newKeyWords }
            };

            Assert.DoesNotThrow(() => storeInventory.EditItem(item.Id, newDetails, context));

            item = storeInventory.GetItemById(item.Id);
            Assert.AreEqual("newName", item.Name);
            Assert.AreEqual(30, item.Amount);
            Assert.AreEqual(newCategories.Count, item.Categories.Count);
            foreach (string name in newCategories)
            {
                Assert.IsTrue(item.Categories.Contains(new Category(name)));
            }
            Assert.AreEqual(10, item.Rank);
            Assert.AreEqual(3, item.Price);
            Assert.AreEqual(newKeyWords.Count, item.Keywords.Count);
            foreach (string word in newKeyWords)
            {
                Assert.IsTrue(item.Keywords.Contains(new Keyword(word)));
            }
        }