Exemplo n.º 1
0
        public void AreEqualTest()
        {
            var launcher = new Launcher();
            var other = new Launcher();

            Assert.AreEqual(launcher, other, "Blank launchers should be equal");

            launcher.Arguments = "a";
            other.Arguments = "a";
            Assert.AreEqual(launcher, other, "Launchers with the same arguments should be equal");

            launcher.File = "file";
            other.File = "file";
            Assert.AreEqual(launcher, other, "Launchers with the same file should be equal");

            launcher.Name = "test";
            other.Name = "test";
            Assert.AreEqual(launcher, other, "Launchers with the same name should be equal");

            launcher.WorkingDirectory = "wd";
            other.WorkingDirectory = "wd";
            Assert.AreEqual(launcher, other, "Launchers with the same working directory should be equal");

            launcher.EnvironmentVariables["a"] = "a";
            other.EnvironmentVariables["a"] = "a";
            launcher.EnvironmentVariables["b"] = "b";
            other.EnvironmentVariables["b"] = "b";
            Assert.AreEqual(launcher, other, "Launchers with the same environment variables should be equal");
        }
Exemplo n.º 2
0
        public void HasChangesTest()
        {
            LaunchGroup group = new LaunchGroup();
            LaunchGroup childGroup = new LaunchGroup();
            Launcher childLauncher = new Launcher();

            Assert.IsFalse(group.HasChanges);

            group.Name = "a";
            Assert.IsTrue(group.HasChanges, "Changing Name should cause HasChanges to be true");

            group.ClearAllHasChanges();
            group.EnvironmentVariables.Add(new EnvironmentVariable("A", "A"));
            Assert.IsTrue(group.HasChanges, "New environment variables should cause HasChanges to be true");

            group.ClearAllHasChanges();
            group.EnvironmentVariables["A"] = "B";
            Assert.IsTrue(group.HasChanges, "Updating environment variables should cause HasChanges to be true");

            group.ClearAllHasChanges();
            group.Groups.Add(childGroup);
            Assert.IsTrue(group.HasChanges, "New child groups should cause HasChages to be true");

            group.ClearAllHasChanges();
            childGroup.Name = "a";
            Assert.IsTrue(group.HasChanges, "Changes to child groups should cause HasChanges to be true");

            group.ClearAllHasChanges();
            group.Launchers.Add(childLauncher);
            Assert.IsTrue(group.HasChanges, "New child launchers should cause HasChanges to be true");

            group.ClearAllHasChanges();
            childLauncher.Name = "A";
            Assert.IsTrue(group.HasChanges, "Changes to child launchers should cause HasChanges to be true");
        }
Exemplo n.º 3
0
        public void AggregateEnvironmentVariablesTest()
        {
            var launcher = new Launcher();
            LaunchGroup group =
                new LaunchGroup(null,
                                new[]
                                    {
                                        new LaunchGroup(null,
                                                        null,
                                                        new[]
                                                            {
                                                                launcher
                                                            }),
                                    });

            group.EnvironmentVariables.UpdateWith(
                new EnvironmentVariable("A", "A"),
                new EnvironmentVariable("B", "B"),
                new EnvironmentVariable("D", "D"));

            group.Groups[0].EnvironmentVariables.UpdateWith(
                new EnvironmentVariable("C", "C"),
                new EnvironmentVariable("B", "B2"));

            launcher.EnvironmentVariables.UpdateWith(
                new EnvironmentVariable("D", "D2"),
                new EnvironmentVariable("E", "E"));

            var envVars = launcher.AggregateEnvironmentVariables();

            Assert.That(envVars, Contains.Item(new EnvironmentVariable("A", "A")));
            Assert.That(envVars, Contains.Item(new EnvironmentVariable("B", "B2")));
            Assert.That(envVars, Contains.Item(new EnvironmentVariable("C", "C")));
            Assert.That(envVars, Contains.Item(new EnvironmentVariable("D", "D2")));
            Assert.That(envVars, Contains.Item(new EnvironmentVariable("E", "E")));
        }
