Example #1
0
        public async void TestRecipeGetAllEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test14DB")
                          .Options;

            //Act
            List <Recipe> testResultsRecipes;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testUser2 = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testRecipe = new Recipe
                {
                    RecipeCookTime = 5,
                    User           = testUser
                };

                var testRecipe2 = new Recipe
                {
                    RecipeCookTime = 5,
                    User           = testUser2
                };

                await _unitOfWork.Recipes.Add(testRecipe);

                await _unitOfWork.Recipes.Add(testRecipe2);

                await _unitOfWork.Complete();

                var tempTestRecipes = await _unitOfWork.Recipes.GetAllEager();

                testResultsRecipes = tempTestRecipes.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(1, testResultsRecipes[0].User.Id);
                Assert.Equal("TestUser", testResultsRecipes[0].User.Username);
                Assert.Equal(2, testResultsRecipes[1].User.Id);
                Assert.Equal("TestUser2", testResultsRecipes[1].User.Username);
            }
        }
Example #2
0
        public async void TestGenericAdd()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test1DB")
                          .Options;

            //Act
            RecipeOrigin testOrigin;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                testOrigin = new RecipeOrigin
                {
                    RecipeOriginName = "Test"
                };

                await _unitOfWork.RecipeOrigins.Add(testOrigin);

                await _unitOfWork.Complete();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                var origin = context.RecipeOrigins
                             .Where(orig => orig.RecipeOriginName == "Test").First();
                Assert.Equal(testOrigin.Id, origin.Id);
            }
        }
Example #3
0
        public async void TestReviewGetByRecipeEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test11DB")
                          .Options;

            //Act
            List <RecipeReview> testResultsRecipeReviews;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testRecipe = new Recipe
                {
                    RecipeCookTime = 5
                };

                var testReview = new RecipeReview
                {
                    Recipe = testRecipe,
                    User   = testUser
                };

                var testReview2 = new RecipeReview
                {
                    Recipe = testRecipe,
                    User   = testUser
                };

                await _unitOfWork.RecipeReviews.Add(testReview);

                await _unitOfWork.RecipeReviews.Add(testReview2);

                await _unitOfWork.Complete();

                var tempTestRecipeReviews = await _unitOfWork.RecipeReviews.GetByRecipeEager(1);

                testResultsRecipeReviews = tempTestRecipeReviews.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(1, testResultsRecipeReviews[0].Recipe.Id);
                Assert.Equal(5, testResultsRecipeReviews[0].Recipe.RecipeCookTime);
                Assert.Equal(1, testResultsRecipeReviews[1].Recipe.Id);
                Assert.Equal(5, testResultsRecipeReviews[1].Recipe.RecipeCookTime);
            }
        }
Example #4
0
        public async void TestCookbookGetByUserEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test7DB")
                          .Options;

            //Act
            List <Cookbook> testResultsCookbooks;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testRecipe = new Recipe
                {
                };

                var testCookbook = new Cookbook
                {
                    User   = testUser,
                    Recipe = testRecipe
                };

                var testCookbook2 = new Cookbook
                {
                    User   = testUser,
                    Recipe = testRecipe
                };

                await _unitOfWork.Cookbooks.Add(testCookbook);

                await _unitOfWork.Cookbooks.Add(testCookbook2);

                await _unitOfWork.Complete();

                var tempTestCookbooks = await _unitOfWork.Cookbooks.GetByUserEager(1);

                testResultsCookbooks = tempTestCookbooks.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(1, testResultsCookbooks[0].User.Id);
                Assert.Equal("TestPass", testResultsCookbooks[0].User.Password);
                Assert.Equal(1, testResultsCookbooks[1].User.Id);
                Assert.Equal("TestPass", testResultsCookbooks[1].User.Password);
            }
        }
Example #5
0
        public async void TestRIGAddRange()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test19DB")
                          .Options;

            //Act
            List <RecipeIngredientGroups> testRIGEntries = new List <RecipeIngredientGroups>();
            List <RecipeIngredientGroups> testResultsRIG;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testRecipe = new Recipe
                {
                    RecipeCookTime = 5
                };

                var testRIG = new RecipeIngredientGroups
                {
                    Recipe = testRecipe
                };

                var testRIG2 = new RecipeIngredientGroups
                {
                    Recipe = testRecipe
                };

                testRIGEntries.Add(testRIG);
                testRIGEntries.Add(testRIG2);

                _unitOfWork.RecipeIngredientGroups.AddRange(testRIGEntries);
                await _unitOfWork.Complete();

                var tempTestRecipeIngredientGroups = await _unitOfWork.RecipeIngredientGroups.GetAll();

                testResultsRIG = tempTestRecipeIngredientGroups.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.NotEmpty(testResultsRIG);
                Assert.Equal(1, testResultsRIG[0].Recipe.Id);
                Assert.Equal(5, testResultsRIG[0].Recipe.RecipeCookTime);
                Assert.Equal(1, testResultsRIG[1].Recipe.Id);
                Assert.Equal(5, testResultsRIG[1].Recipe.RecipeCookTime);
            }
        }
