Exemple #1
0
        /// <summary>
        /// Fire the OnExpected event handlers. This is considered a low-level method and should be used with
        /// caution only if there is not another more suitable alternative.
        /// </summary>
        /// <typeparam name="T">IComparable datatype that these values represent</typeparam>
        /// <param name="lowerValue">Lower boundry for a range</param>
        /// <param name="upperValue">Upper boundry for a range</param>
        /// <param name="testValue">Value being tested</param>
        /// <param name="message">Custom message with .Net {0} string format place holders</param>
        /// <param name="args">List of arguments that can be supplied to <paramref name="message"/>.  This will be
        /// added to final message</param>
        public bool AssertExpectedRange <T>(T testValue, T lowerValue, T upperValue, string message, params object[] args) where T : IComparable
        {
            GuardEventArgs eventArgs = new GuardEventArgs();

            eventArgs.ApplicationName = CoreConfig.ApplicationKey;
            eventArgs.TestValue       = testValue;
            eventArgs.FirstValue      = lowerValue;
            eventArgs.SecondValue     = upperValue;
            eventArgs.IsResult        = GuardCompareResult.Success;
            eventArgs.Message         = "";
            if (string.IsNullOrEmpty(message) == false)
            {
                eventArgs.Message = TextUtils.StringFormat(message, args);
            }
            if (string.IsNullOrEmpty(eventArgs.Message) == false)
            {
                eventArgs.Message += " ";
            }
            eventArgs.Message += eventArgs.IsResult.ToString().ToUpper() + " ";
            eventArgs.Message += string.Format("{0} Test Value: '{1}', ", typeof(T).FullName, lowerValue);
            eventArgs.Message += string.Format("First Value: '{0}'", testValue);
            eventArgs.Message += string.Format("Second Value: '{0}", upperValue);
            eventArgs.Message  = message;
            return(AssertExpected(eventArgs));
        }
Exemple #2
0
 /// <summary>
 /// Method that is called by default when validation fails.  Overwrite this to customize response
 /// </summary>
 /// <param name="eventArgs">Information about the value that is being Validated</param>
 private static void _defaultUnexpectedHandler(GuardEventArgs eventArgs)
 {
     //GuardInvalidException pe = new GuardInvalidException(eventArgs.ApplicationName, eventArgs.Message);
     //pe.Data.Add("ValidationDetails", eventArgs);
     ////Log.Error(pe);
     //throw pe;
     //do nothing
 }
Exemple #3
0
        /// <summary>
        /// Method that is called when an value with within expected parameters
        /// </summary>
        /// <param name="obj">Object that is being validated</param>
        /// <param name="message">Message that should be passed to any handler</param>
        /// <returns>Always returns true (object is valid)</returns>
        public bool AssertExpected(object obj, string message)
        {
            GuardEventArgs eventArgs = new GuardEventArgs();

            eventArgs.ApplicationName = CoreConfig.ApplicationKey;
            eventArgs.TestValue       = obj;
            eventArgs.IsResult        = GuardCompareResult.Success;
            AssertUnexpected(eventArgs);
            return(true);
        }
Exemple #4
0
 /// <summary>
 /// Fire the OnExpected event handlers.  This is considered a low-level method and should be used with
 /// caution only if there is not another more suitable alternative.
 /// </summary>
 /// <param name="eventArgs"></param>
 public bool AssertExpected(GuardEventArgs eventArgs)
 {
     if (OnExpectedEvents != null)
     {
         GuardValidEventHandler[] delegateList = (GuardValidEventHandler[])OnExpectedEvents.GetInvocationList();
         foreach (GuardValidEventHandler dlgate in delegateList)
         {
             dlgate.Invoke(eventArgs);
         }
     }
     return(true);
 }
Exemple #5
0
 /// <summary>
 /// Fire any OnUnexpected event handlers
 /// </summary>
 /// <param name="eventArgs"></param>
 /// <returns></returns>
 public bool AssertUnexpected(GuardEventArgs eventArgs)
 {
     if (OnUnexpectedEvents != null)
     {
         OnUnexpectedEvents(eventArgs);
         //IsValidEventHandler[] delegateList = (IsValidEventHandler[])OnUnexpectedEvents.GetInvocationList();
         //foreach (IsValidEventHandler dlgate in delegateList)
         //{
         //    dlgate.Invoke(eventArgs);
         //}
     }
     return(false);
 }
