Вероятно, лучший способ обработать это состоит в том, чтобы разделить код, так, чтобы логика, которая обрабатывает содержание страницы, была разделена от кода, который выбирает страницу.
Тогда передают экземпляр кода устройства выбора в логику обработки, тогда можно легко заменить его ложным устройством выбора для модульного теста.
, например,
class Processor(oject):
def __init__(self, fetcher):
self.m_fetcher = fetcher
def doProcessing(self):
## use self.m_fetcher to get page contents
class RealFetcher(object):
def fetchPage(self, url):
## get real contents
class FakeFetcher(object):
def fetchPage(self, url):
## Return whatever fake contents are required for this test
How about:
internal static bool IsTimeOver()
{
return DateTime.Now.TimeOfDay > _whenTimeIsOver;
}
Operator overloading is very helpful for date and time work :) You might also want to consider making it a property instead of a method.
It's a slight pity that there isn't a
DateTime.CurrentTime
or
TimeSpan.CurrentTime
to avoid DateTime.Now.TimeOfDay
(just as there's DateTime.Today
) but alas, no...
I have a set of extension methods on int
in MiscUtil which would make the initialization of _whenTimeIsOver
neater - you'd use:
private static readonly TimeSpan _whenTimeIsOver = 16.Hours() + 25.Minutes();
It's not to everyone's tastes, but I like it...