public void GetRecipe_ParametersMatchExpectedValues()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>()
                            .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeRecipe = new FakeRecipe {
            }.Generate();

            //Act
            using (var context = new RecipeDbContext(dbOptions))
            {
                context.Recipes.AddRange(fakeRecipe);
                context.SaveChanges();

                var service = new RecipeRepository(context, new SieveProcessor(sieveOptions));

                //Assert
                var recipeById = context.Recipes.FirstOrDefault(r => r.RecipeId == fakeRecipe.RecipeId);

                recipeById.Should().BeEquivalentTo(fakeRecipe);
                recipeById.RecipeId.Should().Be(fakeRecipe.RecipeId);
                recipeById.RecipeTextField1.Should().Be(fakeRecipe.RecipeTextField1);
                recipeById.RecipeTextField2.Should().Be(fakeRecipe.RecipeTextField2);
                recipeById.RecipeDateField1.Should().Be(fakeRecipe.RecipeDateField1);
            }
        }
Example #2
0
 public RecipeService(RecipeDbContext recipeDbContext,
                      NutritioninfoRepository repository, OrderRepository orderRepository)
 {
     _context           = recipeDbContext;
     _nutritionInfoRepo = repository;
     _orderRepo         = orderRepository;
 }
 public UsersController(IUserService userService, UserManager <IdentityUser> UserManager, RecipeDbContext Context, RoleManager <IdentityRole> roleManager)
 {
     this.userService = userService;
     this.UserManager = UserManager;
     this.Context     = Context;
     this.roleManager = roleManager;
 }
Example #4
0
 public RecipeRepository(RecipeDbContext context,
                         SieveProcessor sieveProcessor)
 {
     _context = context
                ?? throw new ArgumentNullException(nameof(context));
     _sieveProcessor = sieveProcessor ??
                       throw new ArgumentNullException(nameof(sieveProcessor));
 }
Example #5
0
        public RepositoryTestData(RecipeDbContext dbContext)
        {
            this.Context = dbContext;
            Recipes      = new List <Recipe>();
            Sources      = new List <RecipeBaseSource>();
            Steps        = new List <RecipeStep>();
            Ingrediants  = new List <Ingrediant>();
            Images       = new List <RecipeImage>();
            Tags         = new List <RecipeTag>();

            InitLocalTestData();
        }
Example #6
0
        protected virtual async Task InitializeAsync()
        {
            var options = new DbContextOptionsBuilder <RecipeDbContext>()
                          .UseInMemoryDatabase("read_from_database")
                          .Options;

            this.DbContext = new RecipeDbContext(options);

            var testDataCreationContext = new RecipeDbContext(options);

            this.TestData = new RepositoryTestData(testDataCreationContext);
            await this.TestData.CreateTestDataAsync(RepositoryTestData.TestDataRemoveOption.NoRemoval, false);
        }
