Exemplo n.º 1
0
 public static AssertionContext <String> FileExists(this AssertionContext <String> source)
 {
     if (File.Exists(source.Value))
     {
         return(source);
     }
     else
     {
         throw new ArgumentException(String.Format(Properties.Resources.Assert_FileExists, source.Name, source.Value));
     }
 }
Exemplo n.º 2
0
 public static AssertionContext <SqlConnection> IsOpen(this AssertionContext <SqlConnection> value)
 {
     if (value.Value.State == ConnectionState.Open)
     {
         return(value);
     }
     else
     {
         throw new ArgumentException(String.Format(Utilities.Sql.Properties.Resources.Assert_IsOpen, value.Name));
     }
 }
Exemplo n.º 3
0
 public static AssertionContext <String> NotOnlyWhitespace(this AssertionContext <String> source)
 {
     if (source.Value.Trim() != "")
     {
         return(source);
     }
     else
     {
         throw new ArgumentException(String.Format(Properties.Resources.Assert_StringIsAllWhitespace, source.Name));
     }
 }
Exemplo n.º 4
0
 public static AssertionContext <T> BetweenExclusive <T>(this AssertionContext <T> source, T lowerBound, T upperBound)
     where T : IComparable <T>
 {
     if ((source.Value.CompareTo(lowerBound) > 0) && (source.Value.CompareTo(upperBound) < 0))
     {
         return(source);
     }
     else
     {
         throw new ArgumentException(String.Format(Properties.Resources.Assert_BetweenExclusive, source.Name, source.Value, lowerBound, upperBound));
     }
 }
Exemplo n.º 5
0
 public static AssertionContext <T> NotEqualTo <T>(this AssertionContext <T> source, T value)
     where T : IComparable <T>
 {
     if (source.Value.CompareTo(value) != 0)
     {
         return(source);
     }
     else
     {
         throw new ArgumentException(String.Format(Properties.Resources.Assert_EqualTo, source.Name, source.Value, value));
     }
 }
Exemplo n.º 6
0
 public static AssertionContext <T> NotNull <T>(this AssertionContext <T> source)
     where T : class
 {
     if (source.Value != null)
     {
         return(source);
     }
     else
     {
         throw new ArgumentNullException(source.Name);
     }
 }
Exemplo n.º 7
0
        public static AssertionContext <T> NotEmpty <T>(this AssertionContext <T> source)
            where T : IEnumerable
        {
            /* Some non-generic IEnumerator enumerators returned by IEnumerable.GetEnumerator()
             * implement IDisposable, while others do not.  Those enumerators
             * that do implement IDisposable will need to have their Dispose() method called.
             *
             * A non-generic IEnumerator cannot be used in a "using" statement.
             * So to make sure Dispose() is called (if it exists), "foreach" is used
             * because it will generate code to dispose of the IEnumerator
             * if the enumerator also implements IDisposable. */

            /* This loop will execute zero or more times,
             * and the foreach will dispose the enumerator, if necessary. */
            foreach (var _ in source.Value)
            {
                return(source); /* Loop executed once.  There is at least one element in the IEnumerable, which means it's not empty. */
            }
            /* Loop executed zero times, which means the IEnumerable is empty. */
            throw new ArgumentException(String.Format(Properties.Resources.Assert_ContainerIsEmpty, source.Name));
        }
Exemplo n.º 8
0
 public static AssertionContext <String> NotNullEmptyOrOnlyWhitespace(this AssertionContext <String> source)
 {
     return(source.NotNull().NotEmpty().NotOnlyWhitespace());
 }
Exemplo n.º 9
0
 public static AssertionContext <T> Name <T>(this AssertionContext <T> source, String name)
 {
     source.Name = name;
     return(source);
 }