예제 #1
0
        public void CmdletPipeParamByPropertyNameCantBePartial()
        {
            var cmd = "new-object psobject -property @{f='abc'; b='def'} | "
                      + CmdletName(typeof(TestParametersByPipelinePropertyNamesCommand));

            Assert.Throws <MethodInvocationException>(() => {
                ReferenceHost.Execute(cmd);
            });
        }
예제 #2
0
        public void NewObjectCanCreatePSObject()
        {
            var results = ReferenceHost.RawExecute("New-Object -Type PSObject");

            Assert.AreEqual(1, results.Count, "No results");
            var obj = results[0].BaseObject;

            Assert.True(obj is PSCustomObject);
        }
예제 #3
0
        public void CmdletPipeParamByPropertyNameIgnoresAlreadyBound(string parameters, string expected)
        {
            var cmd = "new-object psobject -property @{foo='abc'; bar='def'} | "
                      + CmdletName(typeof(TestParametersByPipelinePropertyNamesCommand))
                      + parameters;
            var result = ReferenceHost.Execute(cmd);

            Assert.AreEqual(expected + Environment.NewLine, result);
        }
예제 #4
0
        public void CmdletPipeParamByPropertyNameCanBeAlias()
        {
            var cmd = "new-object psobject -property @{baz='abc'; b='def'} | "
                      + CmdletName(typeof(TestParametersByPipelinePropertyNamesCommand));
            var expected = "abc " + Environment.NewLine;
            var result   = ReferenceHost.Execute(cmd);

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

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

            Assert.AreEqual(NewlineJoin(typeof(CustomTestClass).FullName), result);
        }
예제 #7
0
        public void CanAccessCSharpObjectProperty()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'",
                                                   "$a.MessageProperty"
                                                   ));

            Assert.AreEqual(NewlineJoin("foo"), result);
        }
예제 #8
0
파일: ArrayTests.cs 프로젝트: prateek/Pash
        public void ElementsFromPipelineAreStoredAsArray()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = @('foo', 'bar', 'baz') | " + CmdletName(typeof(TestCmdletPhasesCommand)),
                                                   "$a.GetType().FullName"
                                                   ));

            Assert.AreEqual(NewlineJoin(typeof(object[]).FullName), result);
        }
예제 #9
0
파일: ReturnTests.cs 프로젝트: prateek/Pash
        public void ReturnEndsScriptAndWritesToPipeline()
        {
            var expected   = NewlineJoin("foo", "bar", "bla");
            var scriptname = CreateScript("'foo'; return 'bar'; 'baz'");
            var command    = NewlineJoin(String.Format("& '{0}'", scriptname), "'bla'");
            var result     = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
예제 #10
0
        public void CmdletPipeParamByPropertyFailsIfAllAreAlreadyBound()
        {
            var cmd = "new-object psobject -property @{foo='abc'; bar='def'} | "
                      + CmdletName(typeof(TestParametersByPipelinePropertyNamesCommand))
                      + " -Foo 'a' -Bar 'a'";

            Assert.Throws <MethodInvocationException>(() => {
                ReferenceHost.Execute(cmd);
            });
        }
예제 #11
0
        public void CmdletPipeParamByPropertyNameCanOnlyProvideOptional()
        {
            var cmd = "new-object psobject -property @{bar='def'} | "
                      + CmdletName(typeof(TestParametersByPipelinePropertyNamesCommand))
                      + " -Foo 'a'";
            var expected = "a def" + Environment.NewLine;
            var result   = ReferenceHost.Execute(cmd);

            Assert.AreEqual(expected, result);
        }
예제 #12
0
        public static void ExecuteAndCompareType(string cmd, params Type[] expectedTypes)
        {
            var results = ReferenceHost.RawExecute(cmd);

            Assert.AreEqual(expectedTypes.Length, results.Count);
            for (int i = 0; i < expectedTypes.Length; i++)
            {
                Assert.AreSame(expectedTypes[i], results[i].BaseObject.GetType());
            }
        }
예제 #13
0
        public void CanSetCSharpObjectField()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'",
                                                   "$a.MessageField = 'baz'",
                                                   "$a.MessageField"
                                                   ));

            Assert.AreEqual(NewlineJoin("baz"), result);
        }
