HostBootSmokeTests.cs
2,117 bytes
| 1 | using System.Net; |
|---|---|
| 2 | using Microsoft.AspNetCore.Hosting; |
| 3 | using Microsoft.AspNetCore.Mvc.Testing; |
| 4 | |
| 5 | namespace SplitApp.WebApp.IntegrationTests; |
| 6 | |
| 7 | /// <summary> |
| 8 | /// Boots the full WebApp host in the "Testing" environment (which skips the |
| 9 | /// per-module Migrate calls) and verifies the public landing endpoints serve. |
| 10 | /// Proves DI composition across all three modules works end-to-end. |
| 11 | /// </summary> |
| 12 | public class HostBootSmokeTests : IClassFixture<WebApplicationFactory<Program>> |
| 13 | { |
| 14 | private readonly WebApplicationFactory<Program> _factory; |
| 15 | |
| 16 | public HostBootSmokeTests(WebApplicationFactory<Program> factory) |
| 17 | { |
| 18 | _factory = factory.WithWebHostBuilder(b => |
| 19 | { |
| 20 | b.UseEnvironment("Testing"); |
| 21 | b.UseSetting("ConnectionStrings:DefaultConnection", "Host=ignored;Database=ignored"); |
| 22 | b.UseSetting("JWT:Issuer", "splitapp-test"); |
| 23 | b.UseSetting("JWT:Audience", "splitapp-test"); |
| 24 | b.UseSetting("JWT:Key", "this-is-a-long-enough-test-signing-key-for-hs256"); |
| 25 | }); |
| 26 | } |
| 27 | |
| 28 | [Fact] |
| 29 | public async Task Get_Root_ReturnsOk() |
| 30 | { |
| 31 | var client = _factory.CreateClient(); |
| 32 | var response = await client.GetAsync("/"); |
| 33 | Assert.Equal(HttpStatusCode.OK, response.StatusCode); |
| 34 | var body = await response.Content.ReadAsStringAsync(); |
| 35 | Assert.Contains("SplitApp", body); |
| 36 | } |
| 37 | |
| 38 | [Fact] |
| 39 | public async Task Get_HomeIndex_RendersLandingPage() |
| 40 | { |
| 41 | var client = _factory.CreateClient(); |
| 42 | var response = await client.GetAsync("/Home/Index"); |
| 43 | Assert.Equal(HttpStatusCode.OK, response.StatusCode); |
| 44 | var body = await response.Content.ReadAsStringAsync(); |
| 45 | // Phase 2 home view content |
| 46 | Assert.Contains("SplitApp", body); |
| 47 | } |
| 48 | |
| 49 | [Fact] |
| 50 | public async Task Get_TripsApi_RequiresAuth() |
| 51 | { |
| 52 | var client = _factory.CreateClient(new WebApplicationFactoryClientOptions |
| 53 | { |
| 54 | AllowAutoRedirect = false, |
| 55 | }); |
| 56 | var response = await client.GetAsync("/api/v1/trips"); |
| 57 | Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode); |
| 58 | } |
| 59 | } |
| 60 | |