Test Entity Framework
This commit is contained in:
@ -3,6 +3,7 @@ using System.Text;
|
||||
using System.Text.Json.Nodes;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using USEntryCoach.Server.Data;
|
||||
using USEntryCoach.Server.Services;
|
||||
@ -53,6 +54,9 @@ builder.Services.AddAuthorization(options =>
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddDbContext<BloggingContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseAuthentication();
|
||||
@ -176,4 +180,29 @@ app.MapGet("/ephemeral_token", async () =>
|
||||
|
||||
app.MapFallbackToFile("/index.html");
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
|
||||
var context = services.GetRequiredService<BloggingContext>();
|
||||
context.Database.EnsureCreated();
|
||||
|
||||
Blog b = new()
|
||||
{
|
||||
Url = "BLa"
|
||||
};
|
||||
|
||||
Post p = new()
|
||||
{
|
||||
Blog = b,
|
||||
Content = "sd zgsödiog söffdgkjasödfl kjasdfökljasdfölasddj föadj kfö",
|
||||
Title = "Hallo Welt"
|
||||
};
|
||||
|
||||
b.Posts.Add(p);
|
||||
|
||||
context.Blogs.Add(b);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user