chore: init project

This commit is contained in:
cesnimda
2026-06-30 15:53:32 +02:00
commit f43ef5f945
94 changed files with 4405 additions and 0 deletions
@@ -0,0 +1,53 @@
using System.Net;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Xunit;
namespace InboxIntel.IntegrationTests;
/// <summary>
/// Test host that disables startup auto-migration so the factory boots without
/// a live PostgreSQL instance. The auth tests below never touch the database
/// (the challenge happens in middleware before any controller runs).
/// </summary>
public class TestAppFactory : WebApplicationFactory<Program>
{
protected override IHost CreateHost(IHostBuilder builder)
{
builder.ConfigureHostConfiguration(cfg => cfg.AddInMemoryCollection(new Dictionary<string, string?>
{
["Database:AutoMigrate"] = "false"
}));
return base.CreateHost(builder);
}
}
/// <summary>
/// Smoke tests proving the host boots and authorization is enforced. A fuller
/// suite would swap PostgreSQL for a Testcontainers instance and the Gmail
/// client for a fake, then exercise sync -> analytics end to end.
/// </summary>
public class AuthEndpointsTests : IClassFixture<TestAppFactory>
{
private readonly TestAppFactory _factory;
public AuthEndpointsTests(TestAppFactory factory) => _factory = factory;
[Fact]
public async Task Protected_endpoint_challenges_when_anonymous()
{
var client = _factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false });
var resp = await client.GetAsync("/api/v1/analytics/dashboard");
// Unauthenticated -> redirect to Google challenge (302) or 401.
resp.StatusCode.Should().BeOneOf(HttpStatusCode.Found, HttpStatusCode.Unauthorized);
}
[Fact]
public async Task Login_endpoint_is_anonymous()
{
var client = _factory.CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false });
var resp = await client.GetAsync("/api/v1/auth/login");
resp.StatusCode.Should().Be(HttpStatusCode.Redirect); // 302 to Google
}
}
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\InboxIntel.Api\InboxIntel.Api.csproj" />
</ItemGroup>
</Project>