예제 #1
0
        public void DisplayTestFailed(MethodInfo methodInfo, Exception e)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("Test Failed: ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(methodInfo.DeclaringType.FullName + "." + methodInfo.Name + "\n");

            FailedException failedExecption = (FailedException)e.InnerException;

            Console.WriteLine(methodInfo.Name + " verification failed");
            Console.WriteLine("Expected : " + failedExecption.GetExpected() + " but was : " + failedExecption.GetObtained() + " : " + failedExecption.Message);           //ceci est le message d'erreur du TU s'il échoue
        }
예제 #2
0
        public override string ToString()
        {
            StringBuilder sbuilder = new StringBuilder();

            sbuilder.Append("Script status: ");
            if (Successful)
            {
                sbuilder.Append("Executed successfully");

                //IF SuccessfulNoError is FALSE, we need to report this
                if (SuccessfulNoError == false)
                {
                    sbuilder.Append(", but errors were reported");
                }

                sbuilder.AppendLine();
            }
            else
            {
                sbuilder.Append("Failed");
                //If _pipelineState is FAILED, we ignore this. Else the result is "Failed [Pipeline state FAILED]"
                if (_pipelineState != PSInvocationState.Failed)
                {
                    sbuilder.Append(string.Format(" [Pipeline state {0}]", _pipelineState));
                }
                sbuilder.AppendLine();

                sbuilder.AppendLine("-EXCEPTION------------------------");
                if (FailedException != null)
                {
                    sbuilder.AppendLine(FailedException.ToString());
                }
                else
                {
                    sbuilder.AppendLine("No exception found");
                }
                sbuilder.AppendLine("----------------------------------");
            }
            sbuilder.AppendLine();

            Collection <UniversalStreamRecord> universalRecordCollection;

            //MTH: We are moving down the streams in this order: Output(1), Error(2), Warning(3), Verbose(4), Debug(5) and finally the Variables
            //See [Understanding Streams, Redirection, and Write-Host in PowerShell](blogs.technet.com/b/heyscriptingguy/archive/2014/03/30/understanding-streams-redirection-and-write-host-in-powershell.aspx)
            universalRecordCollection = UniversalStreamRecord.FromPSObjectPSCollection(StreamOutput);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Output));

            //MTH: This will list all non-terminating errors. In fact, these ARE real errors but normally $ErrorActionPreference is set to "Continue" - which is the default.
            //If set to $ErrorActionPreference = "Stop", any error will become terminating.
            //See: [Managing non-terminating errors](http://blogs.msdn.com/b/powershell/archive/2006/04/25/583241.aspx)
            universalRecordCollection = UniversalStreamRecord.FromErrorRecordPSCollection(StreamError);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Error));

            //Only contains entires when $WarningPreference = 'Continue' - this is the default in PowerShell
            universalRecordCollection = UniversalStreamRecord.FromInformationalRecordPSCollection(StreamWarning);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Warning));

            //Only contains entries when $VerbosePreference = 'Continue'
            universalRecordCollection = UniversalStreamRecord.FromInformationalRecordPSCollection(StreamVerbose);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Verbose));

            //Only contains entries when $DebugPreference = 'Continue'
            universalRecordCollection = UniversalStreamRecord.FromInformationalRecordPSCollection(StreamDebug);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, PSStreamNameEnum.Debug));

            //Add the variables but only if read/write variables were passed in (second paramter FALSE)
            universalRecordCollection = UniversalStreamRecord.FromVariablePlainHashSet(Variables, false);
            sbuilder.AppendLine(UniversalStreamRecordCollectionToString(universalRecordCollection, "Writeable variables:", "No writeable variable exist"));

            return(sbuilder.ToString());
        }