public AreasService(CookbookDbContext context, IMapper mapper, IUserContextService userContextService, IAuthorizationService authorizationService, IAreasRepository <Area> areasRepository) : base(context, mapper, userContextService, authorizationService) { _areasRepository = areasRepository; }
public CategoriesService(CookbookDbContext context, IMapper mapper, IUserContextService userContextService, IAuthorizationService authorizationService, ICategoriesRepository <Category> categoriesRepository) : base(context, mapper, userContextService, authorizationService) { _categoriesRepository = categoriesRepository; }
public IngredientsService(CookbookDbContext context, IMapper mapper, IUserContextService userContextService, IAuthorizationService authorizationService, IIngredientsRepository <Ingredient> ingredientsRepository) : base(context, mapper, userContextService, authorizationService) { _ingredientsRepository = ingredientsRepository; }
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); } }
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"); } }); }
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); } }
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); } }
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); } }
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); } }
public IngredientRepository(CookbookDbContext dbContext) { this.dbContext = dbContext; }
public RecipeTypeRepository(CookbookDbContext dbContext) { this.dbContext = dbContext; }
protected BaseRepository(CookbookDbContext context) { this._context = context; }
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; }
// 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(); } }
public ResipeController(CookbookDbContext db) { _db = db; }
public UnitOfWork(CookbookDbContext cookbookDbContext) { this.cookbookDbContext = cookbookDbContext; }
public CategorieController(CookbookDbContext db) { _db = db; }
public IngredientOperationHandler(CookbookDbContext context) { _context = context; }
public DatabaseForTestSeeder(CookbookDbContext context, PasswordHasher <User> passwordHasher) { _context = context; _passwordHasher = passwordHasher; }
public DishTypeRepository(CookbookDbContext dbContext) { this.dbContext = dbContext; }
public CommentsServices(CookbookDbContext context) { _context = context; }
public SearchService(CookbookDbContext context) { _context = context; }
public RecipeRepository(CookbookDbContext db) { _db = db; }
public RecipesService(IRecipesRepository <Recipe> recipesRepository, CookbookDbContext context, IMapper mapper, IUserContextService userContextService, IAuthorizationService authorizationService) : base(context, mapper, userContextService, authorizationService) { _recipesRepository = recipesRepository; }
public UsersRepository(CookbookDbContext _context) { cookbookDbContext = _context; }
public ProductController(CookbookDbContext db) { _db = db; }
public EfRepositoryBase(CookbookDbContext dbContext) { _dbContext = dbContext; }