public async void Handle_ShouldReturnMetricsFromRepository_WhenRefreshCacheTrue()
        {
            // ARRANGE
            var rideRepositoryMock = new Mock <IRideRepository>();
            var memoryCache        = new MemoryCache(new MemoryCacheOptions());
            var loggerMock         = new Mock <ILogger>();

            rideRepositoryMock
            .Setup(x => x.GetOverviewRideMetrics(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(),
                                                 It.IsAny <DateTime>())).ReturnsAsync(new RideMetrics());

            var datePeriod = PeriodSelectionEnum.ThisYear;
            var dateRange  = DatePeriodHelper.GetDateRangeFromPeriodSelection(datePeriod);
            var cacheKey   = $"ride-{dateRange.StartDate.ToString()}-{dateRange.EndDate.ToString()}";

            memoryCache.Set(cacheKey, new RideMetrics());

            var handler = new GetRideMetricsByPeriodSelectionQueryHandler(
                rideRepositoryMock.Object,
                loggerMock.Object,
                memoryCache
                );

            // ACT
            var response = await handler.Handle(new GetRideMetricsByPeriodSelectionQuery()
            {
                DatePeriod = datePeriod, RefreshCache = true
            }, new CancellationToken());


            // ASSERT
            Assert.Equal(QueryResultTypeEnum.Success, response.Type);
            rideRepositoryMock.Verify(x => x.GetOverviewRideMetrics(It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Once);
        }
        public async Task <QueryResult <RecruitmentMessageMetrics> > Handle(GetRecruitmentMessageMetricsByPeriodSelectionQuery request, CancellationToken cancellationToken)
        {
            var dateRange = DatePeriodHelper.GetDateRangeFromPeriodSelection(request.DatePeriod);
            var cacheKey  = $"recruitment-message-{dateRange.StartDate.ToString()}-{dateRange.EndDate.ToString()}";

            if (request.RefreshCache)
            {
                _cache.Remove(cacheKey);
            }

            var metrics = await _cache.GetOrCreateAsync(cacheKey, async entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(23);

                return(await _recruitmentMessageRepository.GetOverviewRecruitmentMessageMetrics(dateRange.StartDate,
                                                                                                dateRange.EndDate,
                                                                                                dateRange.PreviousPeriodStartDate,
                                                                                                dateRange.PreviousPeriodEndDate));
            });

            metrics.CurrentPeriodLabel = dateRange.CurrentPeriodLabel;
            metrics.PriorPeriodLabel   = dateRange.PriorPeriodLabel;

            return(new QueryResult <RecruitmentMessageMetrics>(result: metrics, type: QueryResultTypeEnum.Success));
        }
Ejemplo n.º 3
0
        public void TestInitial()
        {
            Assert.AreEqual(DayOfWeek.Monday, EidssSiteContext.Instance.FirstDayOfWeek);
            Assert.AreEqual(CalendarWeekRule.FirstFourDayWeek, EidssSiteContext.Instance.WeekRule);

            Assert.AreEqual(new DateTime(2008, 12, 29), DatePeriodHelper.GetFirstWeekOfYear(2009));
            Assert.AreEqual(new DateTime(2010, 1, 4), DatePeriodHelper.GetFirstWeekOfYear(2010));
            Assert.AreEqual(new DateTime(2011, 1, 3), DatePeriodHelper.GetFirstWeekOfYear(2011));
            Assert.AreEqual(new DateTime(2012, 1, 2), DatePeriodHelper.GetFirstWeekOfYear(2012));
            Assert.AreEqual(new DateTime(2012, 12, 31), DatePeriodHelper.GetFirstWeekOfYear(2013));
            Assert.AreEqual(new DateTime(2013, 12, 30), DatePeriodHelper.GetFirstWeekOfYear(2014));

            Assert.AreEqual(52, DatePeriodHelper.GetWeekOfYear(new DateTime(2012, 12, 30)));
            Assert.AreEqual(1, DatePeriodHelper.GetWeekOfYear(new DateTime(2013, 12, 30)));
            Assert.AreEqual(3, DatePeriodHelper.GetWeekOfYear(new DateTime(2014, 1, 17)));
            Assert.AreEqual(52, DatePeriodHelper.GetWeekOfYear(new DateTime(2006, 1, 1)));
            Assert.AreEqual(1, DatePeriodHelper.GetWeekOfYear(new DateTime(2008, 1, 1)));
            Assert.AreEqual(1, DatePeriodHelper.GetWeekOfYear(new DateTime(2009, 1, 1)));
            Assert.AreEqual(53, DatePeriodHelper.GetWeekOfYear(new DateTime(2010, 1, 1)));
            Assert.AreEqual(52, DatePeriodHelper.GetWeekOfYear(new DateTime(2011, 1, 1)));

            var list = DatePeriodHelper.GetWeeksList(2007);

            Assert.AreEqual(52, list.Count);
        }