Example #6
0
        public async void TestRIGDeleteAll()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test16DB")
                          .Options;

            //Act
            List <RecipeIngredientGroups> rigElements;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testRecipe = new Recipe
                {
                };

                var testRIG = new RecipeIngredientGroups
                {
                    Recipe = testRecipe
                };

                var testRIG2 = new RecipeIngredientGroups
                {
                    Recipe = testRecipe
                };

                await _unitOfWork.RecipeIngredientGroups.Add(testRIG);

                await _unitOfWork.RecipeIngredientGroups.Add(testRIG2);

                await _unitOfWork.Complete();

                await _unitOfWork.RecipeIngredientGroups.DeleteAll(1);

                await _unitOfWork.Complete();

                var tempTestRIG = await _unitOfWork.RecipeIngredientGroups.GetAll();

                rigElements = tempTestRIG.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Empty(rigElements);
            }
        }
Example #7
0
        public async void TestReviewGetEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test10DB")
                          .Options;

            //Act
            RecipeReview testResultReview;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testRecipe = new Recipe
                {
                    RecipeCookTime    = 5,
                    RecipeInstruction = "Do the thing"
                };

                var testReview = new RecipeReview
                {
                    Recipe = testRecipe,
                    User   = testUser
                };

                //await _unitOfWork.Recipes.Add(testRecipe);
                await _unitOfWork.RecipeReviews.Add(testReview);

                await _unitOfWork.Complete();

                var tempTestReview = await _unitOfWork.RecipeReviews.GetEager(1);

                testResultReview = tempTestReview;
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(5, testResultReview.Recipe.RecipeCookTime);
            }
        }
Example #8
0
        public async void TestGenericGetAll()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test4DB")
                          .Options;

            //Act
            List <RecipeOrigin> testOrigins;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testOrigin = new RecipeOrigin
                {
                    RecipeOriginName = "Test1"
                };

                var testOrigin2 = new RecipeOrigin
                {
                    RecipeOriginName = "Test2"
                };

                await _unitOfWork.RecipeOrigins.Add(testOrigin);

                await _unitOfWork.RecipeOrigins.Add(testOrigin2);

                await _unitOfWork.Complete();

                var tempTestOrigins = await _unitOfWork.RecipeOrigins.GetAll();

                testOrigins = tempTestOrigins.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal("Test1", testOrigins[0].RecipeOriginName);
                Assert.Equal("Test2", testOrigins[1].RecipeOriginName);
            }
        }
Example #9
0
        public async void TestUserDelete()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test8DB")
                          .Options;

            //Act
            List <User> userElements;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                await _unitOfWork.Users.Add(testUser);

                await _unitOfWork.Complete();

                await _unitOfWork.Users.Delete(1);

                await _unitOfWork.Complete();

                var tempTestUsers = await _unitOfWork.Users.GetAll();

                userElements = tempTestUsers.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Empty(userElements);
            }
        }
Example #10
0
        public async void TestRecipeDelete()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test12DB")
                          .Options;

            //Act
            List <Recipe> recipeElements;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testRecipe = new Recipe
                {
                };

                await _unitOfWork.Recipes.Add(testRecipe);

                await _unitOfWork.Complete();

                await _unitOfWork.Recipes.Delete(1);

                await _unitOfWork.Complete();

                var tempTestRecipes = await _unitOfWork.Recipes.GetAll();

                recipeElements = tempTestRecipes.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Empty(recipeElements);
            }
        }
Example #11
0
        public async void TestCookbookDelete()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test5DB")
                          .Options;

            //Act
            List <Cookbook> cookbookElements;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testCookbook = new Cookbook
                {
                };

                await _unitOfWork.Cookbooks.Add(testCookbook);

                await _unitOfWork.Complete();

                _unitOfWork.Cookbooks.Delete(1);
                await _unitOfWork.Complete();

                var tempTestOrigins = await _unitOfWork.Cookbooks.GetAll();

                cookbookElements = tempTestOrigins.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Empty(cookbookElements);
            }
        }
