public RecipesService(RecipesContext context, ILogger <RecipesService> logger, IMediaLogicHelper mediaHelper, IMapper mapper) { this.Context = context ?? throw new ArgumentNullException(nameof(context)); this.MediaHelper = mediaHelper; this.Entities = this.Context.Set <Recipe>() ?? throw new ArgumentNullException(nameof(context)); this._logger = logger; this._mapper = mapper; try { context.Database.EnsureCreated(); } catch (Exception e) { this._logger.LogError($"Database isn't reachable. Exception: {e.InnerException}", e); throw e; } }
public void Setup() { this._loggerMock = new Mock <ILogger <RecipesService> >(); var workingDirectory = Environment.CurrentDirectory; this._mediasPath = Path.Combine(workingDirectory, "TestData"); var mapperConfig = new MapperConfiguration(cfg => { cfg.AddProfile(new OrganizationProfile()); }); this._mapper = mapperConfig.CreateMapper(); this._configuration = new Mock <IConfiguration>(); this._configuration.SetupGet(c => c["MediasSettings:BasePath"]).Returns(this._mediasPath); this._configuration.SetupGet(c => c["MediasSettings:ImagesDirectory"]).Returns(this._imagesDirectory); this._configuration.SetupGet(c => c["MediasSettings:MaxImageSize"]).Returns(Convert.ToString(MAX_IMAGESIZE)); this._mediaHelper = new MediaLogicHelper(this._configuration.Object, new Mock <ILogger <MediaLogicHelper> >().Object); //this._savedMediasPath = Path.Combine(workingDirectory, "TestData", "Saved"); // TODO: rethink this. It will then need UserId/RecipeId //this._mediaHelper.SetupGet(h => h.UserMediasPath).Returns("C:\\Users\\Manon\\Programming\\Apps\\Recipes\\Media\\2301\\RecipeImages\\SpinashTart"); //this._mediaHelper.SetupGet(h => h.UserMediasPath).Returns(this._savedMediasPath); }