private async Task <FindMyTutorWebContext> GetContext() { var options = new DbContextOptionsBuilder <FindMyTutorWebContext>() .UseInMemoryDatabase(databaseName: "FindMyTutor_InMemory_Database") .Options; var context = new FindMyTutorWebContext(options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var reportedComment = new ReportedComment { Id = 122, ReporterId = "a", ResourceCreatorId = "b" }; var reportedOffer = new ReportedOffer { Id = 112, ReporterId = "a", ResourceCreatorId = "n" }; context.ReportedComment.Add(reportedComment); context.ReportedOffers.Add(reportedOffer); await context.SaveChangesAsync(); return(context); }
public async Task SeedAsync(FindMyTutorWebContext dbContext, IServiceProvider serviceProvider) { if (dbContext == null) { throw new ArgumentNullException(nameof(dbContext)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(ApplicationDbContextSeeder)); var seeders = new List <ISeeder> { //new RolesSeeder(), //new SettingsSeeder(), }; foreach (var seeder in seeders) { await seeder.SeedAsync(dbContext, serviceProvider); await dbContext.SaveChangesAsync(); logger.LogInformation($"Seeder {seeder.GetType().Name} done."); } }
private async Task <FindMyTutorWebContext> GetContext() { var options = new DbContextOptionsBuilder <FindMyTutorWebContext>() .UseInMemoryDatabase(databaseName: "FindMyTutor_InMemory_Database") .Options; var context = new FindMyTutorWebContext(options); context.Comments.AddRange(comments); int a = await context.SaveChangesAsync(); return(context); }
//Task<int> AddOffer(OfferDTO offer); //Task<int> RemoveOffer(int id); private async Task <FindMyTutorWebContext> GetContext() { var options = new DbContextOptionsBuilder <FindMyTutorWebContext>() .UseInMemoryDatabase(databaseName: "FindMyTutor_InMemory_Database") .EnableSensitiveDataLogging() .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options ; var context = new FindMyTutorWebContext(options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var offers = new Offer[] { new Offer { Id = 72, TutorId = "a", Description = "Very cool", Title = "Math lessons" }, new Offer { Id = 22, TutorId = "b", Description = "Very cool indeed", Title = "Lit lessons" }, new Offer { Id = 32, TutorId = "a", Description = "Amazing", Title = "Algebra lessons" }, new Offer { Id = 42, TutorId = "b", Description = "Ghastly", Title = "Vazov lessons" } }; context.Offers.AddRange(offers); int a = await context.SaveChangesAsync(); return(context); }
private async Task <FindMyTutorWebContext> GetContext() { var options = new DbContextOptionsBuilder <FindMyTutorWebContext>() .UseInMemoryDatabase(databaseName: "FindMyTutor_InMemory_Database") .EnableSensitiveDataLogging() .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .Options ; var context = new FindMyTutorWebContext(options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var messages = new Message[] { new Message { Id = 72, SenderId = "a", ReceiverId = "b", Content = "ab" }, new Message { Id = 72, SenderId = "b", ReceiverId = "a", Content = "absss" }, new Message { Id = 72, SenderId = "e", ReceiverId = "d", Content = "asas" }, new Message { Id = 72, SenderId = "r", ReceiverId = "e", Content = "asasa" }, }; context.Messages.AddRange(messages); int a = await context.SaveChangesAsync(); return(context); }