Exemplo n.º 4
0
        public void WorkingDirectoryValidationTest()
        {
            Launcher launcher = new Launcher();
            launcher.WorkingDirectory = string.Empty;

            var wdError = launcher[Property<Launcher>.Name(p => p.WorkingDirectory)];

            Assert.IsTrue(string.IsNullOrEmpty(wdError),
                          "The WorkingDirectory property should not cause an error if it is empty");

            string nonexistentDirectory;
            do
            {
                nonexistentDirectory = Guid.NewGuid().ToString();
            } while (Directory.Exists(nonexistentDirectory));

            launcher.WorkingDirectory = nonexistentDirectory;
            wdError = launcher[Property<Launcher>.Name(p => p.WorkingDirectory)];
            Assert.IsFalse(string.IsNullOrEmpty(wdError),
                           "The WorkingDirectory property should cause an error when the directory doesn't exist");

            launcher.WorkingDirectory = Path.GetDirectoryName(_GetExistingFilePath());
            wdError = launcher[Property<Launcher>.Name(p => p.WorkingDirectory)];
            Assert.IsTrue(Directory.Exists(launcher.WorkingDirectory),
                          "The directory {0} must exist for this test to complete successfully",
                          launcher.WorkingDirectory);
            Assert.IsTrue(string.IsNullOrEmpty(wdError),
                          "The WorkingDirectory property should not cause an error when the directory exists");
        }
Exemplo n.º 5
0
        public void LaunchWithEnvironmentVariablesTest()
        {
            const string SCRIPT_NAME = "test.bat";
            string scriptPath = Path.Combine(mTempDir, SCRIPT_NAME);
            string testFilePath = Path.Combine(mTempDir, "test.txt");
            string script = @"
            @echo %v1%>>""" + testFilePath + @"""
            @echo %v2%>>""" + testFilePath + @"""
            @echo %v3%>>""" + testFilePath + @"""";

            var v1 = new EnvironmentVariable("v1", "{E16620DD-D150-4F2C-B4AE-DBC54E72373C}");
            var v2 = new EnvironmentVariable("v2", "{4EB5E514-BF79-43B1-A535-0BB5AAD4D60F}");
            var v3 = new EnvironmentVariable("v3", "{9DD27426-93AF-46D0-81DE-4073EDBC7664}");

            File.WriteAllText(scriptPath, script);

            Launcher launcher = new Launcher();
            launcher.File = scriptPath;
            launcher.EnvironmentVariables.Add(v1);
            launcher.EnvironmentVariables.Add(v2);
            launcher.EnvironmentVariables.Add(v3);

            Process process = launcher.Launch();
            process.WaitForExit();

            Assert.IsTrue(process.HasExited, "Process should have exited");
            Assert.IsTrue(File.Exists(testFilePath), "Process should have created the file '{0}'", testFilePath);

            string[] contents = File.ReadAllLines(testFilePath);
            Assert.That(contents.Length, Is.EqualTo(3),
                        "There should have been three lines in the output file");
            Assert.AreEqual(v1.Value, contents[0], "The first environment variable value was wrong");
            Assert.AreEqual(v2.Value, contents[1], "The second environment variable value was wrong");
            Assert.AreEqual(v3.Value, contents[2], "The third environment variable value was wrong");
        }
