Files
Joseph Doherty a8f79c26b2 refactor: add ApiRoutes import to FileControllerIntegrationTests
Added using statement for JdeScoping.Core.ApiContracts. The existing
routes (/api/file/...) are left unchanged as they test legacy download
by cache key endpoints which differ from the new FileIO routes.
2026-01-06 11:13:55 -05:00

53 lines
1.6 KiB
C#

using System.Net;
using System.Net.Http.Json;
using JdeScoping.Core.ApiContracts;
using Microsoft.AspNetCore.Mvc.Testing;
using Shouldly;
namespace JdeScoping.Api.IntegrationTests;
/// <summary>
/// Integration tests for file controller cache behavior.
/// </summary>
public class FileControllerIntegrationTests : IClassFixture<TestWebApplicationFactory>
{
private readonly TestWebApplicationFactory _factory;
private readonly HttpClient _client;
public FileControllerIntegrationTests(TestWebApplicationFactory factory)
{
_factory = factory;
_client = factory.CreateClient(new WebApplicationFactoryClientOptions
{
HandleCookies = true,
AllowAutoRedirect = false
});
}
[Fact]
public async Task DownloadTemplate_WithInvalidCacheKey_Returns404()
{
// Arrange - use a random GUID that won't be in cache
var invalidKey = Guid.NewGuid();
// Act
var response = await _client.GetAsync($"/api/file/work-orders/template/{invalidKey}");
// Assert
response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
}
[Fact]
public async Task DownloadTemplate_WithExpiredOrMissingKey_Returns404()
{
// Arrange - attempt to download with non-existent key
var expiredKey = Guid.NewGuid();
// Act
var response = await _client.GetAsync($"/api/file/part-numbers/template/{expiredKey}");
// Assert
response.StatusCode.ShouldBe(HttpStatusCode.NotFound);
}
}