示例#1
0
 public AreasService(CookbookDbContext context, IMapper mapper,
                     IUserContextService userContextService, IAuthorizationService authorizationService,
                     IAreasRepository <Area> areasRepository)
     : base(context, mapper, userContextService, authorizationService)
 {
     _areasRepository = areasRepository;
 }
示例#2
0
 public CategoriesService(CookbookDbContext context, IMapper mapper,
                          IUserContextService userContextService, IAuthorizationService authorizationService,
                          ICategoriesRepository <Category> categoriesRepository)
     : base(context, mapper, userContextService, authorizationService)
 {
     _categoriesRepository = categoriesRepository;
 }
示例#3
0
 public IngredientsService(CookbookDbContext context, IMapper mapper,
                           IUserContextService userContextService, IAuthorizationService authorizationService,
                           IIngredientsRepository <Ingredient> ingredientsRepository)
     : base(context, mapper, userContextService, authorizationService)
 {
     _ingredientsRepository = ingredientsRepository;
 }
示例#4
0
        public async void CanUpdateSavedRecipe()
        {
            DbContextOptions <CookbookDbContext> options = new DbContextOptionsBuilder <CookbookDbContext>().UseInMemoryDatabase("CanUpdateSavedRecipe").Options;

            using (CookbookDbContext context = new CookbookDbContext(options))
            {
                SavedRecipe savedRecipe = new SavedRecipe();
                savedRecipe.SavedRecipeID = 1;
                savedRecipe.Name          = "Chicken";
                savedRecipe.APIReference  = 2;
                savedRecipe.UserID        = 2;

                savedRecipe.Name         = "Pork";
                savedRecipe.APIReference = 3;
                savedRecipe.UserID       = 3;

                SavedRecipeService savedRecipeService = new SavedRecipeService(context);

                await savedRecipeService.CreateRecipe(savedRecipe);

                await savedRecipeService.UpdateSavedRecipe(savedRecipe);

                var result = context.SavedRecipe.FirstOrDefault(s => s.SavedRecipeID == s.SavedRecipeID);

                Assert.Equal(savedRecipe, result);
            }
        }
示例#5
0
 public MealDbSeeder(CookbookDbContext context, IMealApiClient client,
                     IMapper autoMapper, IDtoToEntityMapper <MealRecipeDto, Recipe> recipeMapper)
 {
     _context      = context;
     _client       = client;
     _autoMapper   = autoMapper;
     _recipeMapper = recipeMapper;
 }
        public RecipeRequestValidator(CookbookDbContext dbContext)
        {
            RuleFor(x => x.AreaId)
            .CustomAsync(async(value, context, cancellation) =>
            {
                if (value == null)
                {
                    return;
                }

                var areaExist = await dbContext.Areas.AnyAsync(x => x.Id == value);
                if (!areaExist)
                {
                    context.AddFailure("AreaId", "This area doesn't exist");
                }
            });

            RuleFor(x => x.CategoryId)
            .CustomAsync(async(value, context, cancellation) =>
            {
                if (value == null)
                {
                    return;
                }

                var categoryExist = await dbContext.Categories.AnyAsync(x => x.Id == value);
                if (!categoryExist)
                {
                    context.AddFailure("CategoryId", "This category doesn't exist");
                }
            });

            RuleFor(x => x.Ingredients)
            .NotEmpty()
            .CustomAsync(async(ingredients, context, cancellation) =>
            {
                var ingredientIdsFromRequest = ingredients.Select(x => x.IngredientId);

                var matchingIngredientIds = await dbContext.Ingredients.Where(
                    x => ingredientIdsFromRequest.Contains(x.Id)).Select(x => x.Id).ToListAsync();

                if (matchingIngredientIds.Count == ingredients.Count)
                {
                    return;
                }

                var noMatchingIds = ingredientIdsFromRequest.Where(x => !matchingIngredientIds.Contains(x)).ToArray();

                if (noMatchingIds.Any())
                {
                    context.AddFailure("Ingredients",
                                       $"Ingredients with id: {string.Join(" ", noMatchingIds)} don't exist");
                }
            });
        }
示例#7
0
        public async void CanCreateUser()
        {
            DbContextOptions <CookbookDbContext> options = new DbContextOptionsBuilder <CookbookDbContext>().UseInMemoryDatabase("CanCreateUser").Options;

            using (CookbookDbContext context = new CookbookDbContext(options))
            {
                User user = new User();
                user.ID       = 1;
                user.UserName = "******";

                UserService userService = new UserService(context);

                await userService.CreateUser(user);

                var result = context.User.FirstOrDefault(u => u.ID == u.ID);

                Assert.Equal(user, result);
            }
        }
示例#8
0
        public async void CanCreateComments()
        {
            DbContextOptions <CookbookDbContext> options = new DbContextOptionsBuilder <CookbookDbContext>().UseInMemoryDatabase("CanCreateComments").Options;

            using (CookbookDbContext context = new CookbookDbContext(options))
            {
                Comments comments = new Comments();
                comments.ID            = 1;
                comments.APIReference  = 2;
                comments.SavedRecipeID = 3;
                comments.Comment       = "So delish";

                CommentsServices commentsServices = new CommentsServices(context);

                await commentsServices.CreateComment(comments);

                var result = context.Comments.FirstOrDefault(c => c.ID == comments.ID);

                Assert.Equal(comments, result);
            }
        }
