Наследование: System.Management.Automation.PSCmdlet
Пример #1
0
        public void InstallContextTest()
        {
            // Test that None is not supported.
            var cmdlet = new GetProductCommand();

            ExceptionAssert.Throws <ArgumentException>(() =>
            {
                cmdlet.UserContext = UserContexts.None;
            });

            var expected = new List <string>();

            expected.Add("{877EF582-78AF-4D84-888B-167FDC3BCC11}");
            expected.Add("{B4EA7821-1AC1-41B5-8021-A2FC77D1B7B7}");

            // Test that "Context" is a supported alias.
            using (var p = CreatePipeline(string.Format(@"get-msiproductinfo -context userunmanaged -usersid '{0}'", CurrentSID)))
            {
                using (OverrideRegistry())
                {
                    var objs = p.Invoke();

                    var actual = new List <string>(objs.Count);
                    foreach (var obj in objs)
                    {
                        actual.Add(obj.GetPropertyValue <string>("ProductCode"));
                    }

                    Assert.AreEqual <int>(expected.Count, objs.Count);
                    CollectionAssert.AreEquivalent(expected, actual);
                }
            }
        }
Пример #2
0
        public void UserSidTest()
        {
            var cmdlet = new GetProductCommand();

            // Test the default.
            Assert.AreEqual <string>(null, cmdlet.UserSid);

            // Test that what we explicitly set is returned.
            cmdlet.UserSid = "S-1-5-21-2127521184-1604012920-1887927527-2039434";
            Assert.AreEqual <string>("S-1-5-21-2127521184-1604012920-1887927527-2039434", cmdlet.UserSid);
        }
Пример #3
0
        public void EveryoneTest()
        {
            var cmdlet = new GetProductCommand();

            // Test that the default is false / not present.
            Assert.AreEqual <bool>(false, cmdlet.Everyone);
            Assert.AreEqual <bool>(false, cmdlet.Everyone.IsPresent);

            // Test that we can set it to true.
            cmdlet.Everyone = true;
            Assert.AreEqual <bool>(true, cmdlet.Everyone);
            Assert.AreEqual <string>(NativeMethods.World, cmdlet.UserSid);

            // Test that explicitly setting it to false nullifies the UserSid.
            cmdlet.Everyone = false;
            Assert.AreEqual <bool>(false, cmdlet.Everyone);
            Assert.AreEqual <string>(null, cmdlet.UserSid);
        }
Пример #4
0
        public void UserSidTest()
        {
            var cmdlet = new GetProductCommand();

            // Test the default.
            Assert.AreEqual<string>(null, cmdlet.UserSid);

            // Test that what we explicitly set is returned.
            cmdlet.UserSid = "S-1-5-21-2127521184-1604012920-1887927527-2039434";
            Assert.AreEqual<string>("S-1-5-21-2127521184-1604012920-1887927527-2039434", cmdlet.UserSid);
        }
Пример #5
0
        public void InstallContextTest()
        {
            // Test that None is not supported.
            var cmdlet = new GetProductCommand();
            ExceptionAssert.Throws<ArgumentException>(() =>
            {
                cmdlet.UserContext = UserContexts.None;
            });

            var expected = new List<string>();
            expected.Add("{877EF582-78AF-4D84-888B-167FDC3BCC11}");
            expected.Add("{B4EA7821-1AC1-41B5-8021-A2FC77D1B7B7}");

            // Test that "Context" is a supported alias.
            using (var p = CreatePipeline(string.Format(@"get-msiproductinfo -context userunmanaged -usersid '{0}'", CurrentSID)))
            {
                using (OverrideRegistry())
                {
                    var objs = p.Invoke();

                    var actual = new List<string>(objs.Count);
                    foreach (var obj in objs)
                    {
                        actual.Add(obj.GetPropertyValue<string>("ProductCode"));
                    }

                    Assert.AreEqual<int>(expected.Count, objs.Count);
                    CollectionAssert.AreEquivalent(expected, actual);
                }
            }
        }
Пример #6
0
        public void EveryoneTest()
        {
            var cmdlet = new GetProductCommand();

            // Test that the default is false / not present.
            Assert.AreEqual<bool>(false, cmdlet.Everyone);
            Assert.AreEqual<bool>(false, cmdlet.Everyone.IsPresent);

            // Test that we can set it to true.
            cmdlet.Everyone = true;
            Assert.AreEqual<bool>(true, cmdlet.Everyone);
            Assert.AreEqual<string>(NativeMethods.World, cmdlet.UserSid);

            // Test that explicitly setting it to false nullifies the UserSid.
            cmdlet.Everyone = false;
            Assert.AreEqual<bool>(false, cmdlet.Everyone);
            Assert.AreEqual<string>(null, cmdlet.UserSid);
        }