Exemple #1
0
            public void ArrayOfTextNodeSubElement()
            {
                var result = ReferenceHost.Execute(NewlineJoin(
                                                       "$path = [xml]\"<a><b><c>CCC1</c><d>DDD1</d></b><b><c>CCC2</c><d>DDD1</d></b></a>\"",
                                                       "$path.a.b.c"
                                                       ));

                Assert.AreEqual(NewlineJoin("CCC1", "CCC2"), result);
            }
Exemple #2
0
        public void OverloadedParameterizedPropertyCanBeAccessed()
        {
            string result = ReferenceHost.Execute(NewlineJoin(
                                                      "$a = Test-CreateOverloadedByArgumentNumbersParameterizedPropertiesObject",
                                                      "$a.Grid(1, 2)"
                                                      ));

            Assert.AreEqual(NewlineJoin("1, 2"), result);
        }
Exemple #3
0
        public void OverloadedParameterizedPropertyWithDifferentReturnTypeCanBeReadFrom()
        {
            string result = ReferenceHost.Execute(NewlineJoin(
                                                      "$a = Test-CreateParameterizedPropertiesObject -DifferentReturnType -FileNames 'a.txt','b.txt'",
                                                      "$a.FileNames('b.txt')"
                                                      ));

            Assert.AreEqual(NewlineJoin("1"), result);
        }
Exemple #4
0
        public void NoMatchesInFile()
        {
            string fileName = CreateFile("first line", ".txt");

            string command = string.Format("(Select-string -Path '{0}' -Pattern 'notfound') -eq $null", fileName);
            string result  = ReferenceHost.Execute(command);

            Assert.AreEqual("True" + Environment.NewLine, result);
        }
Exemple #5
0
        public void QuietMatchesInLiteralFilePath(string fileContent, string command, string expectedResult)
        {
            string[] lines       = fileContent.Split(',');
            string   fileName    = CreateFile(NewlineJoin(lines), ".txt");
            string   fullCommand = string.Format("{0} -LiteralPath '{1}'", command, fileName);
            string   result      = ReferenceHost.Execute(fullCommand);

            Assert.AreEqual(expectedResult + Environment.NewLine, result);
        }
Exemple #6
0
        public void NameIsCaseInsensitive()
        {
            string result = ReferenceHost.Execute(new string[] {
                "$foo = 'bar'",
                "(Get-Variable -name FOO).Value"
            });

            Assert.AreEqual("bar" + Environment.NewLine, result);
        }
Exemple #7
0
        public void NameAndValueOnlyParameter()
        {
            string result = ReferenceHost.Execute(new string[] {
                "$foo = 'bar'",
                "Get-Variable foo -ValueOnly"
            });

            Assert.AreEqual("bar" + Environment.NewLine, result);
        }
        public void ListAllAliases()
        {
            string result = ReferenceHost.Execute(new string[] {
                "Set-Alias testalias Get-ChildItem",
                "Get-ChildItem alias: | ? { $_.Name -eq 'testalias' } | % { $_.Name }"
            });

            Assert.AreEqual("testalias" + Environment.NewLine, result);
        }
        public void ListSingleAlias()
        {
            string result = ReferenceHost.Execute(new string[] {
                "Set-Alias testalias Get-ChildItem",
                @"Get-ChildItem alias:testalias | % { $_.Name }"
            });

            Assert.AreEqual("testalias" + Environment.NewLine, result);
        }
Exemple #10
0
        public void AddTypeAddsAssemblyToCurrentAppDomain()
        {
            string result = ReferenceHost.Execute(
                @"Add-Type -AssemblyName 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[System.AppDomain]::CurrentDomain.GetAssemblies() | Foreach-Object { $_.fullname.split(',')[0] }
");

            StringAssert.Contains("System.Web" + Environment.NewLine, result);
        }
Exemple #11
0
        public void TypesFromAddedAssemblyAvailable()
        {
            string result = ReferenceHost.Execute(
                @"Add-Type -AssemblyName 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
[System.Web.HttpApplication].FullName
");

            StringAssert.Contains("System.Web.HttpApplication" + Environment.NewLine, result);
        }
Exemple #12
0
        public void CanAccessCSharpObjectField()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'",
                                                   "$a.MessageField"
                                                   ));

            Assert.AreEqual(NewlineJoin("bar"), result);
        }
Exemple #13
0
        public void CanGetCustomCSharpObjectAndIdentifyType()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)),
                                                   "$a.GetType().FullName"
                                                   ));

            Assert.AreEqual(NewlineJoin(typeof(CustomTestClass).FullName), result);
        }
Exemple #14
0
            public void MissingXmlProperty()
            {
                var result = ReferenceHost.Execute(NewlineJoin(
                                                       "$path = [xml]\"<a>hello a</a>\"",
                                                       "$path.z"
                                                       ));

                Assert.AreEqual(NewlineJoin(), result);
            }
Exemple #15
0
        public void NoNameAndValueOnlyReturnsAllParameterValues()
        {
            string result = ReferenceHost.Execute(new string[] {
                "$foo = 'bar'",
                "Get-Variable -ValueOnly"
            });

            StringAssert.Contains("bar" + Environment.NewLine, result);
        }
