Beispiel #1
0
        public void Test_GetBuildFileName()
        {
            try {
                ConsoleDriver.GetBuildFileName(null, null, false);
                Assert.Fail("Exception not thrown.");
            } catch {
            }

            string baseDirectory  = TempDir.Create(Path.Combine(TempDirName, "GetBuildFileName"));
            string build1FileName = Path.Combine(baseDirectory, "file1.build");
            string build2FileName = Path.Combine(baseDirectory, "file2.build");

            try {
                ConsoleDriver.GetBuildFileName(baseDirectory, null, false);
                Assert.Fail("ApplicationException not thrown.");
            } catch (ApplicationException) {
            }

            TempFile.Create(build1FileName);

            Assert.AreEqual(build1FileName, ConsoleDriver.GetBuildFileName(Path.GetDirectoryName(build1FileName), null, false));

            // create a second build file in same directory
            TempFile.Create(build2FileName);
            Assert.AreEqual(Path.GetDirectoryName(build1FileName), Path.GetDirectoryName(build2FileName));

            try {
                ConsoleDriver.GetBuildFileName(Path.GetDirectoryName(build1FileName), null, false);
                Assert.Fail("ApplicationException not thrown.");
            } catch (ApplicationException) {
            }
        }
Beispiel #2
0
        public void Test_FindInParentOption()
        {
            string baseDirectory = TempDir.Create(Path.Combine(TempDirName, "Find"));
            string buildFileName = Path.Combine(baseDirectory, "file.build");
            string subDirectory  = TempDir.Create(Path.Combine(baseDirectory, "SubDirectory"));

            // create a build file
            TempFile.Create(buildFileName);

            // find the build file from the sub directory
            Assert.AreEqual(buildFileName, ConsoleDriver.GetBuildFileName(subDirectory, null, true));

            // create a second build file
            string secondBuildFileName = Path.Combine(baseDirectory, "file2.build");

            TempFile.Create(secondBuildFileName);

            // try to find build file in sub directory
            // expect an exception - multiple *.build files found
            try {
                ConsoleDriver.GetBuildFileName(subDirectory, null, true);
                Assert.Fail("ApplicationException not thrown (#1).");
            } catch (ApplicationException) {
            }

            // try to find a build file that doesn't exist
            // expect an exception - build file not found
            //
            // however, we might find a "default.build" file if there's one in
            // one of the parent directories (eg. the root)
            try {
                string buildFile = ConsoleDriver.GetBuildFileName(subDirectory, "foobarmustnotexist.xml", true);
                if (Path.GetFileName(buildFile) != "default.build")
                {
                    Assert.Fail("ApplicationException not thrown (#2).");
                }
            } catch (ApplicationException) {
            }

            // try to find a build file with a bad pattern
            try {
                // buildFileName has a full path while GetBuildFileName will only accept a filename/pattern or null.
                ConsoleDriver.GetBuildFileName(subDirectory, buildFileName, true);
                Assert.Fail("Exception not thrown.");
            } catch {
            }

            // try to find specific build file in sub directory (expect success)
            Assert.AreEqual(buildFileName, ConsoleDriver.GetBuildFileName(subDirectory, Path.GetFileName(buildFileName), true));
        }