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
-~----------~----~----~----~------~----~------~--~---

Reply via email to