public void ExecuteCommandCyclicTes() { var textReader = Substitute.For<TextReader>(); Console.SetIn(textReader); var textWriter = Substitute.For<TextWriter>(); Console.SetOut(textWriter); textReader.ReadLine().Returns("scalc '1,2,3"); textWriter .When(t => t.WriteLine("another input please")) .Do(c => textReader.ReadLine().Returns(string.Empty)); var stringCalculator = new StringCalculator(); stringCalculator.ExecuteAddCyclic(); textWriter.Received().WriteLine("The result is 6"); textWriter.Received().WriteLine("another input please"); }