public async void Handle_ShouldReturnMetricsFromRepository_WhenRefreshCacheTrue() { // ARRANGE var recruitmentMessageRepositoryMock = new Mock <IRecruitmentMessageRepository>(); var memoryCache = new MemoryCache(new MemoryCacheOptions()); var loggerMock = new Mock <ILogger>(); recruitmentMessageRepositoryMock .Setup(x => x.GetOverviewRecruitmentMessageMetrics(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).ReturnsAsync(new RecruitmentMessageMetrics()); var datePeriod = PeriodSelectionEnum.ThisYear; var dateRange = DatePeriodHelper.GetDateRangeFromPeriodSelection(datePeriod); var cacheKey = $"recruitmentMessage-{dateRange.StartDate.ToString()}-{dateRange.EndDate.ToString()}"; memoryCache.Set(cacheKey, new RecruitmentMessageMetrics()); var handler = new GetRecruitmentMessageMetricsByPeriodSelectionQueryHandler( recruitmentMessageRepositoryMock.Object, loggerMock.Object, memoryCache ); // ACT var response = await handler.Handle(new GetRecruitmentMessageMetricsByPeriodSelectionQuery() { DatePeriod = datePeriod, RefreshCache = true }, new CancellationToken()); // ASSERT Assert.Equal(QueryResultTypeEnum.Success, response.Type); recruitmentMessageRepositoryMock.Verify(x => x.GetOverviewRecruitmentMessageMetrics(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Once); }
public async void Handle_ShouldReturnMetricsSuccessfully() { // ARRANGE var recruitmentMessageRepositoryMock = new Mock <IRecruitmentMessageRepository>(); var memoryCache = new MemoryCache(new MemoryCacheOptions()); var loggerMock = new Mock <ILogger>(); recruitmentMessageRepositoryMock .Setup(x => x.GetOverviewRecruitmentMessageMetrics(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>())).ReturnsAsync(new RecruitmentMessageMetrics()); var handler = new GetRecruitmentMessageMetricsByPeriodSelectionQueryHandler( recruitmentMessageRepositoryMock.Object, loggerMock.Object, memoryCache ); // ACT var response = await handler.Handle(new GetRecruitmentMessageMetricsByPeriodSelectionQuery() { DatePeriod = PeriodSelectionEnum.ThisYear }, new CancellationToken()); // ASSERT Assert.Equal(QueryResultTypeEnum.Success, response.Type); recruitmentMessageRepositoryMock.Verify(x => x.GetOverviewRecruitmentMessageMetrics(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Once); }