private void TestOneSearch(DirectoryInfo indexPath, string query, int expectedHitCount) { TextWriter outSave = Console.Out; try { MemoryStream bytes = new MemoryStream(); // .NET NOTE: GetEncoding(0) returns the current system's default encoding var fakeSystemOut = new StreamWriter(bytes, Encoding.GetEncoding(0)); Console.SetOut(fakeSystemOut); // LUCENENET specific: changed the arguments to act more like the dotnet.exe commands. // * only optional arguments start with - // * options have a long form that starts with -- // * required arguments must be supplied without - or -- and in a specific order // Since the demo is meant to be seen by end users, these changes were necessary to make // it consistent with the lucene-cli utility. SearchFiles.Main(new string[] { indexPath.FullName, "--query", query }); fakeSystemOut.Flush(); // .NET NOTE: GetEncoding(0) returns the current system's default encoding string output = Encoding.GetEncoding(0).GetString(bytes.ToArray()); // intentionally use default encoding assertTrue("output=" + output, output.Contains(expectedHitCount + " total matching documents")); } finally { Console.SetOut(outSave); } }