add: тесты для сервисов отчетов
This commit is contained in:
parent
2e861c19a4
commit
0bdf0c9f6c
56
back/Services.Tests/Reports/ReportOffsetServiceTests.cs
Normal file
56
back/Services.Tests/Reports/ReportOffsetServiceTests.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using Contracts.DTO;
|
||||||
|
using Contracts.Repositories;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using Moq;
|
||||||
|
using Services.Reports;
|
||||||
|
using Services.Support.Exceptions;
|
||||||
|
|
||||||
|
namespace Services.Tests.Reports;
|
||||||
|
|
||||||
|
public class ReportOffsetServiceTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetReportData_WhenSpendingGroupNotFound_ThenThrowsEntityNotFoundException()
|
||||||
|
{
|
||||||
|
var spendingGroupRepoMock = new Mock<ISpendingGroupRepo>();
|
||||||
|
spendingGroupRepoMock.Setup(repo => repo.GetByPlan(It.IsAny<SpendingPlanSearch>())).ReturnsAsync((SpendingGroupDto)null);
|
||||||
|
var reportOffsetService = new ReportOffsetFromPlanService(spendingGroupRepoMock.Object);
|
||||||
|
|
||||||
|
Assert.ThrowsAsync<EntityNotFoundException>(() => reportOffsetService.GetReportData(new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetReportData_WhenSpendingGroupHasNoChangeRecords_ThenThrowsReportDataNotFoundException()
|
||||||
|
{
|
||||||
|
var spendingGroupRepoMock = new Mock<ISpendingGroupRepo>();
|
||||||
|
spendingGroupRepoMock.Setup(repo => repo.GetByPlan(It.IsAny<SpendingPlanSearch>())).ReturnsAsync(new SpendingGroupDto());
|
||||||
|
var reportOffsetService = new ReportOffsetFromPlanService(spendingGroupRepoMock.Object);
|
||||||
|
|
||||||
|
Assert.ThrowsAsync<ReportDataNotFoundException>(() => reportOffsetService.GetReportData(new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetReportData_WhenSpendingGroupHasChangeRecords_ThenReturnsSpendingGroupViewModel()
|
||||||
|
{
|
||||||
|
var spendingGroupRepoMock = new Mock<ISpendingGroupRepo>();
|
||||||
|
var spendingGroup = new SpendingGroupDto()
|
||||||
|
{
|
||||||
|
ChangeRecords =
|
||||||
|
[
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Id = Guid.NewGuid(),
|
||||||
|
ChangedAt = DateTime.Now
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
spendingGroupRepoMock.Setup(repo => repo.GetByPlan(It.IsAny<SpendingPlanSearch>())).ReturnsAsync(spendingGroup);
|
||||||
|
var reportOffsetService = new ReportOffsetFromPlanService(spendingGroupRepoMock.Object);
|
||||||
|
|
||||||
|
var result = await reportOffsetService.GetReportData(new());
|
||||||
|
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.IsType<SpendingGroupViewModel>(result);
|
||||||
|
}
|
||||||
|
}
|
41
back/Services.Tests/Reports/ReportPeriodServiceTests.cs
Normal file
41
back/Services.Tests/Reports/ReportPeriodServiceTests.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using Contracts.DTO;
|
||||||
|
using Contracts.Repositories;
|
||||||
|
using Contracts.SearchModels;
|
||||||
|
using Contracts.ViewModels;
|
||||||
|
using Moq;
|
||||||
|
using Services.Reports;
|
||||||
|
using Services.Support.Exceptions;
|
||||||
|
|
||||||
|
namespace Services.Tests.Reports;
|
||||||
|
|
||||||
|
public class ReportPeriodServiceTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void GetReportData_WhenChangeRecordsNotFound_ThenThrowsReportDataNotFoundException()
|
||||||
|
{
|
||||||
|
var changeRecordRepoMock = new Mock<IChangeRecordRepo>();
|
||||||
|
changeRecordRepoMock.Setup(repo => repo.GetList(It.IsAny<ChangeRecordSearch>())).ReturnsAsync((List<ChangeRecordDto>)null);
|
||||||
|
var reportPeriodService = new ReportPeriodService(changeRecordRepoMock.Object);
|
||||||
|
|
||||||
|
Assert.ThrowsAsync<ReportDataNotFoundException>(() => reportPeriodService.GetReportData(DateTime.MinValue, DateTime.MaxValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetReportData_WhenChangeRecordsFound_ThenReturnsChangeRecordViewModels()
|
||||||
|
{
|
||||||
|
var changeRecordRepoMock = new Mock<IChangeRecordRepo>();
|
||||||
|
var changeRecords = new List<ChangeRecordDto>()
|
||||||
|
{
|
||||||
|
new() { Id = Guid.NewGuid(), ChangedAt = DateTime.Now },
|
||||||
|
new() { Id = Guid.NewGuid(), ChangedAt = DateTime.Now }
|
||||||
|
};
|
||||||
|
changeRecordRepoMock.Setup(repo => repo.GetList(It.IsAny<ChangeRecordSearch>())).ReturnsAsync(changeRecords);
|
||||||
|
var reportPeriodService = new ReportPeriodService(changeRecordRepoMock.Object);
|
||||||
|
|
||||||
|
var result = await reportPeriodService.GetReportData(DateTime.MinValue, DateTime.MaxValue);
|
||||||
|
|
||||||
|
changeRecordRepoMock.Verify(repo => repo.GetList(It.IsAny<ChangeRecordSearch>()), Times.Once);
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.IsType<List<ChangeRecordViewModel>>(result.ToList());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user