// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MiniLinkContext context) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebAssemblyDebugging(); } else { // run migrations and ensure db is up to date context.Database.Migrate(); 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.UseHttpsRedirection(); app.UseBlazorFrameworkFiles(); app.UseStaticFiles(); app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); endpoints.MapControllers(); endpoints.MapFallbackToFile("index.html"); }); }
public async Task TestRead() { MiniLinkContext context = GetContext(); IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context); async Task ResetRepo() { context.Dispose(); context = GetContext(); linkRepo = new BaseRepository <LinkEntry>(context); return; } var entry = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow); var entry2 = new LinkEntry("https://www.facebook.com/", "", DateTime.UtcNow); await linkRepo.InsertAsync(entry); await linkRepo.InsertAsync(entry2); var save = await linkRepo.SaveChangesAsync(); await ResetRepo(); var readEntry = await linkRepo.GetByIdAsync(entry.Id); Assert.Equal(entry.Id, readEntry.Id); Assert.Equal(entry.URL, readEntry.URL); var readAll = await linkRepo.GetAllAsync(); Assert.Equal(2, readAll.Count); context.Dispose(); }
public async Task TestDelete() { MiniLinkContext context = GetContext(); IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context); async Task ResetRepo() { context.Dispose(); context = GetContext(); linkRepo = new BaseRepository <LinkEntry>(context); return; } var entry = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow); await linkRepo.InsertAsync(entry); await linkRepo.SaveChangesAsync(); await ResetRepo(); var entryToDelete = await linkRepo.GetByIdAsync(entry.Id); await linkRepo.DeleteAsync(entryToDelete); await linkRepo.SaveChangesAsync(); await ResetRepo(); var deletedEntry = await linkRepo.GetByIdAsync(entry.Id); Assert.True(deletedEntry == default(LinkEntry)); context.Dispose(); }
public MiniLinkContext GetContext() { var options = new DbContextOptionsBuilder <MiniLinkContext>().UseSqlite(_connection).Options; var context = new MiniLinkContext(options); context.Database.EnsureCreated(); return(context); }
public async Task TestInsert() { MiniLinkContext context = GetContext(); IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context); var entry = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow); var entry2 = new LinkEntry("https://www.facebook.com/", "", DateTime.UtcNow); await linkRepo.InsertAsync(entry); await linkRepo.InsertAsync(entry2); var save = await linkRepo.SaveChangesAsync(); Assert.Equal(2, save); context.Dispose(); }
public async Task TestInsertAndGetByBase64Id() { MiniLinkContext context = GetContext(); IBaseRepository <LinkEntry> linkRepo; IBaseRepository <LinkEntryVisit> linkVisitRepo; MemoryCacheOptions options; IMemoryCache cache; async Task <ILinkEntryService> SetupAsync() { context = GetContext(); linkRepo = new BaseRepository <LinkEntry>(context); linkVisitRepo = new BaseRepository <LinkEntryVisit>(context); var options = new MemoryCacheOptions(); IMemoryCache cache = new MemoryCache(options); return(new LinkEntryService(linkRepo, linkVisitRepo, cache)); } ILinkEntryService linkEntryService = await SetupAsync(); var url = "https://www.google.com/"; var add = await linkEntryService.AddLinkEntry(url, ""); Assert.True(add.Success); // reset context to ensue ef doesnt keep the results context.Dispose(); linkEntryService = await SetupAsync(); var fetch = await linkEntryService.GetLinkEntryByBase64Id(add.Entry.Base64Id, true); Assert.Equal(fetch.URL, url); context.Dispose(); }
public async Task TestUpdate() { MiniLinkContext context = GetContext(); IBaseRepository <LinkEntry> linkRepo = new BaseRepository <LinkEntry>(context); async Task ResetRepo() { context.Dispose(); context = GetContext(); linkRepo = new BaseRepository <LinkEntry>(context); return; } var entry = new LinkEntry("https://www.google.com/", "", DateTime.UtcNow); await linkRepo.InsertAsync(entry); var save = await linkRepo.SaveChangesAsync(); await ResetRepo(); var readEntry = await linkRepo.GetByIdAsync(entry.Id); readEntry.Visits = 5; await linkRepo.UpdateAsync(readEntry); await linkRepo.SaveChangesAsync(); await ResetRepo(); var updatedEntry = await linkRepo.GetByIdAsync(entry.Id); Assert.Equal(readEntry.Visits, updatedEntry.Visits); Assert.True(entry.Visits != updatedEntry.Visits); context.Dispose(); }
public BaseRepository(MiniLinkContext context) { _context = context; }