123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using System;
- using System.Diagnostics;
- using System.Threading;
- using System.Windows;
- namespace Standard;
- internal static class Assert
- {
- private static void _Break()
- {
- Debugger.Break();
- }
- [Conditional("DEBUG")]
- public static void Evaluate(Assert.EvaluateFunction argument)
- {
- argument();
- }
- [Obsolete("Use Assert.AreEqual instead of Assert.Equals", false)]
- [Conditional("DEBUG")]
- public static void Equals<T>(T expected, T actual)
- {
- }
- [Conditional("DEBUG")]
- public static void AreEqual<T>(T expected, T actual)
- {
- if (expected == null)
- {
- if (actual != null && !actual.Equals(expected))
- {
- Assert._Break();
- return;
- }
- }
- else if (!expected.Equals(actual))
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void AreNotEqual<T>(T notExpected, T actual)
- {
- if (notExpected == null)
- {
- if (actual == null || actual.Equals(notExpected))
- {
- Assert._Break();
- return;
- }
- }
- else if (notExpected.Equals(actual))
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void Implies(bool condition, bool result)
- {
- if (condition && !result)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void Implies(bool condition, Assert.ImplicationFunction result)
- {
- if (condition && !result())
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsNeitherNullNorEmpty(string value)
- {
- }
- [Conditional("DEBUG")]
- public static void IsNeitherNullNorWhitespace(string value)
- {
- if (string.IsNullOrEmpty(value))
- {
- Assert._Break();
- }
- if (value.Trim().Length == 0)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsNotNull<T>(T value) where T : class
- {
- if (value == null)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsDefault<T>(T value) where T : struct
- {
- value.Equals(default(T));
- }
- [Conditional("DEBUG")]
- public static void IsNotDefault<T>(T value) where T : struct
- {
- value.Equals(default(T));
- }
- [Conditional("DEBUG")]
- public static void IsFalse(bool condition)
- {
- if (condition)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsFalse(bool condition, string message)
- {
- if (condition)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsTrue(bool condition)
- {
- if (!condition)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsTrue(bool condition, string message)
- {
- if (!condition)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void Fail()
- {
- Assert._Break();
- }
- [Conditional("DEBUG")]
- public static void Fail(string message)
- {
- Assert._Break();
- }
- [Conditional("DEBUG")]
- public static void IsNull<T>(T item) where T : class
- {
- if (item != null)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void BoundedDoubleInc(double lowerBoundInclusive, double value, double upperBoundInclusive)
- {
- if (value < lowerBoundInclusive || value > upperBoundInclusive)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void BoundedInteger(int lowerBoundInclusive, int value, int upperBoundExclusive)
- {
- if (value < lowerBoundInclusive || value >= upperBoundExclusive)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsApartmentState(ApartmentState expectedState)
- {
- if (Thread.CurrentThread.GetApartmentState() != expectedState)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void NullableIsNotNull<T>(T? value) where T : struct
- {
- if (value == null)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void NullableIsNull<T>(T? value) where T : struct
- {
- if (value != null)
- {
- Assert._Break();
- }
- }
- [Conditional("DEBUG")]
- public static void IsNotOnMainThread()
- {
- if (Application.Current.Dispatcher.CheckAccess())
- {
- Assert._Break();
- }
- }
- public delegate void EvaluateFunction();
- public delegate bool ImplicationFunction();
- }
|