コード例 #1
0
        public void CreateReturnsXunitException()
        {
            var exception = AssertException.Create("abc");

            Assert.IsType <Xunit.Sdk.XunitException>(exception);
            Assert.Equal("abc", exception.Message);
        }
コード例 #2
0
 /**
  * Checks a postcondition and throws an exception if this postcondition is false
  *
  * @param postcondition This postcondition should be true, otherwise an exception will be thrown
  * @param conditionDescription A textual description of the postcondition
  */
 internal static void That(bool postcondition, string conditionDescription)
 {
     if (!postcondition)
     {
         throw AssertException.Create("Postcondition", conditionDescription);
     }
 }
コード例 #3
0
 internal static void IsNotNullOrEmpty(string toBeTested, string objectName)
 {
     if (string.IsNullOrEmpty(toBeTested))
     {
         throw AssertException.Create("Precondition", objectName + " is not null or empty");
     }
 }
コード例 #4
0
 /**
  * Checks if the toBeTested is not null and throws an exception if this precondition is false.
  *
  * @param toBeTested The object for test.
  * @param objectName Name of the object.
  */
 internal static void IsNotNull(object toBeTested, string objectName)
 {
     if (toBeTested == null)
     {
         throw AssertException.Create("Precondition", objectName + " is not null");
     }
 }
コード例 #5
0
 internal static void That(System.Func <bool> function)
 {
     if (!function())
     {
         throw AssertException.Create("Precondition", function);
     }
 }
コード例 #6
0
 /**
  * Checks a precondition and throws an exception if this
  * precondition is false This method should be used, if a
  * description must be dynamically created.  string.Format() will
  * only be called, if the precondition fails.
  *
  * @param precondition This precondition should be true, otherwise an exception will be thrown
  * @param descriptionFormat Will be passed to string.Format(), to create a textual description of the precondition
  * @param descriptionParameters Will be passed to string.Format(), to create a textual description of the precondition
  */
 internal static void That(bool precondition, string descriptionFormat, params object[] descriptionParameters)
 {
     if (!precondition)
     {
         throw AssertException.Create("Precondition", descriptionFormat, descriptionParameters);
     }
 }
コード例 #7
0
ファイル: Fix.cs プロジェクト: forki/Gu.Roslyn.Asserts
        private static CodeAction FindAction(List <CodeAction> actions, string fixTitle)
        {
            if (fixTitle != null)
            {
                if (actions.All(x => x.Title != fixTitle))
                {
                    var errorBuilder = StringBuilderPool.Borrow();
                    errorBuilder.AppendLine($"Did not find a code fix with title {fixTitle}.").AppendLine("Found:");
                    foreach (var codeAction in actions)
                    {
                        errorBuilder.AppendLine(codeAction.Title);
                    }

                    throw AssertException.Create(StringBuilderPool.Return(errorBuilder));
                }

                actions.RemoveAll(x => x.Title != fixTitle);
            }

            if (actions.Count == 0)
            {
                throw AssertException.Create("Expected one code fix, was 0.");
            }

            if (actions.Count > 1)
            {
                throw AssertException.Create($"Expected only one code fix, found {actions.Count}:\r\n" +
                                             $"{string.Join("\r\n", actions.Select(x => x.Title))}\r\n" +
                                             "Use the overload that specifies title.");
            }

            return(actions[0]);
        }
コード例 #8
0
        /// <summary>
        /// Call string.Replace(<paramref name="oldValue"/>, <paramref name="newValue"/>) but check that string contains <paramref name="oldValue"/> first.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="oldValue">The text to replace.</param>
        /// <param name="newValue">The text to replace with.</param>
        /// <returns>The sting with the replaced text.</returns>
        public static string AssertReplace(this string text, string oldValue, string newValue)
        {
            if (!text.Contains(oldValue))
            {
                throw AssertException.Create($"AssertReplace failed, expected {oldValue} to be in {text}");
            }

            return(text.Replace(oldValue, newValue));
        }