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); }
public void OverloadedParameterizedPropertyCanBeAccessed() { string result = ReferenceHost.Execute(NewlineJoin( "$a = Test-CreateOverloadedByArgumentNumbersParameterizedPropertiesObject", "$a.Grid(1, 2)" )); Assert.AreEqual(NewlineJoin("1, 2"), result); }
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); }
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); }
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); }
public void NameIsCaseInsensitive() { string result = ReferenceHost.Execute(new string[] { "$foo = 'bar'", "(Get-Variable -name FOO).Value" }); Assert.AreEqual("bar" + Environment.NewLine, result); }
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); }
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); }
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); }
public void CanAccessCSharpObjectField() { var result = ReferenceHost.Execute(NewlineJoin( "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'", "$a.MessageField" )); Assert.AreEqual(NewlineJoin("bar"), result); }
public void CanGetCustomCSharpObjectAndIdentifyType() { var result = ReferenceHost.Execute(NewlineJoin( "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)), "$a.GetType().FullName" )); Assert.AreEqual(NewlineJoin(typeof(CustomTestClass).FullName), result); }
public void MissingXmlProperty() { var result = ReferenceHost.Execute(NewlineJoin( "$path = [xml]\"<a>hello a</a>\"", "$path.z" )); Assert.AreEqual(NewlineJoin(), result); }
public void NoNameAndValueOnlyReturnsAllParameterValues() { string result = ReferenceHost.Execute(new string[] { "$foo = 'bar'", "Get-Variable -ValueOnly" }); StringAssert.Contains("bar" + Environment.NewLine, result); }
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); }
public void ByName() { string result = ReferenceHost.Execute(new string[] { "$foo = 'bar'", "(Get-Variable foo).Value" }); Assert.AreEqual("bar" + Environment.NewLine, result); }
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); }
public void PrivateVariableNotReturnedInWildcardSearch() { string result = ReferenceHost.Execute(new string[] { "New-Variable -name foo -visibility private", "Get-Variable fo?" }); Assert.AreEqual(String.Empty, result); }
public void SetAlias() { string result = ReferenceHost.Execute(new string[] { "$alias:AliasProviderTest = 'abc'", "$alias:AliasProviderTest" }); Assert.AreEqual("abc" + Environment.NewLine, result); }
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()"); }
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); }
public void InvokeGetMethodsWithOneParameter() { string result = ReferenceHost.Execute( @"$type = [System.Object] $type.GetMethods(20) | Foreach-Object { $_.name }" ); StringAssert.Contains("GetHashCode" + Environment.NewLine, result); }
public void ReadOnlyParameterizedPropertyCanBeAccessed() { string result = ReferenceHost.Execute(NewlineJoin( "$a = Test-CreateParameterizedPropertiesObject -ReadOnly -FileNames 'abc.txt'", "$a.FileNames(0)" )); Assert.AreEqual(NewlineJoin("abc.txt"), result); }
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); }
public void AccessingNonExistingPropertiesDoesntFail() { var result = ReferenceHost.Execute(NewlineJoin( "$a = New-Object -Type PSObject", "$a.testname" )); Assert.AreEqual(NewlineJoin(), result); }
public void NoParametersReturnsAllParameters() { string result = ReferenceHost.Execute(new string[] { "$foo = 'bar'", "Get-Variable| % { $_.Value }" }); StringAssert.Contains("bar" + Environment.NewLine, result); }
public void CanGetValueFromRootXmlElement() { var result = ReferenceHost.Execute(NewlineJoin( "$path = [xml]\"<a>hello a</a>\"", "$path.a" )); Assert.AreEqual(NewlineJoin("hello a"), result); }
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); }