public void ShouldPickOption2AndRunIt() { const string option1String = "option1"; IOption option1 = Substitute.For<IOption>(); option1.MatchesString(option1String).Returns(true); const string option2String = "option 2"; IOption option2 = Substitute.For<IOption>(); option2.MatchesString(option2String).Returns(true); TextReader textReader = Substitute.For<TextReader>(); textReader.ReadLine().Returns(option2String); OptionsDispatcher optionsDispatcher = new OptionsDispatcher(new[] { option1, option2 }, textReader); optionsDispatcher.ChooseOptionAndRun(); option2.Received(1).Run(); option1.DidNotReceive().Run(); }
static void Main() { using (Logger logger = new Logger()) { IEventsRepository eventsRepository = new EventsRepository("calendarData.dat"); IAddPolicy shareableSchedulePolicy = new ShareableSchedulePolicy(eventsRepository); IAddPolicy exclusiveSchedulePolicy = new ExclusiveSchedulePolicy(eventsRepository); Planner planner = new Planner(eventsRepository, shareableSchedulePolicy, exclusiveSchedulePolicy); IMeetingFactory meetingFactory = new MeetingFactory(); IOption addMeetingOption = new AddMeetingOption(meetingFactory, planner, logger); ITodoFactory todoFactory = new TodoFactory(); IOption addTodoOption = new AddTodoOption(todoFactory, planner, logger); IOption listEventsOption = new ListEventsOption(planner); IOption endApplicationOption = new EndApplicationOption(); OptionsDispatcher optionsDispatcher = new OptionsDispatcher(new[] { addTodoOption, addMeetingOption, listEventsOption, endApplicationOption, }, Console.In, logger); bool result = true; while (result) { result = optionsDispatcher.ChooseOptionAndRun(); } } }