Ejemplo n.º 4
0
        public async void Handle_ShouldReturnMetricsFromCache_WhenDatePeriodIsCached()
        {
            // ARRANGE
            var recruitmentMessageRepositoryMock = new Mock <IRecruitmentMessageRepository>();
            var memoryCache = new MemoryCache(new MemoryCacheOptions());
            var loggerMock  = new Mock <ILogger>();

            var datePeriod = PeriodSelectionEnum.ThisYear;
            var dateRange  = DatePeriodHelper.GetDateRangeFromPeriodSelection(datePeriod);
            var cacheKey   = $"recruitment-message-{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
            }, 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.Never);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Calculate the end date of the FRA which
        /// will replace the cash instrument
        /// </summary>
        /// <param name="calendar"></param>
        /// <param name="assetController"></param>
        /// <returns></returns>
        public DateTime CalculateFraEndTime(IBusinessCalendar calendar, IPriceableRateAssetController assetController)//,
        //string currency, string rollConvention)
        {
            var deposit = (PriceableDeposit)assetController;
            BusinessDayConventionEnum adjustment = deposit.BusinessDayAdjustments.businessDayConvention;

            return(DatePeriodHelper.AddPeriod(assetController.GetRiskMaturityDate(),
                                              "3M", calendar, adjustment.ToString(), null));
        }
Ejemplo n.º 6
0
        public void GetDateRangeFromPeriodSelection_For_All_Time_Should_Return_Successful()
        {
            var result = DatePeriodHelper.GetDateRangeFromPeriodSelection(PeriodSelectionEnum.AllTime);

            Assert.Equal(null, result.StartDate);
            Assert.Equal(new DateTime(2100, 1, 1), result.EndDate);

            Assert.Equal(null, result.PreviousPeriodStartDate);
            Assert.Equal(null, result.PreviousPeriodEndDate);

            Assert.Equal("All Time", result.CurrentPeriodLabel);
            Assert.Equal(null, result.PriorPeriodLabel);
        }
Ejemplo n.º 7
0
        public void GetDateRangeFromPeriodSelection_For_Rolling_30_Should_Return_Successful()
        {
            var result           = DatePeriodHelper.GetDateRangeFromPeriodSelection(PeriodSelectionEnum.Rolling30);
            var daysBetweenDates = (new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day) - new DateTime(DateTime.Now.AddDays(-30).Year, DateTime.Now.AddDays(-30).Month, DateTime.Now.AddDays(-30).Day)).TotalDays * -1;

            Assert.Equal(new DateTime(DateTime.Now.AddDays(-30).Year, DateTime.Now.AddDays(-30).Month, DateTime.Now.AddDays(-30).Day), result.StartDate);
            Assert.Equal(new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day), result.EndDate);

            Assert.Equal(new DateTime(DateTime.Now.AddDays(-30).Year, DateTime.Now.AddDays(-30).Month, DateTime.Now.AddDays(-30).Day).AddDays(daysBetweenDates), result.PreviousPeriodStartDate);
            Assert.Equal(new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day).AddDays(daysBetweenDates), result.PreviousPeriodEndDate);

            Assert.Equal($"{new DateTime(DateTime.Now.AddDays(-30).Year, DateTime.Now.AddDays(-30).Month, DateTime.Now.AddDays(-30).Day).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)} - {new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}", result.CurrentPeriodLabel);
            Assert.Equal($"{new DateTime(DateTime.Now.AddDays(-30).Year, DateTime.Now.AddDays(-30).Month, DateTime.Now.AddDays(-30).Day).AddDays(daysBetweenDates).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)} - {new DateTime(DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day).AddDays(daysBetweenDates).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}", result.PriorPeriodLabel);
        }
Ejemplo n.º 8
0
        public void GetDateRangeFromPeriodSelection_For_This_Month_Should_Return_Successful()
        {
            var result           = DatePeriodHelper.GetDateRangeFromPeriodSelection(PeriodSelectionEnum.ThisMonth);
            var daysBetweenDates = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1) - new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)).TotalDays * -1;

            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1), result.StartDate);
            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1), result.EndDate);

            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(daysBetweenDates), result.PreviousPeriodStartDate);
            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).AddDays(daysBetweenDates), result.PreviousPeriodEndDate);

            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("MMM yyyy", CultureInfo.InvariantCulture), result.PriorPeriodLabel);
            Assert.Equal(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddMonths(1).ToString("MMM yyyy", CultureInfo.InvariantCulture), result.CurrentPeriodLabel);
        }
