public void HasAttributes_on_mirroed_object_with_exectedCount_should_fail(Mirror.MemberSet target, string expectedMessage, string expectedTargetFormat) { AssertionFailure[] failures = Capture(() => Assert.HasAttributes <FooAttribute>(target, 4)); Assert.Count(1, failures); Assert.AreEqual("Expected to find 4 attribute instances but found 3.", failures[0].Description); AssertCommonFailureLabeledValues(failures[0], "SampleType2" + expectedTargetFormat, "FooAttribute"); }
public void HasAttribute_on_mirrored_object_should_fail(Mirror.MemberSet target, string expectedMessage, string expectedTargetFormat) { AssertionFailure[] failures = Capture(() => Assert.HasAttribute(typeof(BarAttribute), target)); Assert.Count(1, failures); Assert.AreEqual("Expected the searched attribute to decorate the target object; but none was found.", failures[0].Description); AssertCommonFailureLabeledValues(failures[0], "SampleType1" + expectedTargetFormat, "BarAttribute"); }
public void HasAttribute_on_mirrored_object_should_pass(Mirror.MemberSet target, string expectedMessage) { Attribute attribute = Assert.HasAttribute(typeof(FooAttribute), target); Assert.IsInstanceOfType <FooAttribute>(attribute); Assert.AreEqual(expectedMessage, ((FooAttribute)attribute).Text); }
/// <summary> /// Verifies that the targeted object is decorated with the exact number of instances of the specified <see cref="Attribute"/>. /// </summary> /// <param name="expectedAttributeType">The type of the searched <see cref="Attribute"/>.</param> /// <param name="target">The targeted object to evaluate.</param> /// <param name="expectedCount">The expected number of attribute instances to be found.</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <returns>An array of attribute instances.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="expectedAttributeType"/> or <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="expectedCount"/> is less than or equal to zero.</exception> public static Attribute[] HasAttributes(Type expectedAttributeType, Mirror.MemberSet target, int expectedCount, string messageFormat, params object[] messageArgs) { if (target == null) { throw new ArgumentNullException("target"); } return(HasAttributes(expectedAttributeType, target.MemberInfo, expectedCount, messageFormat, messageArgs)); }
/// <summary> /// Verifies that the targeted object is decorated with the exact number of instances of the specified <see cref="Attribute"/>. /// </summary> /// <typeparam name="TAttribute">The type of the searched <see cref="Attribute"/>.</typeparam> /// <param name="target">The target type to evaluate.</param> /// <param name="expectedCount">The expected number of attribute instances to be found.</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <returns>An array of attribute instances.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="expectedCount"/> is less than or equal to zero.</exception> public static TAttribute[] HasAttributes <TAttribute>(Mirror.MemberSet target, int expectedCount, string messageFormat, params object[] messageArgs) where TAttribute : Attribute { return(ToAttributeArray <TAttribute>(HasAttributes(typeof(TAttribute), target, expectedCount, messageFormat, messageArgs))); }
/// <summary> /// Verifies that the targeted object is decorated with the exact number of instances of the specified <see cref="Attribute"/>. /// </summary> /// <typeparam name="TAttribute">The type of the searched <see cref="Attribute"/>.</typeparam> /// <param name="target">The target type to evaluate.</param> /// <param name="expectedCount">The expected number of attribute instances to be found.</param> /// <returns>An array of attribute instances.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="expectedCount"/> is less than or equal to zero.</exception> public static TAttribute[] HasAttributes <TAttribute>(Mirror.MemberSet target, int expectedCount) where TAttribute : Attribute { return(HasAttributes <TAttribute>(target, expectedCount, null, null)); }
/// <summary> /// Verifies that the targeted object is decorated with the exact number of instances of the specified <see cref="Attribute"/>. /// </summary> /// <param name="expectedAttributeType">The type of the searched <see cref="Attribute"/>.</param> /// <param name="target">The targeted object to evaluate.</param> /// <param name="expectedCount">The expected number of attribute instances to be found.</param> /// <returns>An array of attribute instances.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="expectedAttributeType"/> or <paramref name="target"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="expectedCount"/> is less than or equal to zero.</exception> public static Attribute[] HasAttributes(Type expectedAttributeType, Mirror.MemberSet target, int expectedCount) { return(HasAttributes(expectedAttributeType, target, expectedCount, null, null)); }
/// <summary> /// Verifies that the targeted type is decorated once with the specified <see cref="Attribute"/>. /// </summary> /// <remarks> /// <para> /// The assertion returns the instance of the actual attribute found. /// </para> /// <para> /// The assertion fails if the target object is decorated with multiple instances of the searched attribute. If several /// instances are expected, use <see cref="Assert.HasAttribute{TAttribute}(MemberInfo, string, object[])"/> instead. /// </para> /// </remarks> /// <typeparam name="TAttribute">The type of the searched <see cref="Attribute"/>.</typeparam> /// <param name="target">The target type to evaluate.</param> /// <param name="messageFormat">The custom assertion message format, or null if none.</param> /// <param name="messageArgs">The custom assertion message arguments, or null if none.</param> /// <returns>The instance of the actual attribute found.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="target"/> is null.</exception> public static TAttribute HasAttribute <TAttribute>(Mirror.MemberSet target, string messageFormat, params object[] messageArgs) where TAttribute : Attribute { return((TAttribute)HasAttribute(typeof(TAttribute), target, messageFormat, messageArgs)); }
/// <summary> /// Verifies that the targeted type is decorated once with the specified <see cref="Attribute"/>. /// </summary> /// <remarks> /// <para> /// The assertion returns the instance of the actual attribute found. /// </para> /// <para> /// The assertion fails if the target object is decorated with multiple instances of the searched attribute. If several /// instances are expected, use <see cref="Assert.HasAttribute{TAttribute}(MemberInfo)"/> instead. /// </para> /// </remarks> /// <typeparam name="TAttribute">The type of the searched <see cref="Attribute"/>.</typeparam> /// <param name="target">The target type to evaluate.</param> /// <returns>The instance of the actual attribute found.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="target"/> is null.</exception> public static TAttribute HasAttribute <TAttribute>(Mirror.MemberSet target) where TAttribute : Attribute { return((TAttribute)HasAttribute(typeof(TAttribute), target, null, null)); }
/// <summary> /// Verifies that the targeted object is decorated once with the specified <see cref="Attribute"/>. /// </summary> /// <remarks> /// <para> /// The assertion returns the instance of the actual attribute found. /// </para> /// <para> /// The assertion fails if the target object is decorated with multiple instances of the searched attribute. If several /// instances are expected, use <see cref="Assert.HasAttribute(Type, MemberInfo)"/> instead. /// </para> /// </remarks> /// <param name="expectedAttributeType">The type of the searched <see cref="Attribute"/>.</param> /// <param name="target">The targeted object to evaluate.</param> /// <returns>The instance of the actual attribute found.</returns> /// <exception cref="AssertionException">Thrown if the verification failed unless the current <see cref="AssertionContext.AssertionFailureBehavior" /> indicates otherwise.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="expectedAttributeType"/> or <paramref name="target"/> is null.</exception> public static Attribute HasAttribute(Type expectedAttributeType, Mirror.MemberSet target) { return(HasAttribute(expectedAttributeType, target, null, null)); }
public void HasAttributes_on_mirroed_object_with_exectedCount_should_pass(Mirror.MemberSet target, string expectedMessage) { FooAttribute[] attributes = Assert.HasAttributes <FooAttribute>(target, 3); Assert.AreElementsEqualIgnoringOrder(attributes.Select(x => x.Text), Enumerable.Range(1, 3).Select(i => expectedMessage + " #" + i)); }