diff --git a/back/Services.Tests/Reports/ReportOffsetServiceTests.cs b/back/Services.Tests/Reports/ReportOffsetServiceTests.cs new file mode 100644 index 0000000..74824d8 --- /dev/null +++ b/back/Services.Tests/Reports/ReportOffsetServiceTests.cs @@ -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(); + spendingGroupRepoMock.Setup(repo => repo.GetByPlan(It.IsAny())).ReturnsAsync((SpendingGroupDto)null); + var reportOffsetService = new ReportOffsetFromPlanService(spendingGroupRepoMock.Object); + + Assert.ThrowsAsync(() => reportOffsetService.GetReportData(new())); + } + + [Fact] + public void GetReportData_WhenSpendingGroupHasNoChangeRecords_ThenThrowsReportDataNotFoundException() + { + var spendingGroupRepoMock = new Mock(); + spendingGroupRepoMock.Setup(repo => repo.GetByPlan(It.IsAny())).ReturnsAsync(new SpendingGroupDto()); + var reportOffsetService = new ReportOffsetFromPlanService(spendingGroupRepoMock.Object); + + Assert.ThrowsAsync(() => reportOffsetService.GetReportData(new())); + } + + [Fact] + public async Task GetReportData_WhenSpendingGroupHasChangeRecords_ThenReturnsSpendingGroupViewModel() + { + var spendingGroupRepoMock = new Mock(); + var spendingGroup = new SpendingGroupDto() + { + ChangeRecords = + [ + new() + { + Id = Guid.NewGuid(), + ChangedAt = DateTime.Now + } + ] + }; + spendingGroupRepoMock.Setup(repo => repo.GetByPlan(It.IsAny())).ReturnsAsync(spendingGroup); + var reportOffsetService = new ReportOffsetFromPlanService(spendingGroupRepoMock.Object); + + var result = await reportOffsetService.GetReportData(new()); + + Assert.NotNull(result); + Assert.IsType(result); + } +} \ No newline at end of file diff --git a/back/Services.Tests/Reports/ReportPeriodServiceTests.cs b/back/Services.Tests/Reports/ReportPeriodServiceTests.cs new file mode 100644 index 0000000..5b7fc35 --- /dev/null +++ b/back/Services.Tests/Reports/ReportPeriodServiceTests.cs @@ -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(); + changeRecordRepoMock.Setup(repo => repo.GetList(It.IsAny())).ReturnsAsync((List)null); + var reportPeriodService = new ReportPeriodService(changeRecordRepoMock.Object); + + Assert.ThrowsAsync(() => reportPeriodService.GetReportData(DateTime.MinValue, DateTime.MaxValue)); + } + + [Fact] + public async Task GetReportData_WhenChangeRecordsFound_ThenReturnsChangeRecordViewModels() + { + var changeRecordRepoMock = new Mock(); + var changeRecords = new List() + { + new() { Id = Guid.NewGuid(), ChangedAt = DateTime.Now }, + new() { Id = Guid.NewGuid(), ChangedAt = DateTime.Now } + }; + changeRecordRepoMock.Setup(repo => repo.GetList(It.IsAny())).ReturnsAsync(changeRecords); + var reportPeriodService = new ReportPeriodService(changeRecordRepoMock.Object); + + var result = await reportPeriodService.GetReportData(DateTime.MinValue, DateTime.MaxValue); + + changeRecordRepoMock.Verify(repo => repo.GetList(It.IsAny()), Times.Once); + Assert.NotNull(result); + Assert.IsType>(result.ToList()); + } +} \ No newline at end of file