/
softailor
/
gridient
Обзор
Документация
Войти
/
softailor
/
gridient
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
backend/Gridient.Core.Tests/Controllers/ReportsControllerTests.cs
44 строки
2 KB
Jenkins
Auto add
18 фев 2026, 10:19
18 фев 2026, 10:19
1e6c4f8
Код
Авторство
О чём код?
using FluentAssertions; using Gridient.Core.Controllers; using Gridient.Core.Features.Reports.Queries; using Gridient.Core.Models; using MediatR; using Microsoft.AspNetCore.Mvc; using Moq; using Xunit; namespace Gridient.Core.Tests.Controllers { public class ReportsControllerTests : ControllerTestBase { #region DownloadExcel /// <summary> /// Проверяет, что ReportsController.DownloadExcel возвращает FileContentResult и вызывает IMediator.Send с DownloadExcelQuery. /// </summary> [Fact] public async Task DownloadExcel_ShouldReturnFileResult() { var mediatorMock = new Mock<IMediator>(); mediatorMock .Setup(x => x.Send(It.IsAny<DownloadExcelQuery>(), It.IsAny<CancellationToken>())) .ReturnsAsync(new byte[] { 1, 2, 3 }); var controller = new ReportsController(mediatorMock.Object); SetupControllerContext(controller, "u"); var request = new ReportRequest { ListId = 1, FieldIds = new[] { 0 } }; var result = await controller.DownloadExcel(request, CancellationToken.None); result.Should().BeOfType<FileContentResult>(); var file = (FileContentResult)result; file.ContentType.Should().Be("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); file.FileContents.Should().BeEquivalentTo(new byte[] { 1, 2, 3 }); mediatorMock.Verify(x => x.Send(It.Is<DownloadExcelQuery>(q => q.Request == request), It.IsAny<CancellationToken>()), Times.Once); } #endregion } }