public static PleyContext Create() { // Create a fresh service provider, and therefore a fresh // InMemory database instance. var serviceProvider = new ServiceCollection() .AddEntityFrameworkInMemoryDatabase() .BuildServiceProvider(); var options = new DbContextOptionsBuilder <PleyContext>() .UseInMemoryDatabase("Test Database") .UseInternalServiceProvider(serviceProvider) .EnableSensitiveDataLogging() .Options; var context = new PleyContext(options); // Seeding the test context if (!context.Users.Any()) { context.Users.Add(Fixtures.reviewer1); context.Users.Add(Fixtures.reviewer2); context.Users.Add(Fixtures.owner1); context.Users.Add(Fixtures.owner2); } if (!context.Restaurants.Any()) { context.Restaurants.Add(Fixtures.restaurant1); context.Restaurants.Add(Fixtures.restaurant1); } if (!context.Reviews.Any()) { context.Reviews.Add(Fixtures.review1); context.Reviews.Add(Fixtures.review2); } context.SaveChanges(); return(context); }
public static ReviewService Create(PleyContext context) { var logger = new Mock <ILogger <ReviewService> >(); var restaurantSvc = RestaurantServiceFactory.Create(context); return(new ReviewService(context, restaurantSvc, logger.Object)); }
public ReviewService( PleyContext context, IRestaurantService svc, ILogger <ReviewService> logger ) { _dbContext = context; _logger = logger; _restaurantSvc = svc; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, PleyContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseRouting(); // app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseAuthentication(); app.UseAuthorization(); // Executes the endpoint that was selected by routing. app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseReactDevelopmentServer(npmScript: "start"); } }); DbInitializer.Initialize(context); }
public static void Initialize(PleyContext context) { context.Database.EnsureCreated(); if (!context.Users.Any()) { var hmac = new System.Security.Cryptography.HMACSHA512(); context.Users.Add(new User { FirstName = "Olivier", LastName = "Example", Email = "*****@*****.**", CreatedOn = DateTime.Now, ModifiedOn = DateTime.Now, Type = UserType.ADMIN, PasswordHash = hmac.ComputeHash(System.Text.Encoding.UTF8.GetBytes("password")), PasswordSalt = hmac.Key }); hmac.Dispose(); context.SaveChanges(); } }
public RestaurantServiceTest() { _ctx = PleyContextFactory.Create(); _svc = RestaurantServiceFactory.Create(_ctx); }
public RestaurantService(PleyContext context, ILogger <RestaurantService> logger) { _dbContext = context; _logger = logger; }
public UserService(PleyContext context, ILogger <UserService> logger) { _dbContext = context; _logger = logger; }
public static RestaurantService Create(PleyContext context) { var logger = new Mock <ILogger <RestaurantService> >(); return(new RestaurantService(context, logger.Object)); }