AssertionMessageUtil.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace XGame.Framework.Assertions
  3. {
  4. internal class AssertionMessageUtil
  5. {
  6. const string k_Expected = "Expected:";
  7. const string k_AssertionFailed = "Assertion failure.";
  8. public static string GetMessage(string failureMessage)
  9. {
  10. return string.Format("{0} {1}", k_AssertionFailed, failureMessage);
  11. }
  12. public static string GetMessage(string failureMessage, string expected)
  13. {
  14. return GetMessage(string.Format("{0}{1}{2} {3}", failureMessage, Environment.NewLine, k_Expected, expected));
  15. }
  16. public static string GetEqualityMessage(object actual, object expected, bool expectEqual)
  17. {
  18. return GetMessage(string.Format("Values are {0}equal.", expectEqual ? "not " : ""),
  19. string.Format("{0} {2} {1}", actual, expected, expectEqual ? "==" : "!="));
  20. }
  21. public static string NullFailureMessage(object value, bool expectNull)
  22. {
  23. return GetMessage(string.Format("Value was {0}Null", expectNull ? "not " : ""),
  24. string.Format("Value was {0}Null", expectNull ? "" : "not "));
  25. }
  26. public static string BooleanFailureMessage(bool expected)
  27. {
  28. return GetMessage("Value was " + !expected, expected.ToString());
  29. }
  30. }
  31. }