Пример #1
0
            public void SuggestedStartTime_NeverRun_NowMinusInterval(
                [Values(19, 100, 87636)] int interval)
            {
                var bi = new BudgetInterval()
                {
                    LastChecked = null, IntervalMilliseconds = interval
                };
                var now = DateTime.Now;
                var ret = bi.SuggestedStartTime(now);

                Assert.AreEqual((double)interval, (now - ret).TotalMilliseconds);
            }
Пример #2
0
            public void SuggestedStartTime_RunToday_Today(
                [Values(19, 100, 87636, int.MaxValue)] int interval,
                [Values(545456, 0, 87895465)] int nowOffset)
            {
                var now = DateTime.Now;
                var bi  = new BudgetInterval()
                {
                    LastChecked = now, IntervalMilliseconds = interval
                };
                var ret = bi.SuggestedStartTime(now.AddMilliseconds(nowOffset));

                Assert.AreEqual(now, ret);
            }
Пример #3
0
        public static void CheckInterval(DataProvidersDataContext dataContext, BudgetInterval budgetInterval)
        {
            var checkTime = DateTime.Now;

            if (budgetInterval.CanRunAt(checkTime, IntervalAllowancePercentage))
            {
                using (var appDataContext = new ApplicationDataContext())
                {
                    var intervalEntries = appDataContext.DataProviderCalls
                                          .Where(dce => dce.CallTime >= budgetInterval.SuggestedStartTime(checkTime) && dce.CallTime < checkTime);

                    CheckInterval <decimal>(budgetInterval.Name, () => intervalEntries.Sum(dpe => dpe.Cost), budgetInterval.CostThreshold, "cost");
                    CheckInterval <int>(budgetInterval.Name, () => intervalEntries.Count(), budgetInterval.CallThreshold, "number of calls");

                    budgetInterval.LastChecked = checkTime;
                    dataContext.SubmitChanges();
                }
            }
        }