public void ResultReceiverWriteToConsoleTest() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); var testReciever = new DivisibilityResultReceiver(); testReciever.Process(new Result { Alias = "TIC", Value = 6 }); var testRecieverContent = sw.ToString(); Assert.AreEqual(string.Format("6 TIC{0}", Environment.NewLine), testRecieverContent); } }
private static ICommand GetDivisibilityCommand() { var receiver = new DivisibilityResultReceiver(); //result dependency is injected to the command. This will write out to the console once the command is executed var devisibilityCheckCommand = new DivisibilityCheckCommand(receiver); //input dependency is(are) accepted by the command. devisibilityCheckCommand.Accept(new InputNumber { Value = 3, Alias = "tic" }); devisibilityCheckCommand.Accept(new InputNumber { Value = 5, Alias = "tac" }); //set the number of iterations for this command devisibilityCheckCommand.SetIterations(100); return(devisibilityCheckCommand); }
/// <summary> /// Method 1 - using dependency injection / Command pattern /// </summary> private static void RunMethodOne() { var receiver = new DivisibilityResultReceiver(); //result dependency is injected to the command. This will write out to the console once the command is executed var devisibilityCheckCommand = new DivisibilityCheckCommand(receiver); //input dependency is accepted by the command devisibilityCheckCommand.Accept(new InputNumber { Value = 3, Alias = "TIC" }); devisibilityCheckCommand.Accept(new InputNumber { Value = 5, Alias = "TAC" }); for (int i = 0; i < 100; i++) { //set the value that requires testing against the input devisibilityCheckCommand.CurrentIteration = i;// change devisibilityCheckCommand.Execute(); } Console.ReadLine(); }