[Subject(typeof(OnceADayProcessor))]
public class When_processing_process_twice
{
private static ICanBeProcessedOnceADay ProcessedOnceADay;
private Establish context =() => { OnceADayProcessor.Now =() => new DateTime(2011, 1, 1, 0, 0, 0, 0); };
private Because of =() =>
{
ProcessedOnceADay = MockRepository.GenerateMock<ICanBeProcessedOnceADay>();
ProcessedOnceADay.Process();
ProcessedOnceADay.Process();
};
private It should_execute =() => ProcessedOnceADay.AssertWasCalled(x => x.Expect(p => p.Process()));
private It should_execute_only_once =() => ProcessedOnceADay.AssertWasNotCalled(x => x.Expect(p => p.Process()));
}
編集したソリューション:メソッドが1回だけ呼び出されることをどのようにアサーションするのですか?
[Subject(typeof(OnceADayProcessor))]
public class When_processing_a_process_twice_at_the_same_day
{
static ICanBeProcessedOnceADay canBeProcessedOnceADay;
Establish context =() =>
{
canBeProcessedOnceADay = A.Fake<ICanBeProcessedOnceADay>();
};
Because of =() =>
{
OnceADayProcessor.Process(canBeProcessedOnceADay);
OnceADayProcessor.Process(canBeProcessedOnceADay);
};
It should_execute_only_once =() =>
A.CallTo(() => canBeProcessedOnceADay.Process()).MustHaveHappened(Repeated.Exactly.Once);
}
これは、メソッドが_少なくとも1回、_exactly_は1回だけ呼び出されることを検証します。 –