Ejemplo n.º 1
0
 /// <summary>
 ///   Determines whether the specified <see cref = "EnvironmentVariable" /> is equal to this instance.
 /// </summary>
 /// <param name = "other">The <see cref = "EnvironmentVariable" /> to compare with this instance.</param>
 /// <returns>
 ///   <c>true</c> if the specified <see cref = "EnvironmentVariable" /> is equal to this instance; otherwise, <c>false</c>.
 /// </returns>
 public bool Equals(EnvironmentVariable other)
 {
     if (ReferenceEquals(null, other))
     {
         return false;
     }
     if (ReferenceEquals(this, other))
     {
         return true;
     }
     return Equals(other.mKey, mKey) && Equals(other.mValue, mValue);
 }
        public void CollectionChangedResetTest()
        {
            var kvp1 = new EnvironmentVariable("a", "b");
            var kvp2 = new EnvironmentVariable("d", "e");
            mEnvVars.Add(kvp1);
            mEnvVars.Add(kvp2);
            mCollectionChangedEvents.Clear();

            mEnvVars.Clear();
            Assert.That(mCollectionChangedEvents.Count, Is.EqualTo(1),
                        "CollectionChanged should have been fired once");
            Assert.AreEqual(NotifyCollectionChangedAction.Reset, mCollectionChangedEvents[0].Action);
        }
        public void CollectionChangedRemoveTest()
        {
            var kvp = new EnvironmentVariable("a", "b");
            mEnvVars.Add(kvp);
            mCollectionChangedEvents.Clear();

            mEnvVars.Remove(kvp);
            Assert.That(mCollectionChangedEvents.Count, Is.EqualTo(1),
                        "CollectionChanged should have been fired once");
            var e = mCollectionChangedEvents[0];

            Assert.AreEqual(NotifyCollectionChangedAction.Remove, e.Action);
            Assert.That(e.OldItems.Count, Is.EqualTo(1), "One old item should have been removed");
            Assert.AreEqual(kvp, e.OldItems[0]);
        }
        public void CollectionChangedAddTest()
        {
            var kvp = new EnvironmentVariable("a", "b");
            mEnvVars.Add(kvp);
            Assert.That(mCollectionChangedEvents.Count, Is.EqualTo(1),
                        "CollectionChanged should have been fired once");
            var e = mCollectionChangedEvents[0];
            Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
            Assert.That(e.NewItems.Count, Is.EqualTo(1), "One item should have been added");
            Assert.AreEqual(kvp, e.NewItems[0]);
            Assert.IsNull(e.OldItems, "There should be no old items");

            mEnvVars.Clear();
            mCollectionChangedEvents.Clear();

            mEnvVars[kvp.Key] = kvp.Value;
            Assert.That(mCollectionChangedEvents.Count, Is.EqualTo(1),
                        "CollectionChanged should have been fired once");
            e = mCollectionChangedEvents[0];
            Assert.AreEqual(NotifyCollectionChangedAction.Add, e.Action);
            Assert.That(e.NewItems.Count, Is.EqualTo(1), "One item should have been added");
            Assert.AreEqual(kvp, e.NewItems[0]);
            Assert.IsNull(e.OldItems, "There should be no old items");
        }
Ejemplo 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");
        }