Re: Check that all properties match?

Ron Grabowski <[email protected]> Wed, 27 Aug 2008 19:06:28 -0700 (PDT)
Newsgroups gmane.comp.windows.dotnet.nunit.user
Message-ID <[email protected]>
I use this code to save typing out each property:

public static class PublicPropertiesAssert
{
 public static void AreEqual(object a, object b)
 {
  Assert.IsNotNull(a);
  Assert.IsNotNull(b);
  Type bType = b.GetType();
  foreach (PropertyInfo propertyInfo in a.GetType().GetProperties())
  {
   Assert.AreEqual(
    propertyInfo.GetValue(a, null),
    bType.GetProperty(propertyInfo.Name).GetValue(b, null),
    "'" + propertyInfo.Name + "' properties should be equal.");
  }
 }
}



----- Original Message ----
From: Simone Busoli <[email protected]>
To: Laimonas Simutis <[email protected]>
Cc: [email protected]
Sent: Wednesday, August 27, 2008 10:37:40 AM
Subject: Re: [Nunit-users] Check that all properties match?


Yes. RhinoMocks has an AllPropertiesMatchContraint class which is used for the same purpose. Often in tests I need to assert that what I get from a method call is equal to a dummy object I passed as input, and I don't want to override the Equals method since I need that only during tests.


On Wed, Aug 27, 2008 at 4:22 PM, Laimonas Simutis <[email protected]> wrote:

Would this be used to compare object equivalency or verifying some
sort of cloning?


On Wed, Aug 27, 2008 at 3:32 AM, Simone Busoli <[email protected]> wrote:
> Hello, would it be useful to have a way to check that all properties with
> matching names are equal on two objects?
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Nunit-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nunit-users
>
>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_______________________________________________
Nunit-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nunit-users