Пример #1
0
        public void Test_Message()
        {
            // Arrange.
            var exception   = Throw();
            var errorRecord = Mock.Of <IErrorRecord>(er =>
                                                     er.Exception == exception &&
                                                     er.ScriptStackTrace == string.Empty);

            var error = new PSScriptError(errorRecord, new FileInfo(@"C:\Tests\Test-Stuff.ps1"));

            // Act.
            var message = error.Message;

            // Assert.
            Assert.Equal("Error!", message);
        }
Пример #2
0
        public void Test_StackTrace()
        {
            // Arrange.
            var exception   = Throw();
            var errorRecord = Mock.Of <IErrorRecord>(er =>
                                                     er.Exception == exception &&
                                                     er.ScriptStackTrace ==
                                                     @"at <ScriptBlock>, C:\Tests\Helpers.ps1: line 34
													  at Test-Things, <No file>: line 116"                                                    .Trim());

            var thisFilePath = GetThisFile();

            var error = new PSScriptError(errorRecord, new FileInfo(@"C:\Tests\Test-Stuff.ps1"));

            // Act.
            var stackTrace = error.StackTrace;

            // Assert.
            Assert.Equal(String.Format(
                             @"at {0}.{1}() in {2}:line 60
at Helpers.ps1 in C:\Tests\Helpers.ps1:line 34
at Test-Stuff.ps1:Test-Things() in C:\Tests\Test-Stuff.ps1:line 116", GetType().FullName, "Throw", thisFilePath),
                         stackTrace);
        }