public void IncrementPriorityCount(Guid userId, Guid productId)
        {
            PriorityUserProduct priorityUserProduct = _context.PriorityUserProducts
                                                      .Where(pup => pup.UserId == userId && pup.ProductId == productId)
                                                      .FirstOrDefault();

            if (priorityUserProduct != null)
            {
                priorityUserProduct.Count += 1;
            }
            else
            {
                priorityUserProduct = new PriorityUserProduct
                {
                    Id        = Guid.NewGuid(),
                    UserId    = userId,
                    ProductId = productId,
                    Count     = 1
                };
                _context.PriorityUserProducts.Add(priorityUserProduct);
            }

            Save();
        }
        private void InitFields()
        {
            user1 = new User
            {
                Id    = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD"),
                Name  = "TestUser1",
                Email = "*****@*****.**"
            };
            fridge1 = new Fridge
            {
                Id     = Guid.NewGuid(),
                UserId = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };

            user2 = new User
            {
                Id    = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD"),
                Name  = "TestUser2",
                Email = "*****@*****.**"
            };
            fridge2 = new Fridge
            {
                Id     = Guid.NewGuid(),
                UserId = Guid.Parse("B71DBC28-AAAA-47B1-8A2A-C6A5BFCD78AD")
            };

            productCategory1 = new ProductCategory
            {
                Id   = Guid.Parse("A5ADA8E6-04E1-49CA-A701-1265E216D69A"),
                Name = "Product Category 1"
            };
            productCategory2 = new ProductCategory
            {
                Id   = Guid.Parse("94CAE204-3337-43FA-8C0E-24C927BACAC4"),
                Name = "Product Category 2"
            };
            productCategory3 = new ProductCategory
            {
                Id   = Guid.NewGuid(),
                Name = "Product Category 3"
            };

            product1 = new BasicProduct
            {
                Id                = Guid.Parse("9C750539-3CA6-4239-941F-805B81C38CD4"),
                Name              = "Salmon",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };
            product2 = new BasicProduct
            {
                Id                = Guid.Parse("9D8FAC6F-C194-44E5-A6D5-B6F6DBDEBBD0"),
                Name              = "Mustard",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };
            product3 = new BasicProduct
            {
                Id                = Guid.Parse("F1F5610D-F065-46D8-9208-D7D1A0CB8C27"),
                Name              = "Brown Sugar",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };

            product4 = new BasicProduct
            {
                Id                = Guid.Parse("06BBED64-A505-492C-889B-472F7DAB0FAA"),
                Name              = "Butter",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };
            product5 = new BasicProduct
            {
                Id                = Guid.Parse("270B1180-45C6-4EE1-BC06-4819743859DC"),
                Name              = "Cream",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };
            product6 = new BasicProduct
            {
                Id                = Guid.Parse("002D754C-176B-4324-A42E-2DC32369074D"),
                Name              = "Eggs",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };

            newProduct1 = new NewProduct
            {
                Id                = Guid.NewGuid(),
                Name              = "New product 1",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = firstUserGuid
            };
            newProduct2 = new NewProduct
            {
                Id                = Guid.NewGuid(),
                Name              = "New product 2",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };
            newProduct3 = new NewProduct
            {
                Id                = Guid.NewGuid(),
                Name              = "New product 3",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };

            recipe1 = new Recipe
            {
                Id          = Guid.Parse("83BD2A25-83EA-47D0-9B7B-0E4D528CF8C2"),
                Description = "",
                Title       = "Salmon recipe",
                UserId      = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };
            recipe2 = new Recipe
            {
                Id          = Guid.Parse("F795B317-DB3B-469F-9891-62C5CCC9DF5D"),
                Description = "",
                Title       = "Scrambled eggs",
                UserId      = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };

            recipe1Product1 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe1.Id,
                ProductId = product1.Id
            };
            recipe1Product2 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe1.Id,
                ProductId = product2.Id
            };
            recipe1Product3 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe1.Id,
                ProductId = product3.Id
            };
            recipe2Product4 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe2.Id,
                ProductId = product4.Id
            };
            recipe2Product5 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe2.Id,
                ProductId = product5.Id
            };
            recipe2Product6 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe2.Id,
                ProductId = product6.Id
            };

            fridge1Product1 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product1.Id
            };
            fridge1Product2 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product2.Id
            };
            fridge1Product3 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product3.Id
            };
            fridge1Product4 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product4.Id
            };
            fridge1Product5 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product5.Id
            };
            fridge1Product6 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product6.Id
            };

            tag1 = new Tag
            {
                Id         = Guid.NewGuid(),
                Text       = "tag1",
                RecipeTags = new List <RecipeTag>()
            };
            tag2 = new Tag
            {
                Id         = Guid.NewGuid(),
                Text       = "tag2",
                RecipeTags = new List <RecipeTag>()
            };
            tag3 = new Tag
            {
                Id         = Guid.NewGuid(),
                Text       = "tag3",
                RecipeTags = new List <RecipeTag>()
            };

            recipe1tag1 = new RecipeTag
            {
                Id       = Guid.NewGuid(),
                TagId    = tag1.Id,
                RecipeId = recipe1.Id
            };
            recipe1tag2 = new RecipeTag
            {
                Id       = Guid.NewGuid(),
                TagId    = tag1.Id,
                RecipeId = recipe1.Id
            };
            recipe2tag3 = new RecipeTag
            {
                Id       = Guid.NewGuid(),
                TagId    = tag1.Id,
                RecipeId = recipe1.Id
            };

            recipe1.RecipeProducts = new List <RecipeProduct>
            {
                recipe1Product1,
                recipe1Product2,
                recipe1Product3
            };
            recipe1.RecipeTags = new List <RecipeTag> {
                recipe1tag1,
                recipe1tag2
            };

            recipe2.RecipeProducts = new List <RecipeProduct>();
            recipe2.RecipeTags     = new List <RecipeTag>
            {
                recipe2tag3
            };

            tempUpdatingRecipe = new Recipe
            {
                RecipeProducts = new List <RecipeProduct>(),
                RecipeTags     = new List <RecipeTag> {
                }
            };

            recipesList = new List <Recipe>
            {
                recipe1,
                recipe2
            };

            user1product1 = new PriorityUserProduct
            {
                Id        = Guid.NewGuid(),
                ProductId = product1.Id,
                UserId    = firstUserGuid
            };
            user2product4 = new PriorityUserProduct
            {
                Id        = Guid.NewGuid(),
                ProductId = product4.Id,
                UserId    = secondUserGuid
            };
            user2product5 = new PriorityUserProduct
            {
                Id        = Guid.NewGuid(),
                ProductId = product5.Id,
                UserId    = secondUserGuid
            };

            productsRepositoryReturnList = new List <Product>
            {
                product1, product2, product3, product4, product5, product6, newProduct1, newProduct2, newProduct3
            };
            priorityRepositoryReturnList = new List <PriorityUserProduct>
            {
                user1product1, user2product4, user2product5
            };

            productsRepositoryMock = new Mock <IProductsRepository>();
            productsRepositoryMock.Setup(rr => rr.GetAllProductsForUser(It.IsAny <Guid>()))
            .Returns <Guid>(g =>
            {
                return(productsRepositoryReturnList.Where(p => p.UserId == g));
            });
            priorityUserProductsRespositoryMock = new Mock <IPriorityUserProductsRepository>();
            priorityUserProductsRespositoryMock.Setup(rr => rr.GetAllPriorityUserProducts())
            .Returns(priorityRepositoryReturnList);
        }
        private FoodNetDbContext GetContextWithData()
        {
            var options = new DbContextOptionsBuilder <FoodNetDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var ctx = new FoodNetDbContext(options);

            user1 = new User
            {
                Id    = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD"),
                Name  = "TestUser1",
                Email = "*****@*****.**"
            };
            fridge1 = new Fridge
            {
                Id     = Guid.NewGuid(),
                UserId = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };

            user2 = new User
            {
                Id    = Guid.NewGuid(),
                Name  = "TestUser2",
                Email = "*****@*****.**"
            };
            fridge2 = new Fridge
            {
                Id     = Guid.NewGuid(),
                UserId = Guid.Parse("B71DBC28-AAAA-47B1-8A2A-C6A5BFCD78AD")
            };

            productCategory1 = new ProductCategory
            {
                Id   = Guid.Parse("A5ADA8E6-04E1-49CA-A701-1265E216D69A"),
                Name = "Product Category 1"
            };
            productCategory2 = new ProductCategory
            {
                Id   = Guid.Parse("94CAE204-3337-43FA-8C0E-24C927BACAC4"),
                Name = "Product Category 2"
            };
            productCategory3 = new ProductCategory
            {
                Id   = Guid.NewGuid(),
                Name = "Product Category 3"
            };

            product1 = new BasicProduct
            {
                Id                = Guid.Parse("9C750539-3CA6-4239-941F-805B81C38CD4"),
                Name              = "Salmon",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };
            product2 = new BasicProduct
            {
                Id                = Guid.Parse("9D8FAC6F-C194-44E5-A6D5-B6F6DBDEBBD0"),
                Name              = "Mustard",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };
            product3 = new BasicProduct
            {
                Id                = Guid.Parse("F1F5610D-F065-46D8-9208-D7D1A0CB8C27"),
                Name              = "Brown Sugar",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };

            product4 = new BasicProduct
            {
                Id                = Guid.Parse("06BBED64-A505-492C-889B-472F7DAB0FAA"),
                Name              = "Butter",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };
            product5 = new BasicProduct
            {
                Id                = Guid.Parse("270B1180-45C6-4EE1-BC06-4819743859DC"),
                Name              = "Cream",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };
            product6 = new BasicProduct
            {
                Id                = Guid.Parse("002D754C-176B-4324-A42E-2DC32369074D"),
                Name              = "Eggs",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };

            newProduct1 = new NewProduct
            {
                Id                = Guid.NewGuid(),
                Name              = "New product 1",
                Description       = "",
                ProductCategoryId = productCategory1.Id,
                UserId            = firstUserGuid
            };
            newProduct2 = new NewProduct
            {
                Id                = Guid.NewGuid(),
                Name              = "New product 2",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };
            newProduct3 = new NewProduct
            {
                Id                = Guid.NewGuid(),
                Name              = "New product 3",
                Description       = "",
                ProductCategoryId = productCategory2.Id,
                UserId            = secondUserGuid
            };

            recipe1 = new Recipe
            {
                Id          = Guid.Parse("83BD2A25-83EA-47D0-9B7B-0E4D528CF8C2"),
                Description = "",
                Title       = "Salmon recipe",
                UserId      = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };
            recipe2 = new Recipe
            {
                Id          = Guid.Parse("F795B317-DB3B-469F-9891-62C5CCC9DF5D"),
                Description = "",
                Title       = "Scrambled eggs",
                UserId      = Guid.Parse("B71DBC28-6A02-47B1-8A2A-C6A5BFCD78AD")
            };

            recipe1Product1 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe1.Id,
                ProductId = product1.Id
            };
            recipe1Product2 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe1.Id,
                ProductId = product2.Id
            };
            recipe1Product3 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe1.Id,
                ProductId = product3.Id
            };
            recipe2Product4 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe2.Id,
                ProductId = product4.Id
            };
            recipe2Product5 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe2.Id,
                ProductId = product5.Id
            };
            recipe2Product6 = new RecipeProduct
            {
                Id        = Guid.NewGuid(),
                RecipeId  = recipe2.Id,
                ProductId = product6.Id
            };

            fridge1Product1 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product1.Id
            };
            fridge1Product2 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product2.Id
            };
            fridge1Product3 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product3.Id
            };
            fridge1Product4 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product4.Id
            };
            fridge1Product5 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product5.Id
            };
            fridge1Product6 = new FridgeProduct
            {
                Id        = Guid.NewGuid(),
                FridgeId  = fridge1.Id,
                ProductId = product6.Id
            };

            priorityUserProduct1 = new PriorityUserProduct
            {
                UserId    = firstUserGuid,
                ProductId = product1.Id,
                Count     = 0
            };

            ctx.ProductCategories.Add(productCategory1);
            ctx.ProductCategories.Add(productCategory2);
            ctx.ProductCategories.Add(productCategory3);

            ctx.Products.Add(product1);
            ctx.Products.Add(product2);
            ctx.Products.Add(product3);
            ctx.Products.Add(product4);
            ctx.Products.Add(product5);
            ctx.Products.Add(product6);

            ctx.Products.Add(newProduct1);
            ctx.Products.Add(newProduct2);
            ctx.Products.Add(newProduct3);

            ctx.Recipes.Add(recipe1);
            ctx.Recipes.Add(recipe2);

            ctx.RecipeProducts.Add(recipe1Product1);
            ctx.RecipeProducts.Add(recipe1Product2);
            ctx.RecipeProducts.Add(recipe1Product3);
            ctx.RecipeProducts.Add(recipe2Product4);
            ctx.RecipeProducts.Add(recipe2Product5);
            ctx.RecipeProducts.Add(recipe2Product6);

            ctx.Users.Add(user1);
            ctx.Users.Add(user2);

            ctx.Fridges.Add(fridge1);
            ctx.Fridges.Add(fridge2);


            ctx.SaveChanges();

            return(ctx);
        }