예제 #14
0
        public void CustomPSObjectPropertiesCanBeAccessedCaseInsensitive()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = New-Object -Type PSObject",
                                                   "$a | Add-Member -Type NoteProperty -Name TestName -Value TestValue",
                                                   "$a.testname"
                                                   ));

            Assert.AreEqual(NewlineJoin("TestValue"), result);
        }
예제 #15
0
        public void CreatePSObjectWithPropertiesByHashtable()
        {
            var result = ReferenceHost.Execute(NewlineJoin(new string[] {
                "$obj = new-object psobject -property @{foo='abc'; bar='def'}",
                "$obj.FoO",
                "$obj.bAR"
            }));
            var expected = NewlineJoin(new string[] { "abc", "def" });

            Assert.AreEqual(expected, result);
        }
예제 #16
0
        public void TwoParameterAmbiguousSetsWhenNoParameterPassedShouldNotExecuteCmdlet()
        {
            var cmd = CmdletName(typeof(TestTwoAmbiguousParameterSetsCommand));
            var ex  = Assert.Throws <ParameterBindingException>(() =>
            {
                ReferenceHost.Execute(cmd);
            }
                                                                );

            StringAssert.Contains("Ambiguous", ex.ErrorRecord.FullyQualifiedErrorId);
        }
예제 #17
0
파일: ReturnTests.cs 프로젝트: prateek/Pash
        public void ReturnEvaluatesExpression(string returnValue, string returnExpression)
        {
            var expected = NewlineJoin("foo", returnValue, "bla");
            var command  = NewlineJoin(
                "& { $testvar = 'TESTVALUE'; 'foo'; return " + returnExpression + "; 'baz' }",
                "'bla'"
                );
            var result = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
예제 #18
0
        public void CmdletParameterWithSameAliasDontWork()
        {
            var cmd = CmdletName(typeof(TestSameAliasesCommand));

            Assert.Throws(typeof(MetadataException),
                          delegate()
            {
                ReferenceHost.Execute(cmd);
            }
                          );
        }
예제 #19
0
파일: ReturnTests.cs 프로젝트: prateek/Pash
        public void ReturnEndsFunctionAndWritesToPipeline()
        {
            var expected = NewlineJoin("foo", "bar", "bla");
            var command  = NewlineJoin(
                "function testfun { 'foo'; return 'bar'; 'baz' }",
                "testfun",
                "'bla'"
                );
            var result = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
예제 #20
0
        public void UseParameterByAmbiguousNamePrefixThrows()
        {
            var cmd = CmdletName(typeof(TestMandatoryInOneSetCommand)) + " -TestP 'foo'"; // could be TestParam or TestParam2
            var ex  = Assert.Throws(typeof(ParameterBindingException),
                                    delegate()
            {
                ReferenceHost.Execute(cmd);
            }
                                    ) as ParameterBindingException;

            StringAssert.Contains("Ambiguous", ex.ErrorRecord.FullyQualifiedErrorId);
        }
예제 #21
0
        public void NoDefaultSetAndPositionalsResultsInAmbiguousError()
        {
            var cmd = CmdletName(typeof(TestNoDefaultSetAndTwoPositionalsCommand)) + " foo";
            var ex  = Assert.Throws(typeof(ParameterBindingException),
                                    delegate()
            {
                ReferenceHost.Execute(cmd);
            }
                                    ) as ParameterBindingException;

            StringAssert.Contains("Ambiguous", ex.ErrorRecord.FullyQualifiedErrorId);
        }
예제 #22
0
        public void OnlyOneParameterSetCanBeActive()
        {
            var cmd = CmdletName(typeof(TestNoMandatoriesCommand)) + " -RandomString 'foo' -RandomInt 2";
            var ex  = Assert.Throws(typeof(ParameterBindingException),
                                    delegate()
            {
                ReferenceHost.Execute(cmd);
            }
                                    ) as ParameterBindingException;

            StringAssert.Contains("Ambiguous", ex.ErrorRecord.FullyQualifiedErrorId);
        }
예제 #23
0
        public void CanGetCSharpObjectMethodAndInvokeLater()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'",
                                                   "$b = $a.SetMessages",
                                                   "$c = $a.Combine",
                                                   "$b.Invoke('bla', 'blub')",
                                                   "$c.Invoke()"
                                                   ));

            Assert.AreEqual(NewlineJoin("blablub"), result);
        }