Exemple #16
0
        public void ListSingleAliasWithBackslashInDriveName()
        {
            string result = ReferenceHost.Execute(new string[] {
                "Set-Alias testalias Get-ChildItem",
                String.Format(@"Get-ChildItem alias:{0}testalias | % {{ $_.Name }}", Path.DirectorySeparatorChar)
            });

            Assert.AreEqual("testalias" + Environment.NewLine, result);
        }
Exemple #17
0
        public void ByName()
        {
            string result = ReferenceHost.Execute(new string[] {
                "$foo = 'bar'",
                "(Get-Variable foo).Value"
            });

            Assert.AreEqual("bar" + Environment.NewLine, result);
        }
Exemple #18
0
        public void GetContentForAlias()
        {
            string result = ReferenceHost.Execute(new string[] {
                "Set-Alias testalias Get-ChildItem",
                @"Get-Content alias:testalias"
            });

            Assert.AreEqual("Get-ChildItem" + Environment.NewLine, result);
        }
Exemple #19
0
        public void PrivateVariableNotReturnedInWildcardSearch()
        {
            string result = ReferenceHost.Execute(new string[] {
                "New-Variable -name foo -visibility private",
                "Get-Variable fo?"
            });

            Assert.AreEqual(String.Empty, result);
        }
Exemple #20
0
        public void SetAlias()
        {
            string result = ReferenceHost.Execute(new string[] {
                "$alias:AliasProviderTest = 'abc'",
                "$alias:AliasProviderTest"
            });

            Assert.AreEqual("abc" + Environment.NewLine, result);
        }
Exemple #21
0
        public void MatchInfoToStringShowsFileNameLineNumberAndLineText()
        {
            string fileName = CreateFile("first line", ".txt");

            string command = string.Format("(sls -Path '{0}' -Pattern 'first').ToString()", fileName);
            string result  = ReferenceHost.Execute(command);

            Assert.AreEqual(fileName + ":1:first line" + Environment.NewLine, result);
        }
        public void GetContent()
        {
            ReferenceHost.Execute("Get-Content -path TestContentCmdletProvider::foo");

            AssertMessagesAreEqual(
                "GetContentReader foo",
                "ContentReader.Read(1)",
                "ContentReader.Close()");
        }
Exemple #23
0
        public void MatchWhenPathFirstParameterAndPatternSecondAsNamedParameter()
        {
            string fileName = CreateFile("first line", ".txt");

            string command = string.Format("(Select-String '{0}' -Pattern 'first').ToString()", fileName);
            string result  = ReferenceHost.Execute(command);

            Assert.AreEqual(fileName + ":1:first line" + Environment.NewLine, result);
        }
Exemple #24
0
        public void InvokeGetMethodsWithOneParameter()
        {
            string result = ReferenceHost.Execute(
                @"$type = [System.Object]
$type.GetMethods(20) | Foreach-Object { $_.name }"
                );

            StringAssert.Contains("GetHashCode" + Environment.NewLine, result);
        }
Exemple #25
0
        public void ReadOnlyParameterizedPropertyCanBeAccessed()
        {
            string result = ReferenceHost.Execute(NewlineJoin(
                                                      "$a = Test-CreateParameterizedPropertiesObject -ReadOnly -FileNames 'abc.txt'",
                                                      "$a.FileNames(0)"
                                                      ));

            Assert.AreEqual(NewlineJoin("abc.txt"), result);
        }
Exemple #26
0
        public void ReturnEndsScriptAndWritesToPipeline()
        {
            var expected   = NewlineJoin("foo", "bar", "bla");
            var scriptname = CreateFile("'foo'; return 'bar'; 'baz'", "ps1");
            var command    = NewlineJoin(String.Format("& '{0}'", scriptname), "'bla'");
            var result     = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
Exemple #27
0
        public void AccessingNonExistingPropertiesDoesntFail()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = New-Object -Type PSObject",
                                                   "$a.testname"
                                                   ));

            Assert.AreEqual(NewlineJoin(), result);
        }
Exemple #28
0
        public void NoParametersReturnsAllParameters()
        {
            string result = ReferenceHost.Execute(new string[] {
                "$foo = 'bar'",
                "Get-Variable| % { $_.Value }"
            });

            StringAssert.Contains("bar" + Environment.NewLine, result);
        }
Exemple #29
0
            public void CanGetValueFromRootXmlElement()
            {
                var result = ReferenceHost.Execute(NewlineJoin(
                                                       "$path = [xml]\"<a>hello a</a>\"",
                                                       "$path.a"
                                                       ));

                Assert.AreEqual(NewlineJoin("hello a"), result);
            }
Exemple #30
0
            public void ArrayOfTextNodeElement()
            {
                var result = ReferenceHost.Execute(NewlineJoin(
                                                       "$path = [xml]\"<a><b>hello a</b><b>hello a</b></a>\"",
                                                       "$path.a.b"
                                                       ));

                Assert.AreEqual(NewlineJoin("hello a", "hello a"), result);
            }