Your example is a little unusual because you're trying to check whether a collection contains a value that satisfies a predicate rather than looking for an equal value to one you already have.
(This makes me think we should extend Assert.Contains with an overload like: Assert.Contains<T>(collection, Predicate<T> predicate.) Anyways, here's one way you can produce the desired assertions: Assert.IsNotEmpty(property.GetCustomAttributes(typeof(MyAttribute), true)); Assert.IsNotEmpty(property.GetCustomAttributes(typeof(MyOtherAttribute), true)); Jeff. -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Chris Sent: Friday, April 03, 2009 6:30 AM To: MbUnit.User Subject: MbUnit Assert.Contains<> Example I've been looking all over the web trying to find an example of Assert.Contains<> for something like the following: I want to test if certain attributes are set on properties of my properties. I've gotten to the point where I get an array of attributes, but I'm not sure how to call the Assert.Contains<> method to determine if the attribute is set. There can be more than one attribute on a property. I have a code sample below. public class MyObject { priavate int x = 0; [MyCustomAttribute] [MyOtherCustomAttribute] public int X { get { return x; } } } .... in the mbunit textfixture class ... Type obj = typeof(MyObject); PropertyInfo[] properties = obj.GetProperties(); Assert.AreEqual(2, properties.Length); //This works ok foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(true); // creates an array with the custom attributes // here's where I'm running into some issues as the property.GetCustomAttributes method returns an array of type object(in this case, the array has two element). // I'd like to iterate through the array and pass the test if the Custom Attribute is found by comparing to the Attribute.TypeId field to the expected value Assert.Contains<object[]>(/*Not sure how to enumerate*/, "MyCustomerAttribute"); Assert.Contains<object[]>(/*Not sure how to enumerate*/, "MyOtherCustomAttribute"); } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "MbUnit.User" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/MbUnitUser?hl=en -~----------~----~----~----~------~----~------~--~---