Example #7
0
        static void Main(string[] args)
        {
            var db = new RecipeDbContext();

            //create if doestn exist
            db.Database.EnsureCreated();

            //add record
            db.Recipes.Add(new Recipe {
                Name = "Musaka"
            });
            db.SaveChanges();
        }
        public void GetRecipes_FilterListWithExact(string filters)
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>()
                            .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeRecipeOne = new FakeRecipe {
            }.Generate();

            fakeRecipeOne.RecipeTextField1 = "Alpha";
            fakeRecipeOne.RecipeTextField2 = "Bravo";
            fakeRecipeOne.RecipeIntField1  = 5;

            var fakeRecipeTwo = new FakeRecipe {
            }.Generate();

            fakeRecipeTwo.RecipeTextField1 = "Charlie";
            fakeRecipeTwo.RecipeTextField2 = "Delta";
            fakeRecipeTwo.RecipeIntField1  = 6;

            var fakeRecipeThree = new FakeRecipe {
            }.Generate();

            fakeRecipeThree.RecipeTextField1 = "Echo";
            fakeRecipeThree.RecipeTextField2 = "Foxtrot";
            fakeRecipeThree.RecipeIntField1  = 7;

            //Act
            using (var context = new RecipeDbContext(dbOptions))
            {
                context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree);
                context.SaveChanges();

                var service = new RecipeRepository(context, new SieveProcessor(sieveOptions));

                var recipeRepo = service.GetRecipes(new RecipeParametersDto {
                    Filters = filters
                });

                //Assert
                recipeRepo.Should()
                .HaveCount(1);

                context.Database.EnsureDeleted();
            }
        }
        public void GetRecipes_SearchQueryReturnsExpectedRecordCount(string queryString, int expectedCount)
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>()
                            .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeRecipeOne = new FakeRecipe {
            }.Generate();

            fakeRecipeOne.RecipeTextField1 = "Alpha";
            fakeRecipeOne.RecipeTextField2 = "Bravo";

            var fakeRecipeTwo = new FakeRecipe {
            }.Generate();

            fakeRecipeTwo.RecipeTextField1 = "Hartsfield";
            fakeRecipeTwo.RecipeTextField2 = "White";

            var fakeRecipeThree = new FakeRecipe {
            }.Generate();

            fakeRecipeThree.RecipeTextField1 = "Bravehart";
            fakeRecipeThree.RecipeTextField2 = "Jonfav";

            //Act
            using (var context = new RecipeDbContext(dbOptions))
            {
                context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree);
                context.SaveChanges();

                var service = new RecipeRepository(context, new SieveProcessor(sieveOptions));

                var recipeRepo = service.GetRecipes(new RecipeParametersDto {
                    QueryString = queryString
                });

                //Assert
                recipeRepo.Should()
                .HaveCount(expectedCount);

                context.Database.EnsureDeleted();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            using (var db = new RecipeDbContext())
            {
                // Create and save a new Blog
                System.Console.WriteLine("Welcome to Food Monk cmd Solution for a RecipeBlog ");
                System.Console.WriteLine("Enter a new Recipe.. ");
                System.Console.WriteLine("Recipe Name: ");
                var name = System.Console.ReadLine();
                System.Console.WriteLine("Recipe Type: ");

                var type = System.Console.ReadLine();
                System.Console.WriteLine("Recipe Ingredients (csv): ");
                var ningredients = System.Console.ReadLine();
                System.Console.WriteLine("Recipe Description: ");
                var    description = System.Console.ReadLine();
                Random rnd         = new Random();
                var    Recipe      = new Recipe
                {
                    Id          = rnd.Next(10, 100),
                    Title       = name,
                    RecipeType  = type,
                    Ratings     = 0,
                    Description = description,
                    CreatedOn   = DateTime.UtcNow.Date
                };

                db.Recipe.Add(Recipe);
                db.SaveChanges();

                //Display all Entries from the database
                var query = from b in db.Recipe
                            orderby b.RecipeType
                            select b;

                System.Console.WriteLine("All Entries in the database:");
                foreach (var item in query)
                {
                    System.Console.WriteLine(item.Title);
                }

                System.Console.WriteLine("Press any key to exit...");
                System.Console.ReadKey();
            }
        }
        public void GetRecipes_ListSortedInDescOrder()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>()
                            .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeRecipeOne = new FakeRecipe {
            }.Generate();

            fakeRecipeOne.RecipeTextField1 = "Bravo";

            var fakeRecipeTwo = new FakeRecipe {
            }.Generate();

            fakeRecipeTwo.RecipeTextField1 = "Alpha";

            var fakeRecipeThree = new FakeRecipe {
            }.Generate();

            fakeRecipeThree.RecipeTextField1 = "Charlie";

            //Act
            using (var context = new RecipeDbContext(dbOptions))
            {
                context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree);
                context.SaveChanges();

                var service = new RecipeRepository(context, new SieveProcessor(sieveOptions));

                var recipeRepo = service.GetRecipes(new RecipeParametersDto {
                    SortOrder = "-RecipeTextField1"
                });

                //Assert
                recipeRepo.Should()
                .ContainInOrder(fakeRecipeThree, fakeRecipeOne, fakeRecipeTwo);

                context.Database.EnsureDeleted();
            }
        }
        public void DeleteRecipe_ReturnsProperCount()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>()
                            .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeRecipeOne = new FakeRecipe {
            }.Generate();
            var fakeRecipeTwo = new FakeRecipe {
            }.Generate();
            var fakeRecipeThree = new FakeRecipe {
            }.Generate();

            //Act
            using (var context = new RecipeDbContext(dbOptions))
            {
                context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree);

                var service = new RecipeRepository(context, new SieveProcessor(sieveOptions));
                service.DeleteRecipe(fakeRecipeTwo);

                context.SaveChanges();

                //Assert
                var recipeList = context.Recipes.ToList();

                recipeList.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                recipeList.Should().ContainEquivalentOf(fakeRecipeOne);
                recipeList.Should().ContainEquivalentOf(fakeRecipeThree);
                Assert.DoesNotContain(recipeList, r => r == fakeRecipeTwo);

                context.Database.EnsureDeleted();
            }
        }
        public void GetRecipes_ReturnExpectedPageSize()
        {
            //Arrange
            var dbOptions = new DbContextOptionsBuilder <RecipeDbContext>()
                            .UseInMemoryDatabase(databaseName: $"RecipeDb{Guid.NewGuid()}")
                            .Options;
            var sieveOptions = Options.Create(new SieveOptions());

            var fakeRecipeOne = new FakeRecipe {
            }.Generate();
            var fakeRecipeTwo = new FakeRecipe {
            }.Generate();
            var fakeRecipeThree = new FakeRecipe {
            }.Generate();

            //Act
            using (var context = new RecipeDbContext(dbOptions))
            {
                context.Recipes.AddRange(fakeRecipeOne, fakeRecipeTwo, fakeRecipeThree);
                context.SaveChanges();

                var service = new RecipeRepository(context, new SieveProcessor(sieveOptions));

                var recipeRepo = service.GetRecipes(new RecipeParametersDto {
                    PageSize = 2
                });

                //Assert
                recipeRepo.Should()
                .NotBeEmpty()
                .And.HaveCount(2);

                recipeRepo.Should().ContainEquivalentOf(fakeRecipeOne);
                recipeRepo.Should().ContainEquivalentOf(fakeRecipeTwo);

                context.Database.EnsureDeleted();
            }
        }