示例#9
0
        public void CreateSavedRecipeExists()
        {
            DbContextOptions <CookbookDbContext> options = new DbContextOptionsBuilder <CookbookDbContext>().UseInMemoryDatabase("CreateSavedRecipeExists").Options;

            using (CookbookDbContext context = new CookbookDbContext(options))
            {
                SavedRecipe savedRecipe = new SavedRecipe();
                savedRecipe.SavedRecipeID = 1;
                savedRecipe.Name          = "Chicken";
                savedRecipe.APIReference  = 2;
                savedRecipe.UserID        = 2;

                SavedRecipeService savedRecipeService = new SavedRecipeService(context);

                savedRecipeService.SavedRecipeExists(1);

                var result = context.SavedRecipe.Any(s => s.SavedRecipeID == 1);

                Assert.False(result);
            }
        }
示例#10
0
        public async void CanSaveRecipe()
        {
            DbContextOptions <CookbookDbContext> options = new DbContextOptionsBuilder <CookbookDbContext>().UseInMemoryDatabase("CanSaveSearchRecipe").Options;

            using (CookbookDbContext context = new CookbookDbContext(options))
            {
                Recipe testRecipe = new Recipe();
                testRecipe.ID   = 1;
                testRecipe.Name = "Peaches and Cream";

                User user = new User();
                user.ID       = 1;
                user.UserName = "******";

                UserService userService = new UserService(context);

                await userService.CreateUser(user);

                SearchService searchServ   = new SearchService(context);
                var           recipeResult = await searchServ.SaveRecipe(testRecipe.ID, user.UserName, testRecipe.Name);

                Assert.Equal(1, recipeResult.SavedRecipeID);
            }
        }
示例#11
0
 public IngredientRepository(CookbookDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#12
0
 public RecipeTypeRepository(CookbookDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#13
0
 protected BaseRepository(CookbookDbContext context)
 {
     this._context = context;
 }
示例#14
0
 public CookingTypeRepository(CookbookDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public RecipeRepository(CookbookDbContext cookbookDbContext)
 {
     this.cookbookDbContext = cookbookDbContext;
 }
 public MealRecipeDtoToRecipeMapper(CookbookDbContext context, ILogger <MealRecipeDtoToRecipeMapper> logger)
 {
     _context = context;
     _logger  = logger;
 }
示例#17
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISeeder seeder, CookbookDbContext context)
        {
            app.UseCors(builder =>
                        builder
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader()
                        );

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMiddleware <ErrorHandlingMiddleware>();

            app.UseMiddleware <RequestTimeMiddleware>();

            app.UseAuthentication();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseOpenApi(options =>
            {
                options.DocumentName = "swagger";
                options.Path         = "/swagger/v1/swagger.json";
                options.PostProcess  = (document, _) =>
                {
                    document.Schemes.Add(OpenApiSchema.Https);
                };
            });

            app.UseSwaggerUi3(options =>
            {
                options.DocumentPath = "/swagger/v1/swagger.json";
            });


            if (context.Database.ProviderName != "Microsoft.EntityFrameworkCore.InMemory")
            {
                ConfigureAsync(seeder).Wait();
            }
        }
示例#18
0
 public ResipeController(CookbookDbContext db)
 {
     _db = db;
 }
示例#19
0
 public UnitOfWork(CookbookDbContext cookbookDbContext)
 {
     this.cookbookDbContext = cookbookDbContext;
 }
示例#20
0
 public CategorieController(CookbookDbContext db)
 {
     _db = db;
 }
示例#21
0
 public IngredientOperationHandler(CookbookDbContext context)
 {
     _context = context;
 }
示例#22
0
 public DatabaseForTestSeeder(CookbookDbContext context, PasswordHasher <User> passwordHasher)
 {
     _context        = context;
     _passwordHasher = passwordHasher;
 }
示例#23
0
 public DishTypeRepository(CookbookDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#24
0
 public CommentsServices(CookbookDbContext context)
 {
     _context = context;
 }
示例#25
0
 public SearchService(CookbookDbContext context)
 {
     _context = context;
 }
示例#26
0
 public RecipeRepository(CookbookDbContext db)
 {
     _db = db;
 }
示例#27
0
 public RecipesService(IRecipesRepository <Recipe> recipesRepository, CookbookDbContext context,
                       IMapper mapper, IUserContextService userContextService, IAuthorizationService authorizationService)
     : base(context, mapper, userContextService, authorizationService)
 {
     _recipesRepository = recipesRepository;
 }
示例#28
0
 public UsersRepository(CookbookDbContext _context)
 {
     cookbookDbContext = _context;
 }
示例#29
0
 public ProductController(CookbookDbContext db)
 {
     _db = db;
 }
示例#30
0
 public EfRepositoryBase(CookbookDbContext dbContext)
 {
     _dbContext = dbContext;
 }