예제 #24
0
        public void CanInvokeCSharpObjectMethodWithArguments()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'",
                                                   "$a.SetMessages('bla', 'blub')",
                                                   "$a.MessageProperty",
                                                   "$a.MessageField"
                                                   ));
            var expected = NewlineJoin("bla", "blub");

            Assert.AreEqual(expected, result);
        }
예제 #25
0
        public void CanInvokeCSharpObjectMethodAndGetResult()
        {
            var result = ReferenceHost.Execute(NewlineJoin(
                                                   "$a = " + CmdletName(typeof(TestCreateCustomObjectCommand)) + " 'foo' 'bar'",
                                                   "$b = $a.Combine()",
                                                   "$b.GetType().FullName",
                                                   "$b"
                                                   ));
            var expected = NewlineJoin(typeof(string).FullName, "foobar");

            Assert.AreEqual(expected, result);
        }
예제 #26
0
파일: ExitTests.cs 프로젝트: prateek/Pash
        public void ExpressionsAreValidExitCodes(string expectedExitCode, string exitExpression)
        {
            var scriptname = CreateScript(NewlineJoin("exit " + exitExpression));
            var command    = NewlineJoin(
                String.Format(". '{0}'", scriptname),
                "$LastExitCode"
                );
            var expected = NewlineJoin(expectedExitCode);
            var result   = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
예제 #27
0
파일: ReturnTests.cs 프로젝트: prateek/Pash
        public void ReturnEndsScriptBlockAndWritesToPipeline()
        {
            var expected = NewlineJoin("foo", "bar", "bla");
            var command  = NewlineJoin(
                "'foo'",
                "& { return 'bar'; 'baz' }",
                "'bla'"
                );
            var result = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
예제 #28
0
        public void ParameterSetWithoutMandatoriesIsNotChosenOverDefaultWithMandatory()
        {
            var cmd = CmdletName(typeof(TestMandatoryInOneSetCommand)) + " 'works'";
            var ex  = Assert.Throws(typeof(ParameterBindingException),
                                    delegate()
            {
                ReferenceHost.Execute(cmd);
            }
                                    ) as ParameterBindingException;

            StringAssert.Contains("Missing", ex.ErrorRecord.FullyQualifiedErrorId);
        }
예제 #29
0
파일: ExitTests.cs 프로젝트: prateek/Pash
        public void ExitInScriptBlockExitsCompletely()
        {
            var command = NewlineJoin(
                "'foo'",
                "& { 'bar'; exit; 'baz'; }",
                "'blub'"
                );
            var expected = NewlineJoin("foo", "bar");
            var result   = ReferenceHost.Execute(command);

            Assert.AreEqual(expected, result);
        }
예제 #30
0
        public void TooManyPositionalParametersShouldThrow()
        {
            var cmd = CmdletName(typeof(TestMandatoryInOneSetCommand)) + " 'foo' 'bar' 'baz' 'bla'";
            var ex  = Assert.Throws(typeof(ParameterBindingException),
                                    delegate()
            {
                ReferenceHost.Execute(cmd);
            }
                                    ) as ParameterBindingException;

            StringAssert.Contains("PositionalParameterNotFound", ex.ErrorRecord.FullyQualifiedErrorId);
        }