test: Update Application handler unit tests for Stream API
- Update mock setups: It.IsAny<byte[]>() → It.IsAny<Stream>() - Update mock verifications: Verify Stream parameter instead of byte[] - Remove obsolete namespace imports (Domain.Models.ValueObjects) - Update exception expectations (BadRequestException instead of PdfProcessingException)
This commit is contained in:
@@ -3,7 +3,6 @@ using DocumentOperator.Application.Common.DTOs;
|
||||
using DocumentOperator.Application.Common.Interfaces;
|
||||
using DocumentOperator.Application.ValidatePdf.Queries;
|
||||
using DocumentOperator.Domain.Common.Exceptions;
|
||||
using DocumentOperator.Domain.Models.ValueObjects;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
@@ -27,7 +26,7 @@ public class ValidatePdfHandlerTests
|
||||
public async Task Handle_ValidPdf_ReturnsPdfMetadata()
|
||||
{
|
||||
// Arrange
|
||||
var pdfBytes = new byte[] { 0x25, 0x50, 0x44, 0x46 }; // "%PDF"
|
||||
var pdfBytes = "%PDF"u8.ToArray(); // "%PDF"
|
||||
var query = new ValidatePdfQuery { PdfBytes = pdfBytes };
|
||||
|
||||
var domainMetadata = new PdfMetadata(
|
||||
@@ -48,7 +47,7 @@ public class ValidatePdfHandlerTests
|
||||
);
|
||||
|
||||
_mockPdfProcessor
|
||||
.Setup(x => x.ValidateAsync(It.IsAny<byte[]>()))
|
||||
.Setup(x => x.ValidateAsync(It.IsAny<Stream>()))
|
||||
.ReturnsAsync(domainMetadata);
|
||||
|
||||
_mockMapper
|
||||
@@ -66,7 +65,7 @@ public class ValidatePdfHandlerTests
|
||||
result.HasAttachments.Should().BeFalse();
|
||||
result.AttachmentCount.Should().Be(0);
|
||||
|
||||
_mockPdfProcessor.Verify(x => x.ValidateAsync(It.IsAny<byte[]>()), Times.Once);
|
||||
_mockPdfProcessor.Verify(x => x.ValidateAsync(It.IsAny<Stream>()), Times.Once);
|
||||
_mockMapper.Verify(x => x.Map<PdfValidationResult>(domainMetadata), Times.Once);
|
||||
}
|
||||
|
||||
@@ -74,19 +73,19 @@ public class ValidatePdfHandlerTests
|
||||
public async Task Handle_PdfProcessorThrowsException_PropagatesException()
|
||||
{
|
||||
// Arrange
|
||||
var pdfBytes = new byte[] { 0x25, 0x50, 0x44, 0x46 }; // "%PDF"
|
||||
var pdfBytes = "%PDF"u8.ToArray(); // "%PDF"
|
||||
var query = new ValidatePdfQuery { PdfBytes = pdfBytes };
|
||||
|
||||
_mockPdfProcessor
|
||||
.Setup(x => x.ValidateAsync(It.IsAny<byte[]>()))
|
||||
.ThrowsAsync(new PdfProcessingException("Invalid PDF format"));
|
||||
.Setup(x => x.ValidateAsync(It.IsAny<Stream>()))
|
||||
.ThrowsAsync(new BadRequestException("Invalid PDF format"));
|
||||
|
||||
// Act & Assert
|
||||
var exception = await Assert.ThrowsAsync<PdfProcessingException>(
|
||||
var exception = await Assert.ThrowsAsync<BadRequestException>(
|
||||
() => _handler.Handle(query, CancellationToken.None)
|
||||
);
|
||||
|
||||
exception.Message.Should().Be("Invalid PDF format");
|
||||
_mockPdfProcessor.Verify(x => x.ValidateAsync(It.IsAny<byte[]>()), Times.Once);
|
||||
_mockPdfProcessor.Verify(x => x.ValidateAsync(It.IsAny<Stream>()), Times.Once);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user