示例#1
0
        public void ShouldSaveRecipe()
        {
            //given
            var options = SqliteInMemory
                          .CreateOptions <CulinaryContext>();

            using (var context = new CulinaryContext(options))
            {
                //when
                context.Database.EnsureCreated();
                var r = new Recipe
                {
                    Dish             = "Cup of tea",
                    DishRecipe       = "Boil water and add tea",
                    MinutesToPrepare = 5,
                    QualityStars     = 1,
                };
                context.Recipes.Add(r);
                context.SaveChanges();
            }

            using (var context = new CulinaryContext(options))
            {
                //VERIFY
                var recipe = context.Recipes.First();
                recipe.Dish.Should().BeEquivalentTo("Cup of tea");
                recipe.DishRecipe.Should().BeEquivalentTo("Boil water and add tea");
                recipe.MinutesToPrepare.ShouldEqual(5);
                recipe.QualityStars.ShouldEqual(1);
            }
        }
示例#2
0
        public void ShouldListRecipes()
        {
            //SETUP
            var options = SqliteInMemory
                          .CreateOptions <CulinaryContext>();
            var numRecipes = 5;

            using (var context = new CulinaryContext(options))
            {
                context.Database.EnsureCreated();

                for (var i = 0; i < numRecipes; i++)
                {
                    var r = new Recipe
                    {
                        Dish             = $"Cup of tea #{i}",
                        DishRecipe       = $"Boil water and add tea for {i} minute(s) ",
                        MinutesToPrepare = i,
                        QualityStars     = i,
                    };

                    context.Recipes.Add(r);
                }

                context.SaveChanges();

                //ATTEMPT
                var service = new ListRecipeService(context);
                var dtos    = service.SelectAll().ToList();

                //VERIFY
                dtos.Count.ShouldEqual(numRecipes);
            }
        }
示例#3
0
 public ListRecipeService(CulinaryContext context)
 {
     _context = context;
 }
        public RecipeController(CulinaryContext context)

        {
            _context = context;
        }