private static void TestBoolean( IBe <bool> expectation, bool expected, Func <string> message ) { expectation.AddMatcher(TruthTestFor(expected, message)); }
/// <summary> /// Tests if a boolean value is True /// </summary> /// <param name="continuation">Continuation to operate on</param> /// <param name="customMessageGenerator">Generates a custom message to include on failure</param> public static void True( this IBe <bool?> continuation, Func <string> customMessageGenerator ) { // ReSharper disable once ConditionIsAlwaysTrueOrFalse continuation.AddMatcher(TruthTestFor(true as bool?, customMessageGenerator)); }
public static void Falsey(this IBe <long> be) { be.AddMatcher( actual => { var passed = actual == 0; return(new MatcherResult( passed, () => $"Expected {actual} {passed.AsNot()}to be falsey")); }); }
public static void Null <T>(this IBe <T> continuation, string customMessage) { continuation.AddMatcher(actual => { var passed = actual == null; return(new MatcherResult( passed, FinalMessageFor( passed ? "Expected not to get null" : $"Expected null but got {Quote(actual)}", customMessage) )); }); }
internal static IStringMore AllNumeric( this IBe <string> be ) { be.AddMatcher(actual => { var passed = actual.All(c => "0123456789".Contains(c)); return(new MatcherResult( passed, $"Expected \"{actual}\" {passed.AsNot()}to be all numeric" )); }); return(be.More()); }
/// <summary> /// Asserts that a string is alpha /// </summary> /// <param name="be"></param> /// <param name="customMessageGenerator"></param> /// <returns></returns> public static IStringMore Alpha( this IBe <string> be, Func <string> customMessageGenerator) { be.AddMatcher(actual => { var passed = actual != null && actual.All(c => c.IsAlpha()); return(new MatcherResult( passed, FinalMessageFor( () => $"Expected {actual.Stringify()} {passed.AsNot()}to be alpha", customMessageGenerator) )); }); return(be.More()); }
/// <summary> /// Tests if a string is empty, with a provided custom error message /// </summary> /// <param name="continuation">Continuation to operate on</param> /// <param name="customMessageGenerator">Generates a custom message to include when failing</param> public static void Empty( this IBe <string> continuation, Func <string> customMessageGenerator) { continuation.AddMatcher( actual => { var passed = actual == ""; return(new MatcherResult( passed, FinalMessageFor( () => passed ? new[] { "Expected not to be empty" } : new[] { "Expected empty string but got", Quote(actual) }, customMessageGenerator) )); }); }
/// <summary> /// Tests if a value is null /// </summary> /// <param name="continuation">Continuation to operate on</param> /// <param name="customMessageGenerator">Generates a custom message to include when failing</param> /// <typeparam name="T">Type of object being tested</typeparam> public static IMore <T> Null <T>( this IBe <T> continuation, Func <string> customMessageGenerator ) { continuation.AddMatcher( actual => { var passed = actual == null; return(new MatcherResult( passed, FinalMessageFor( () => passed ? new[] { "Expected not to get null" } : new[] { "Expected null but got", Quote(actual) }, customMessageGenerator) )); }); return(continuation.More()); }
/// <summary> /// Tests if a boolean value is False /// </summary> /// <param name="continuation">Continuation to operate on</param> public static void False(this IBe <bool> continuation) { continuation.AddMatcher(TruthTestFor(false, null)); }
/// <summary> /// Tests if a boolean value is False /// </summary> /// <param name="continuation">Continuation to operate on</param> /// <param name="customMessageGenerator">Generats a custom message to include on failure</param> public static void False( this IBe <bool> continuation, Func <string> customMessageGenerator) { continuation.AddMatcher(TruthTestFor(false, customMessageGenerator)); }
public static void False(this IBe <bool?> expectation, string message) { expectation.AddMatcher(TruthTestFor(false as bool?, message)); }
public static void False(this IBe <bool?> expectation) { expectation.AddMatcher(TruthTestFor(false as bool?, null)); }