Esempio n. 1
0
            public void CanRunAt_Now_NeverRun_True(
                [Values(0, 10000, 25695454)] int interval)
            {
                var bi = new BudgetInterval()
                {
                    IntervalMilliseconds = interval
                };
                var ret = bi.CanRunAt(DateTime.Now);

                Assert.True(ret);
            }
Esempio n. 2
0
 public void CanRunAt_InvalidAllowance_Exception(
     [Values(1000)] int interval,
     [Values(-100, -1, 101)] int allowancePercentage,
     [Values(1000)] int checkTimeOffset)
 {
     var bi = new BudgetInterval()
     {
         IntervalMilliseconds = interval, LastChecked = DateTime.Now
     };
     var ret = bi.CanRunAt(bi.LastChecked.Value.AddMilliseconds(checkTimeOffset), allowancePercentage);
 }
Esempio n. 3
0
            public void CanRunAt_Now_RunNow_CanRunYesterday_False(
                [Values(0, 10000, 25695454)] int interval)
            {
                var bi = new BudgetInterval()
                {
                    IntervalMilliseconds = interval, LastChecked = DateTime.Now
                };
                var ret = bi.CanRunAt(DateTime.Now.AddDays(-1));

                Assert.False(ret);
            }
Esempio n. 4
0
            public void CanRunAt_OKTimePassed_True(
                [Values(1000)] int interval,
                [Values(10)] int allowancePercentage,
                [Values(900, 1000, 1100, 1285744)] int checkTimeOffset)
            {
                var bi = new BudgetInterval()
                {
                    IntervalMilliseconds = interval, LastChecked = DateTime.Now
                };
                var ret = bi.CanRunAt(bi.LastChecked.Value.AddMilliseconds(checkTimeOffset), allowancePercentage);

                Assert.True(ret);
            }
Esempio n. 5
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();
                }
            }
        }