public void Listing5_01to06()
 {
     using (ConsoleTester consoleTester = ConsoleTester.GetConsoleTester(
                "<<Inigo Montoya: Enough to survive on\r\n"))
     {
         Program_Accessor.Main();
     }
 }
        public void RootDirectoryWithoutTrailingSlash()
        {
            string root        = @".\Blah\";
            string chapter     = "5";
            string fromListing = "15-29";
            string toListing   = "30-31";

            using (ConsoleTester tester = ConsoleTester.GetConsoleTester(
                       string.Format("<<{0}\r\n", Program.HelpText) +
                       string.Format(@"<>The chapter folder, ""{0}\Blah\Chapter05\Listing5_30-31"", could not be found." + Environment.NewLine,
                                     Environment.CurrentDirectory)))
            {
                Assert.AreEqual <int>(-1, Program.Main(root, chapter, fromListing, toListing));
            }
        }
        public void ChapterDirectoryDoesNotExist()
        {
            string root        = @".\MockProject\";
            string chapter     = "99";
            string fromListing = "15-29";
            string toListing   = "30-31";

            using (ConsoleTester tester = ConsoleTester.GetConsoleTester(
                       string.Format("<<{0}\r\n", Program.HelpText) +
                       string.Format(@"<>The chapter folder, ""{0}\MockProject\Chapter99\Listing99_30-31"", could not be found." + Environment.NewLine,
                                     Environment.CurrentDirectory)))
            {
                Assert.AreEqual <int>(-1, Program.Main(root, chapter, fromListing, toListing));
            }
        }
        public void MainTest2()
        {
            string root        = @".\MockProject\";
            string chapter     = "5";
            string fromListing = "15-29";
            string toListing   = "98-99";

            string fromName        = string.Format("Listing{0}_{1}", chapter, fromListing);
            string toName          = string.Format("Listing{0}_{1}", chapter, toListing);
            string chapterFolder   = "Chapter" + chapter.PadLeft(2, '0');
            string fromProjectName = string.Format("{0}.Listing{1}_{2}", chapterFolder, chapter, fromListing);
            string toProjectName   = string.Format("{0}.Listing{1}_{2}", chapterFolder, chapter, toListing);

            ConsoleTester tester = ConsoleTester.GetConsoleTester();

            tester.Execute(".\\ProjectRename.exe", string.Format("{0} {1} {2} {3}", root, chapter, fromListing, toListing));

            DirectoryInfo fromProjectDirectory = new DirectoryInfo(PathEx.Combine(root, chapterFolder, fromName));

            Assert.IsTrue(fromProjectDirectory.Exists, "From project directory does not exists.  Problem with the test.");

            DirectoryInfo toProjectDirectory = new DirectoryInfo(PathEx.Combine(root, chapterFolder, toName));

            Assert.IsTrue(fromProjectDirectory.Exists, "to directory was not even created");

            foreach (FileInfo file in toProjectDirectory.GetFiles("*", SearchOption.AllDirectories))
            {
                if (file.Directory.Parent.Name.ToLower() != "bin" && file.Directory.Parent.Name.ToLower() != "obj")
                {
                    TestContext.WriteLine(file.Name);
                    Assert.IsFalse(file.Name.Contains(fromName));
                    using (StreamReader reader = new StreamReader(file.FullName))
                    {
                        string content = reader.ReadToEnd();
                        Assert.IsFalse(content.Contains(fromName));
                        Assert.IsFalse(content.Contains(fromName.Replace("-", "to")));
                    }
                }
            }
        }