u/Enguarde_

▲ 1 r/dotnet

Hello, I am a C# desktop application dev, I have a small personal projet of an Aspnet Core (Rasor) application

I wanna do E2E tests, for now just test the page title. My actual test (with Nunit and playwright) run well when I test the title of the google webpage. But I can't test my own app.

I've try to setup it in E2E Nunit setupfixture and then make a "Page.GotoAsync(localhost)" on it but I've got either :

System.InvalidOperationException : The static resources manifest file testhost.staticwebassets.endpoints.json' was not found.

When I try to lauch my app with the same code as Program.cs

OR

net::ERR_CONNECTION_REFUSED When I finnaly succed to build the app with an test overrided AppBuilder, which seems to me the cleanest way.

I'm a little bit confused on how to build WebApplication and run it in test with task and await stuff.

The playwright tutorials are mostly explaining framework by testing ulr "https://playwright.dev/dotnet/" so it doesnt help.

Here's the simple content of my Program.cs

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDbContext>();

// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();

using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
    db.Database.EnsureCreated();
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    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.UseRouting();
app.UseAuthorization();
app.MapStaticAssets();
app.MapRazorPages()
   .WithStaticAssets();
app.Run();var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDbContext>();

// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();

using (var scope = app.Services.CreateScope())
{
    var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
    db.Database.EnsureCreated();
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    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.UseRouting();
app.UseAuthorization();
app.MapStaticAssets();
app.MapRazorPages()
   .WithStaticAssets();
app.Run();
u/Enguarde_ — 17 days ago