/// <summary> /// Asserts against an expected attribute, with a matcher for the attribute /// </summary> /// <param name="with"></param> /// <param name="matcher"></param> /// <param name="customMessageGenerator"></param> /// <typeparam name="TAttribute"></typeparam> /// <returns></returns> public static IMore <MethodInfo> Attribute <TAttribute>( this IWith <MethodInfo> with, Func <TAttribute, bool> matcher, Func <string> customMessageGenerator ) where TAttribute : Attribute { matcher ??= _ => true; return(with.AddMatcher(actual => TryMatchAnyParameterAttribute(actual, matcher, customMessageGenerator) ?? TryMatchParameterAttribute(actual, matcher, customMessageGenerator) ?? MatchMethodAttribute(actual, matcher, customMessageGenerator) )); }
public static IMore <Dog> Name( this IWith <Dog> with, string expected) { return(with.AddMatcher(actual => { var name = actual.Name; // ?.GetOrDefault(nameof(Animal.Name), null as string); var passed = name == expected; return new MatcherResult( passed, () => $"Expected {actual} to have name '{expected}'" ); })); }