Example #1
0
    public void StringStartsWith()
    {
        string expectedValue = "XX";
        string actualValue   = "xxx";

        // MSTest
        MSTestStringAssert.StartsWith(actualValue, expectedValue, "Some context");
        // StringAssert.StartsWith failed. String 'xxx' does not start with string 'XX'. Some context

        // NUnit
        Assert.That(actualValue, Does.StartWith(expectedValue), () => "Some context");
        // Some context
        //  Expected: String starting with "XX"
        //  But was: "xxx"

        // XUnit
        XUnitAssert.StartsWith(expectedValue, actualValue);
        // Assert.StartsWith() Failure
        // Not found: XX
        // In value: xx...

        // Fluent
        actualValue.Should().StartWith(expectedValue, "SOME REASONS");
        // Expected actualValue to start with "XX" because SOME REASONS, but "xxx" differs near "xxx" (index 0).

        // Shouldly
        actualValue.ShouldStartWith(expectedValue, "Some context", Case.Sensitive);
        // actualValue
        //   should start with
        // "XX"
        //   but was
        // "xxx"
        //
        // Additional Info:
        //  Some context
    }
 /// <summary>
 /// Tests whether the specified string begins with the specified substring
 /// and throws an exception if the test string does not start with the
 /// substring.
 /// </summary>
 /// <param name="value">
 /// The string that is expected to begin with <paramref name="substring"/>.
 /// </param>
 /// <param name="substring">
 /// The string expected to be a prefix of <paramref name="value"/>.
 /// </param>
 /// <param name="message">
 /// The message to include in the exception when <paramref name="value"/>
 /// does not begin with <paramref name="substring"/>. The message is
 /// shown in test results.
 /// </param>
 /// <exception cref="AssertFailedException">
 /// Thrown if <paramref name="value"/> does not begin with
 /// <paramref name="substring"/>.
 /// </exception>
 public static void StartsWith(string value, string substring, string message)
 {
     StringAssert.StartsWith(value, substring, message, null);
 }
 /// <summary>
 /// Tests whether the specified string begins with the specified substring
 /// and throws an exception if the test string does not start with the
 /// substring.
 /// </summary>
 /// <param name="value">
 /// The string that is expected to begin with <paramref name="substring"/>.
 /// </param>
 /// <param name="substring">
 /// The string expected to be a prefix of <paramref name="value"/>.
 /// </param>
 /// <exception cref="AssertFailedException">
 /// Thrown if <paramref name="value"/> does not begin with
 /// <paramref name="substring"/>.
 /// </exception>
 public static void StartsWith(string value, string substring)
 {
     StringAssert.StartsWith(value, substring, string.Empty, null);
 }