Example #14
0
 public CountriesRepository(RecipeDbContext countryContext)
 {
     _countryContext = countryContext;
 }
Example #15
0
 public OrderRepository(RecipeDbContext context)
 {
     _context = context;
 }
Example #16
0
 public EditModel(RecipeDbContext db)
 {
     _db = db;
 }
 public CheckingController(ICheckingService Service, UserManager <IdentityUser> UserManager, RecipeDbContext Context)
 {
     this.Service     = Service;
     this.UserManager = UserManager;
     this.Context     = Context;
 }
Example #18
0
 public StepRepository(RecipeDbContext context, ILoggerFactory logger) : base(context, logger)
 {
 }
Example #19
0
 public IngrediantRepository(RecipeDbContext context, ILoggerFactory logger) : base(context, logger)
 {
 }
Example #20
0
 public BaseSourceRepository(RecipeDbContext context, ILoggerFactory logger) : base(context, logger)
 {
 }
 public WeeklyMenuRepository(RecipeDbContext Context, UserManager <IdentityUser> UserManager)
 {
     this.Context     = Context;
     this.UserManager = UserManager;
 }
Example #22
0
 public UserDataRepository(RecipeDbContext context)
 {
     _context = context;
 }
Example #23
0
 public RecipeData(RecipeDbContext context)
 {
     _context = context;
 }
 public RecipeRepository(RecipeDbContext recipeDbContext)
 {
     _recipeDbContext = recipeDbContext;
 }
Example #25
0
 public NutritioninfoRepository(RecipeDbContext context)
 {
     _context = context;
 }