Exemple #6
0
        /// <summary>
        /// Fire the OnUnExpected event handlers. This is considered a low-level method and should be used with
        /// caution only if there is not another more suitable alternative.
        /// </summary>
        /// <param name="targetValue">Value that is being verified</param>
        /// <param name="expectedValue">Value that is expected</param>
        /// <param name="message">Custom message with .Net {0} string format place holders</param>
        /// <param name="args">List of arguments that can be supplied to <paramref name="message"/>.  This will be
        /// added to final message</param>
        public bool AssertUnexpected <T>(T?targetValue, T?expectedValue, string message, params object[] args) where T : struct
        {
            GuardEventArgs eventArgs = new GuardEventArgs();

            eventArgs.TestValue  = targetValue;
            eventArgs.FirstValue = expectedValue;
            eventArgs.IsResult   = GuardCompareResult.Failure;
            if (string.IsNullOrEmpty(message))
            {
                message = TextUtils.StringFormat(message, args);
            }
            if (string.IsNullOrEmpty(eventArgs.Message) == false)
            {
                eventArgs.Message += " ";
            }
            eventArgs.Message += eventArgs.IsResult.ToString().ToUpper() + " ";
            eventArgs.Message += string.Format("Nullable<{0}> Test Value: '{1}', ", typeof(T).FullName, targetValue);
            eventArgs.Message += string.Format("First Value: '{0}'", expectedValue);
            eventArgs.Message  = message;
            eventArgs.Message  = message;
            return(AssertUnexpected(eventArgs));
        }
Exemple #7
0
        /// <summary>
        /// Fire the OnUnExpected event handlers. This is considered a low-level method and should be used with
        /// caution only if there is not another more suitable alternative.
        /// </summary>
        /// <param name="targetValue">Value that is being verified</param>
        /// <param name="expectedValue">Value that is expected</param>
        /// <param name="message">Custom message with .Net {0} string format place holders</param>
        /// <param name="args">List of arguments that can be supplied to <paramref name="message"/>.  This will be
        /// added to final message</param>
        public bool AssertUnexpected <T>(T targetValue, T expectedValue, string message, params object[] args) where T : IComparable
        {
            GuardEventArgs eventArgs = new GuardEventArgs();

            eventArgs.ApplicationName = CoreConfig.ApplicationKey;
            eventArgs.TestValue       = targetValue;
            eventArgs.FirstValue      = expectedValue;
            eventArgs.IsResult        = GuardCompareResult.Failure;
            eventArgs.Message         = "";
            if (string.IsNullOrEmpty(message) == false)
            {
                eventArgs.Message = TextUtils.StringFormat(message, args);
            }
            if (string.IsNullOrEmpty(eventArgs.Message) == false)
            {
                eventArgs.Message += " ";
            }
            eventArgs.Message += eventArgs.IsResult.ToString().ToUpper() + " ";
            eventArgs.Message += string.Format("{0} Test Value '{1}', ", typeof(T).FullName, targetValue);
            eventArgs.Message += string.Format("First Value '{0}'", expectedValue);
            eventArgs.Message  = message;
            return(AssertUnexpected(eventArgs));
        }
Exemple #8
0
 /// <summary>
 /// Method that is called by default when validation fails.  Overwrite this to customize response
 /// </summary>
 /// <param name="eventArgs">Information about the value that is being Validated</param>
 private static void _defaultUnexpectedHandler(GuardEventArgs eventArgs)
 {
     //don't do anyting since this class returns value through method calls
 }
Exemple #9
0
 /// <summary>
 /// Method that is called by default when validation fails.  Overwrite this to customize response
 /// </summary>
 /// <param name="eventArgs">Information about the value that is being Validated</param>
 private static void _defaultUnexpectedHandler(GuardEventArgs eventArgs)
 {
     GuardViolationException pe = new GuardViolationException(eventArgs.ApplicationName, eventArgs.Message);
     pe.Data.Add("ValidationDetails", eventArgs);
     throw pe;
 }   
Exemple #10
0
 /// <summary>
 /// Method that is called by default when validation fails.  Overwrite this to customize response
 /// </summary>
 /// <param name="eventArgs">Information about the value that is being Validated</param>
 private static void _defaultUnexpectedHandler(GuardEventArgs eventArgs)
 {
     //don't do anyting since this class returns value through method calls
 }