Пример #1
0
 //protected ContractException() : this("Contract failed.") { }
 //protected ContractException(string message) : base(message) { }
 //protected ContractException(string message, Exception inner) : base(message, inner) { }
 public ContractException(ContractFailureKind kind, string user, string cond)
     : base(user + ": " + cond)
 {
     this.Kind      = kind;
     this.User      = user;
     this.Condition = cond;
 }
Пример #2
0
 public static string RaiseContractFailedEvent(System.Diagnostics.Contracts.ContractFailureKind kind, string user, string condition, Exception inner)
 {
     FailureCount++;
     if (condition != null)
     {
         if (user != null)
         {
             return(String.Format("{0} failed: {1}: {2}", kind, condition, user));
         }
         else
         {
             return(String.Format("{0} failed: {1}", kind, condition));
         }
     }
     else
     {
         if (user != null)
         {
             return(String.Format("{0} failed: {1}", kind, user));
         }
         else
         {
             return(String.Format("{0} failed.", kind));
         }
     }
 }
Пример #3
0
        internal static void RaiseContractFailure(SDC.ContractFailureKind kind, string message, string file, int line)
        {
            if (message == null)
            {
                switch (kind)
                {
                case SDC.ContractFailureKind.Assert: message = "An assertion was not met"; break;

                case SDC.ContractFailureKind.Precondition: message = "A pre-requisite was not met"; break;

                case SDC.ContractFailureKind.Postcondition: message = "A post-condition was not met"; break;

                default: message = "An expectation was not met"; break;
                }
            }
            if (file != null)
            {             // add the caller infos
                message = String.Format("{0} in {1}:line {2}", message, file, line);
            }

            //TODO: check if we are running under NUnit, and map to an Assert.Fail() instead ?

            Debug.Fail(message);
            // If you break here, that means that an assertion failed somewhere up the stack.
            // TODO: find a way to have the debugger break, but show the caller of Contract.Assert(..) method, instead of here ?
            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }

            throw new InvalidOperationException(message);
        }
 public ContractException(SDC.ContractFailureKind kind, string failure, string?userMessage, string?condition, Exception?innerException)
     : base(failure, innerException)
 {
     base.HResult     = -2146233022;
     this.Kind        = kind;
     this.UserMessage = userMessage;
     this.Condition   = condition;
 }
Пример #5
0
        public static void TriggerFailure(System.Diagnostics.Contracts.ContractFailureKind kind, string message, string user, string condition, Exception inner)
        {
            switch (kind)
            {
            case System.Diagnostics.Contracts.ContractFailureKind.Assert:
                throw new AssertException(user, condition);

            case System.Diagnostics.Contracts.ContractFailureKind.Assume:
                throw new AssumeException(user, condition);

            case System.Diagnostics.Contracts.ContractFailureKind.Invariant:
                throw new InvariantException(user, condition);

            case System.Diagnostics.Contracts.ContractFailureKind.Postcondition:
                throw new PostconditionException(user, condition);

            case System.Diagnostics.Contracts.ContractFailureKind.PostconditionOnException:
                throw new PostconditionOnThrowException(user, condition);

            case System.Diagnostics.Contracts.ContractFailureKind.Precondition:
                throw new PreconditionException(user, condition);
            }
        }