public void EffectiveLastCheckedTime_Null_MinDate() { var bi = new BudgetInterval(); var ret = bi.EffectiveLastCheckedTime; Assert.AreEqual(DateTime.MinValue, ret); }
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); }
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); }
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); }
public void EffectiveLastCheckedTime_Value_Returned( [Values(1, 22, -8789, 0)] int dayDiff) { DateTime now = DateTime.Now.AddDays(dayDiff); var bi = new BudgetInterval() { LastChecked = now }; var ret = bi.EffectiveLastCheckedTime; Assert.AreEqual(now, ret); }
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); }
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); }
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); }
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(); } } }