From: nunit-...@googlegroups.com [mailto:nunit-...@googlegroups.com] On Behalf Of Simone Busoli
Sent: Thursday, January 08, 2009 9:18 AM
To: nunit-...@googlegroups.com
Subject: [nunit-discuss] Asserting that all public properties match
AssertThat( PropertiesOf(actual), Are.EqualTo( PropertiesOf(Expected) ) );
I think an intuitive way to express it is using the ValueType word in some way, something everyone should be aware of. ÂÂ
I'm afraid I'm not. :-( Except that it's the name of a BCL class. Care to educate me?
ÂRhinoMocks uses an even more explicit approach, AllPropertiesMatch.ÂÂ
I like it, at least for Assert and as the name of a constraint. But I can't figureout the fluent syntax for it. I could write... Assert.That(actual, Has.All.Properties.EqualTo( expected ))Âbut that seems ambiguous to me. EitherÂ1) All properties of actual are equal to expected OR2) All properties of actual are equal to the corresponding property of expected.ÂBut I'm a nitpicker, so if nobody else thinks it's ambiguous, I'll withdrawmy objection.ÂCharlie
I think an intuitive way to express it is using the ValueType word in some way, something everyone should be aware of. ÂÂI'm afraid I'm not. :-( Except that it's the name of a BCL class. Care to educate me?
ÂRhinoMocks uses an even more explicit approach, AllPropertiesMatch.ÂÂI like it, at least for Assert and as the name of a constraint. But I can't figureout the fluent syntax for it. I could write... Assert.That(actual, Has.All.Properties.EqualTo( expected ))Âbut that seems ambiguous to me. EitherÂ1) All properties of actual are equal to expected OR2) All properties of actual are equal to the corresponding property of expected.ÂBut I'm a nitpicker, so if nobody else thinks it's ambiguous, I'll withdrawmy objection.
> Problem is value-equality must be recursive. So if I have a class A
>
> public class A {
> public int SomeInt;
> public List<int> TheList { get; }
> }
>
> .. what would I write? I don't want exclude "TheList" from
> the comparison (since it is part of the "value" of an object
> of type A), yet I have to express somehow that
> A.TheList.Capacity should be ignored.
You're right - I didn't think of that.
Charlie
On Thu, Jan 8, 2009 at 10:37 PM, Charlie Poole <cha...@nunit.com> wrote:
I think an intuitive way to express it is using the ValueType word in some way, something everyone should be aware of. ÂÂI'm afraid I'm not. :-( Except that it's the name of a BCL class. Care to educate me?Fire up Reflector, select the Int32 type, switch from C# to IL and you see that it inherits from ValueType. In the .NET FX, all primitive types, except for string and arrays, are value types. Go see how ValueType implements Equals and you see that it compares the value of the fields of the object, not their reference, which is the default implementation of Equals in the Object class.Â
Yes, that's what I meant by the BCL class. So, you're suggesting we use some syntaxlike Is.EqualAsValueType()? That would be confusing to me, if the object in questionwere not a ValueType.
ÂÂRhinoMocks uses an even more explicit approach, AllPropertiesMatch.ÂÂI like it, at least for Assert and as the name of a constraint. But I can't figureout the fluent syntax for it. I could write... Assert.That(actual, Has.All.Properties.EqualTo( expected ))Âbut that seems ambiguous to me. EitherÂ1) All properties of actual are equal to expected OR2) All properties of actual are equal to the corresponding property of expected.ÂBut I'm a nitpicker, so if nobody else thinks it's ambiguous, I'll withdrawmy objection.Yes I think it's ambiguous but I don't like it much anyways since it is too verbose.Â
I'm still thinking about a good way to express it.ÂÂ
OK... let us know if you think of something.ÂCharlieÂ