Example #12
0
        public void TestUnitOfWork()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test0DB")
                          .Options;

            //Act

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                Assert.NotNull(_unitOfWork.Cookbooks);
                Assert.NotNull(_unitOfWork.Recipes);
                Assert.NotNull(_unitOfWork.RecipeIngredients);
                Assert.NotNull(_unitOfWork.RecipeIngredientGroups);
                Assert.NotNull(_unitOfWork.RecipeMeasurements);
                Assert.NotNull(_unitOfWork.RecipeOrigins);
                Assert.NotNull(_unitOfWork.RecipeReviews);
                Assert.NotNull(_unitOfWork.Users);
            }
        }
Example #13
0
 /// <summary>
 /// Constructor for the RecipeReview repository.
 /// </summary>
 /// <param name="context">The DbContext to be used in the repository.</param>
 public ReviewRepository(CookingpapaContext context) : base(context)
 {
 }
Example #14
0
 public UserRepository(CookingpapaContext context) : base(context)
 {
 }
Example #15
0
        public async void TestRIGGetByRecipeEager()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <CookingpapaContext>()
                          .UseInMemoryDatabase(databaseName: "Test18DB")
                          .Options;

            //Act
            List <RecipeIngredientGroups> testResultsRecipeIngredientGroups;

            using (var context = new CookingpapaContext(options))
            {
                var _unitOfWork = new UnitOfWork(context);

                var testUser = new User
                {
                    Username = "******",
                    Password = "******",
                    Email    = "*****@*****.**"
                };

                var testOrigin = new RecipeOrigin
                {
                    RecipeOriginName = "America"
                };

                var testRecipe = new Recipe
                {
                    RecipeCookTime = 5,
                    User           = testUser,
                    RecipeOrigin   = testOrigin
                };

                var testIngredient = new RecipeIngredient
                {
                    RecipeIngredientName = "TestIngredient"
                };

                var testMeasurement = new RecipeMeasurement
                {
                    RecipeMeasurementName = "TestMeasurement"
                };

                var testRIG = new RecipeIngredientGroups
                {
                    Recipe                 = testRecipe,
                    RecipeIngredient       = testIngredient,
                    RecipeMeasurement      = testMeasurement,
                    RecipeIngredientAmount = 5
                };

                var testRIG2 = new RecipeIngredientGroups
                {
                    Recipe                 = testRecipe,
                    RecipeIngredient       = testIngredient,
                    RecipeMeasurement      = testMeasurement,
                    RecipeIngredientAmount = 5
                };

                await _unitOfWork.RecipeIngredientGroups.Add(testRIG);

                await _unitOfWork.RecipeIngredientGroups.Add(testRIG2);

                await _unitOfWork.Complete();

                var tempTestRecipeIngredientGroups = await _unitOfWork.RecipeIngredientGroups.GetByRecipeEager(1);

                testResultsRecipeIngredientGroups = tempTestRecipeIngredientGroups.ToList();
            }

            //Assert
            using (var context = new CookingpapaContext(options))
            {
                Assert.Equal(1, testResultsRecipeIngredientGroups[0].Recipe.Id);
                Assert.Equal(5, testResultsRecipeIngredientGroups[0].Recipe.RecipeCookTime);
                Assert.Equal(1, testResultsRecipeIngredientGroups[1].Recipe.Id);
                Assert.Equal(5, testResultsRecipeIngredientGroups[1].Recipe.RecipeCookTime);
            }
        }
Example #16
0
 /// <summary>
 /// Constructor for the Recipe database table.
 /// </summary>
 /// <param name="context">The DbContext to be used to construct the repository.</param>
 public RecipeRepository(CookingpapaContext context) : base(context)
 {
 }
 /// <summary>
 /// Constructor for the RecipeIngredientGroups repository.
 /// </summary>
 /// <param name="context">The DbContext to be used in the repository.</param>
 public RecipeIngredientGroupRepository(CookingpapaContext context) : base(context)
 {
 }
Example #18
0
 /// <summary>
 /// Constructor for the Cookbook Repository.
 /// </summary>
 /// <param name="context">The DbContext to be used to build the repository.</param>
 public CookbookRepository(CookingpapaContext context) : base(context)
 {
 }