0.2.0 #4

Merged
mfnefd merged 15 commits from dev into main 2024-12-11 04:42:35 +04:00
2 changed files with 97 additions and 0 deletions
Showing only changes of commit 0bdf0c9f6c - Show all commits

View 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);
}
}

View 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());
}
}