using System.Net;
using System.Net.Http.Json;
using JdeScoping.Core.ApiContracts;
using Microsoft.AspNetCore.Mvc.Testing;
using Shouldly;
namespace JdeScoping.Api.IntegrationTests;
///
/// Integration tests for file controller cache behavior.
///
public class FileControllerIntegrationTests : IClassFixture
{
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);
}
}