Ejemplo n.º 1
0
        public void InsertRangeToDataStore()
        {
            List <Ingredient> itemsToAdd = new List <Ingredient>
            {
                new Ingredient
                {
                    Category       = UnitTestItems.IngredientCategories.Meat,
                    AdditionalCost = 0,
                    Name           = "Pork",
                },
                new Ingredient
                {
                    Category       = UnitTestItems.IngredientCategories.Topping,
                    AdditionalCost = 0,
                    Name           = "BBQ Sauce",
                },
            };

            Context.Ingredients.InsertRange(itemsToAdd);
            Context.SaveChanges();

            //Check save successful by opening new context and inspecting data

            NachoMaticContext newContext = new NachoMaticContext();

            bool hasNewItems = newContext.Ingredients.Any(i => i.Name == "Pork") && newContext.Ingredients.Any(i => i.Name == "BBQ Sauce");

            Assert.IsTrue(hasNewItems);
        }
Ejemplo n.º 2
0
        public void InsertItemToDataStore()
        {
            var category = Context.IngredientCategories.FirstOrDefault(c => c.Type == NachoMatic.IngredientType.Meat);

            if (category != null)
            {
                Ingredient newIngredient = new Ingredient
                {
                    Category       = category,
                    AdditionalCost = 0,
                    Name           = "Pork",
                };

                Context.Ingredients.Insert(newIngredient);
                Context.SaveChanges();

                //Check save successful by opening new context and inspecting data

                NachoMaticContext newContext = new NachoMaticContext();

                bool hasNewItem = newContext.Ingredients.Any(i => i.Name == "Pork");

                Assert.IsTrue(hasNewItem);
            }
        }
Ejemplo n.º 3
0
        public void DeleteItemFromDataStore()
        {
            IngredientCategory removing = Context.IngredientCategories.First();

            Context.IngredientCategories.Delete(removing.Id);

            Context.SaveChanges();

            //Check save successful by opening new context and inspecting data

            NachoMaticContext newContext = new NachoMaticContext();

            bool itemGone = newContext.IngredientCategories.All(i => i.Name != removing.Name);

            Assert.IsTrue(itemGone);
        }
Ejemplo n.º 4
0
        public void UpdateItemInDataStore()
        {
            NachoItem originalItem = Context.NachoItems.First();

            originalItem.Name = "New Name";

            Context.NachoItems.Update(originalItem);

            Context.SaveChanges();

            //Check save successful by opening new context and inspecting data

            NachoMaticContext newContext = new NachoMaticContext();

            NachoItem updatedItem = newContext.NachoItems.GetById(originalItem.Id);

            Assert.AreEqual("New Name", updatedItem.Name);
        }