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