Compare commits

..

No commits in common. "b36b69df83f9caedf2f8ce11d3122d8795eec01e" and "ad5d58437c8fc1be7446b66e30cb562c0557aaaa" have entirely different histories.

2 changed files with 6 additions and 17 deletions

View file

@ -31,7 +31,7 @@ public class WorkOrderMediaControllerTests
}
[Fact]
public void AddMedia_HasTwoHundredMegabyteRequestLimit()
public void AddMedia_HasFiftyMegabyteRequestLimit()
{
var method = typeof(WorkOrderMediaController).GetMethod(nameof(WorkOrderMediaController.AddMedia));
var attribute = Assert.Single(
@ -39,24 +39,14 @@ public class WorkOrderMediaControllerTests
candidate => candidate.AttributeType == typeof(RequestSizeLimitAttribute));
var bytes = Assert.Single(attribute.ConstructorArguments);
Assert.Equal(200_000_000L, bytes.Value);
}
[Fact]
public void AddMedia_HasTwoHundredMegabyteMultipartBodyLimit()
{
var method = typeof(WorkOrderMediaController).GetMethod(nameof(WorkOrderMediaController.AddMedia));
var attribute = Assert.IsType<RequestFormLimitsAttribute>(Assert.Single(
method!.GetCustomAttributes(typeof(RequestFormLimitsAttribute), inherit: true)));
Assert.Equal(200_000_000L, attribute.MultipartBodyLengthLimit);
Assert.Equal(50_000_000L, bytes.Value);
}
[Fact]
public async Task AddMedia_FileOverLimit_ReturnsStableUnprocessableEntity()
{
var file = new Mock<IFormFile>();
file.SetupGet(candidate => candidate.Length).Returns(200_000_001);
file.SetupGet(candidate => candidate.Length).Returns(50_000_001);
var storage = new Mock<IFileStoragePort>(MockBehavior.Strict);
var controller = CreateController(storage: storage);
@ -65,7 +55,7 @@ public class WorkOrderMediaControllerTests
var response = Assert.IsType<UnprocessableEntityObjectResult>(result);
var error = Assert.IsType<WorkOrderBoardValidationErrorDto>(response.Value);
Assert.Equal("FileTooLarge", error.Code);
Assert.Equal("The uploaded file must not exceed 200 MB.", error.Message);
Assert.Equal("The uploaded file must not exceed 50 MB.", error.Message);
storage.VerifyNoOtherCalls();
}

View file

@ -17,7 +17,7 @@ namespace Api.SeaHavenIndustries.Controllers
[Route("api/workorders")]
public class WorkOrderMediaController : Controller
{
public const long MaxUploadBytes = 200_000_000;
public const long MaxUploadBytes = 50_000_000;
private readonly IWorkOrderMediaService _workOrderMediaService;
private readonly IFileStoragePort _fileStorage;
@ -75,7 +75,6 @@ namespace Api.SeaHavenIndustries.Controllers
[HttpPost("{id:int}/media")]
[RequestSizeLimit(MaxUploadBytes)]
[RequestFormLimits(MultipartBodyLengthLimit = MaxUploadBytes)]
public async Task<IActionResult> AddMedia(
int id,
[FromForm] WorkOrderMediaCategory? category,
@ -92,7 +91,7 @@ namespace Api.SeaHavenIndustries.Controllers
{
throw new WorkOrderBoardValidationException(
"FileTooLarge",
"The uploaded file must not exceed 200 MB.");
"The uploaded file must not exceed 50 MB.");
}
WorkOrderMediaFileRules.EnsureAllowed(file, category);