Exemplo n.º 6
0
        public void LaunchTest()
        {
            const string SCRIPT_NAME = "test.bat";
            string scriptPath = Path.Combine(mTempDir, SCRIPT_NAME);
            string testFilePath = Path.Combine(mTempDir, "test.txt");
            string script = @"@echo test>""" + testFilePath + @"""";

            File.WriteAllText(scriptPath, script);

            Launcher launcher = new Launcher();
            launcher.File = scriptPath;

            Process process = launcher.Launch();
            process.WaitForExit();

            Assert.IsTrue(process.HasExited, "Process should have exited");
            Assert.IsTrue(File.Exists(testFilePath), "Process should have created the file '{0}'", testFilePath);
        }
Exemplo n.º 7
0
        public void HasChangesTest()
        {
            Launcher launcher = new Launcher();
            Assert.IsFalse(launcher.HasChanges);

            launcher.File = "a";
            Assert.IsTrue(launcher.HasChanges, "Updating File should cause HasChanges to be true");

            launcher.HasChanges = false;
            launcher.Name = "a";
            Assert.IsTrue(launcher.HasChanges, "Updating Name should cause HasChanges to be true");

            launcher.HasChanges = false;
            launcher.Parent = new LaunchGroup();
            Assert.IsTrue(launcher.HasChanges, "Updating Parent should cause HasChanges to be true");

            launcher.HasChanges = false;
            launcher.WorkingDirectory = "a";
            Assert.IsTrue(launcher.HasChanges, "Updating WorkingDirectory should cause HasChanges to be true");

            launcher.HasChanges = false;
            launcher.EnvironmentVariables.Add(new EnvironmentVariable("a", "b"));
            Assert.IsTrue(launcher.HasChanges, "New environment variables should cause HasChanges to be true");

            launcher.HasChanges = false;
            launcher.EnvironmentVariables["a"] = "c";
            Assert.IsTrue(launcher.HasChanges, "Updating environment variables should cause HasChanges to be true");
        }
Exemplo n.º 8
0
        public void FileValidationTest()
        {
            Launcher launcher = new Launcher();
            launcher.File = string.Empty;

            var fileError = launcher[Property<Launcher>.Name(p => p.File)];

            Assert.IsFalse(string.IsNullOrEmpty(fileError), "The File property should cause an error when empty");

            string nonexistentFile;
            do
            {
                nonexistentFile = Guid.NewGuid().ToString();
            } while (File.Exists(nonexistentFile));

            launcher.File = nonexistentFile;
            fileError = launcher[Property<Launcher>.Name(p => p.File)];
            Assert.IsFalse(string.IsNullOrEmpty(fileError),
                           "The File property should cause an error when the file doesn't exist");

            launcher.File = _GetExistingFilePath();
            fileError = launcher[Property<Launcher>.Name(p => p.File)];
            Assert.IsTrue(File.Exists(launcher.File),
                          "The file {0} must exist for this test to complete successfully",
                          launcher.File);
            Assert.IsTrue(string.IsNullOrEmpty(fileError),
                          "The File property should not cause an error when the file exists");
        }
Exemplo n.º 9
0
        public void AreNotEqualTest()
        {
            var launcher = new Launcher {Arguments = "a"};
            var other = new Launcher {Arguments = "b"};
            Assert.AreNotEqual(launcher, other, "Launchers with different arguments should not be equal");

            launcher = new Launcher {File = "a"};
            other = new Launcher {File = "b"};
            Assert.AreNotEqual(launcher, other, "Launchers with different files should not be equal");

            launcher = new Launcher {Name = "a"};
            other = new Launcher {Name = "b"};
            Assert.AreNotEqual(launcher, other, "Launchers with different names should not be equal");

            launcher = new Launcher {WorkingDirectory = "a"};
            other = new Launcher {WorkingDirectory = "b"};
            Assert.AreNotEqual(launcher, other, "Launchers with different working directories should not be equal");

            launcher = new Launcher();
            other = new Launcher();
            launcher.EnvironmentVariables["a"] = "a";
            other.EnvironmentVariables["b"] = "b";
            Assert.AreNotEqual(launcher, other, "Launchers with different environment variables should not be equal");
        }
Exemplo n.º 10
0
 /// <summary>
 ///   Determines whether the specified <see cref = "Launcher" /> is equal to the current <see cref = "Launcher" />.
 /// </summary>
 /// <returns>
 ///   true if the specified <see cref = "Launcher" /> is equal to the current <see cref = "Launcher" />; otherwise, false.
 /// </returns>
 /// <param name = "other">The <see cref = "Launcher" /> to compare with the current <see cref = "Launcher" />. </param>
 /// <filterpriority>2</filterpriority>
 public bool Equals(Launcher other)
 {
     if (ReferenceEquals(null, other))
     {
         return false;
     }
     if (ReferenceEquals(this, other))
     {
         return true;
     }
     return Equals(other.mEnvironmentVariables, mEnvironmentVariables) &&
            Equals(other.mArguments, mArguments) &&
            Equals(other.mFile, mFile) &&
            Equals(other.mName, mName) &&
            Equals(other.mWorkingDirectory, mWorkingDirectory);
 }