Ejemplo n.º 9
0
        public void GetDateRangeFromPeriodSelection_For_This_Year_Should_Return_Successful()
        {
            var result           = DatePeriodHelper.GetDateRangeFromPeriodSelection(PeriodSelectionEnum.ThisYear);
            var daysBetweenDates = (new DateTime(DateTime.Now.Year + 1, 1, 1) - new DateTime(DateTime.Now.Year, 1, 1)).TotalDays * -1;

            Assert.Equal(new DateTime(DateTime.Now.Year, 1, 1), result.StartDate);
            Assert.Equal(new DateTime(DateTime.Now.Year + 1, 1, 1), result.EndDate);

            Assert.Equal(new DateTime(DateTime.Now.Year, 1, 1).AddDays(daysBetweenDates), result.PreviousPeriodStartDate);
            Assert.Equal(new DateTime(DateTime.Now.Year + 1, 1, 1).AddDays(daysBetweenDates), result.PreviousPeriodEndDate);

            Assert.Equal((DateTime.Now.Year - 1).ToString(), result.PriorPeriodLabel);
            Assert.Equal((DateTime.Now.Year).ToString(), result.CurrentPeriodLabel);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Выводит список недель. Для текущего года отсекаются те недели, которые ещё не наступили.
        /// </summary>
        /// <returns></returns>
        public static DataTable CreateWeeksTable(int year)
        {
            var weeksTable = CreatePeriodTable();

            foreach (var wp in DatePeriodHelper.GetWeeksList(year, true))
            {
                var weekRow = weeksTable.NewRow();
                weekRow["PeriodNumber"] = wp.WeekNumber;
                weekRow["StartDay"]     = wp.WeekStartDate;
                weekRow["PeriodID"]     = String.Format("{0}_{1}", year, wp.WeekNumber);
                weekRow["FinishDay"]    = wp.WeekStartDate.AddDays(6);
                weekRow["PeriodName"]   = String.Format("{0:d} - {1:d}", weekRow["StartDay"], weekRow["FinishDay"]);
                weeksTable.Rows.Add(weekRow);
            }

            return(weeksTable);
        }
Ejemplo n.º 11
0
        public List <SelectListItemSurrogate> GetWeeksList(int year)
        {
            Year = year;
            var weeksList = DatePeriodHelper.GetWeeksList(year);
            var result    = new List <SelectListItemSurrogate>();

            foreach (var week in weeksList)
            {
                var sli = new SelectListItemSurrogate
                {
                    Text = String.Format("{0:00} ({1} - {2})"
                                         , week.WeekNumber
                                         , week.WeekStartDate.ToString("dd/MM/yyyy")
                                         , week.WeekStartDate.AddDays(6).ToString("dd/MM/yyyy")),
                    Value    = week.WeekNumber.ToString(CultureInfo.InvariantCulture),
                    Selected = WeekId.HasValue && week.WeekNumber == WeekId.Value
                };
                result.Add(sli);
            }
            return(result);
        }
Ejemplo n.º 12
0
        public void TestCompareSQLtoCS()
        {
            DbManagerFactory.SetSqlFactory(Config.GetSetting("EidssConnectionString"));
            ConnectionManager.DefaultInstance.SetCredentials(Config.GetSetting("EidssConnectionString"));

            EidssUserContext.Init();
            using (var manager = DbManagerFactory.Factory.Create())
            {
                for (int year = 1900; year <= 2050; year++)
                {
                    for (int day = 24; day <= 31; day++)
                    {
                        DateTime dt = new DateTime(year, 12, day);
                        Assert.AreEqual(DatePeriodHelper.GetWeekOfYear(dt), manager.SetCommand("SET DATEFIRST 1; select dbo.fnWeekDatepart('" + dt.ToString("yyyyMMdd") + "')").ExecuteScalar());
                    }
                    for (int day = 1; day <= 7; day++)
                    {
                        DateTime dt = new DateTime(year, 1, day);
                        Assert.AreEqual(DatePeriodHelper.GetWeekOfYear(dt), manager.SetCommand("SET DATEFIRST 1; select dbo.fnWeekDatepart('" + dt.ToString("yyyyMMdd") + "')").ExecuteScalar());
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public static void WeekLookupTemplate(ref AggregateCaseHeader obj)
        {
            if (_WeekLookupTemplate == null)
            {
                _WeekLookupTemplate = new BaseReferenceList("rftSampleStatus");
            }
            _WeekLookupTemplate.Clear();
            if (obj.YearForAggr != null)
            {
                using (DbManagerProxy manager = DbManagerFactory.Factory.Create(ModelUserContext.Instance))
                {
                    foreach (WeekPeriod wp in DatePeriodHelper.GetWeeksList((int)obj.YearForAggr))
                    {
                        _WeekLookupTemplate.Add(BaseReference.Accessor.Instance(null).CreateDummy(manager, null, (long)wp.WeekNumber, String.Format("{0:d}-{1:d}", wp.WeekStartDate, wp.WeekStartDate.AddDays(6))));
                    }
                }
            }

            long thisYear = (long)DateTime.Now.Year;

            obj.WeekAggrLookup.RemoveAll(m => (long)m.Key > 0L);
            if (obj.YearForAggr == thisYear)
            {
                obj.WeekAggrLookup.AddRange(_WeekLookupTemplate.Where(m => m.idfsBaseReference <= (long)DatePeriodHelper.GetWeekOfYear(DateTime.Now)));
            }
            else
            {
                obj.WeekAggrLookup.AddRange(_WeekLookupTemplate);
            }

            long?val = obj.WeekForAggr;

            obj.WeekAggr = obj.WeekAggrLookup
                           .Where(c => c.idfsBaseReference == val)
                           .SingleOrDefault();
        }