56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
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);
|
|
}
|
|
} |