/// <summary> /// Asserts that a string starts exactly with the specified <paramref name="expected"/> value, /// including the casing and any leading or trailing whitespace. /// </summary> /// <param name="expected">The string that the subject is expected to start with.</param> /// <param name="because"> /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. /// </param> /// <param name="becauseArgs"> /// Zero or more objects to format using the placeholders in <see cref="because" />. /// </param> public AndConstraint <StringAssertions> StartWith(string expected, string because = "", params object[] becauseArgs) { Guard.ThrowIfArgumentIsNull(expected, nameof(expected), "Cannot compare start of string with <null>."); if (expected.Length == 0) { throw new ArgumentException("Cannot compare start of string with empty string.", nameof(expected)); } var stringStartValidator = new StringStartValidator(Subject, expected, StringComparison.CurrentCulture, because, becauseArgs); stringStartValidator.Validate(); return(new AndConstraint <StringAssertions>(this)); }
/// <summary> /// Asserts that a string starts with the specified <paramref name="expected"/>, /// including any leading or trailing whitespace, with the exception of the casing. /// </summary> /// <param name="expected">The string that the subject is expected to start with.</param> /// <param name="because"> /// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion /// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically. /// </param> /// <param name="becauseArgs"> /// Zero or more objects to format using the placeholders in <see cref="because" />. /// </param> public AndConstraint <StringAssertions> StartWithEquivalent(string expected, string because = "", params object[] becauseArgs) { if (expected == null) { throw new ArgumentNullException(nameof(expected), "Cannot compare string start equivalence with <null>."); } if (expected.Length == 0) { throw new ArgumentException("Cannot compare string start equivalence with empty string.", nameof(expected)); } var stringStartValidator = new StringStartValidator(Subject, expected, StringComparison.CurrentCultureIgnoreCase, because, becauseArgs); stringStartValidator.Validate(); return(new AndConstraint <StringAssertions>(this)); }