Thanks for walking through this too Simone. Until you do have generic
constraints, I wonder if NUnit can identify that the test can't
succeed and leave a more informative message.
> >> With no ToString(), btw. That must have been some other errorAny ideas on how to flush that other error out? Could the error be
> >> that VS trapped at some point.
that DateTime doesn't know about the DatePoint?
Charlie, time to put generics on constraints? :)
I guess the simplest approach would be to deal only with constraints taking an actual and an expected value - which is most of them anyway. In order to avoid ambiguity among the Assert.That overloads, it would probably have to be a completely new class, rather than deriving from Constraint. It could have a generic member Matches, which would take a Type parameter for the supplied actual value. Is that along the lines you are suggesting?Charlie
> Any ideas on how to flush that other error out? Could the
> error be that DateTime doesn't know about the DatePoint?
Can you replicate it in a small example?
Charlie
Theoretically, it could, but it would get tricky because NUnit should make assumptions about the two objects that might now be always true. When comparing objects about equality or disequality, NUnit could assume that in order to perform a successful comparison the two objects should be of the same type or on the same hierarchy. That should be solved by generic constraints, but what if one of the objects, for example, implements IEquatable<TOfOtherObject>? NUnit should be aware of this and give them a chance to compare too.I dunno, Charlie might have a clearer opinion on this. Maybe NUnit could provide a warning message?
It does - the test fails! :-)Seriously, that's what test frameworks do, they run tests and give error messages when a test fails. Sometimes, it's hard to figure out why the test failed - as in this case. But that's usually related to .NET corner cases rather than NUnit.It's true that Generics would make this test pass, but the test would still depend on some non-obvious details of the internal implementation of NUnit. IMO, that makes it not such a good test. Still, I agree that the current result violates the principleof least surprise, so it would be good to fix it.Charlie
> There no exception being thrown that I know of, so I don't
> think I can do better than the trace left by NUnit I posted
> earlier (and below so you don't have to hunt for it), or my
> copied view of the call stack.
I may have misunderstood something earlier. I was assuming that
your call stack was the result of an exception that VS caught.
Could you explain again how you got it?
Charlie
From: nunit-...@googlegroups.com [mailto:nunit-...@googlegroups.com] On Behalf Of Simone Busoli
Sent: Friday, December 26, 2008 10:57 AM
To: nunit-...@googlegroups.com
Subject: [nunit-discuss] Re: Is.EqualTo calling ToString on implicit conversion
Sure Charlie. Actually, I have already implemented something with a totally different syntax a while ago. It was something likeAssert.That(1, i => i.Is.EqualTo(1)).That used the same constraints as NUnit but provided syntactic sugar so that you couldn't pass a string to the above EqualTo method. If you're interested I'll give you the url of the repo.
I'd like to take a look.Charlie
> The call stack I first showed was the result of copy paste of
> the VS call stack window as I stepped through the debugger. I
> wanted to communicate that I was jumping straight from
> Assert.That(actObject,
> Is.EqualTo(expObject) to ToString() instead of
> Equals(object). No error other than the test failure was thrown.
Here's that original call stack:
1 Smack.Core.Tests.DLL!
Smack.Core.Tests.Domain.Temporal.DatePointTest.Implicit_Equality_DatePoint_D
ateTime_Equals
() Line 94 + 0x2d bytes
2 Smack.Core.DLL!Smack.Core.Domain.Temporal.DatePoint.implicit
operator Smack.Core.Domain.Temporal.DatePoint(System.DateTime datetime =
{12/25/2008 12:00:00 AM}) Line 202
3 Smack.Core.Tests.DLL!
Smack.Core.Tests.Domain.Temporal.DatePointTest.Implicit_Equality_DatePoint_D
ateTime_Equals
() Line 94 + 0x63 bytes [External Code]
4 Smack.Core.DLL!Smack.Core.Domain.Temporal.DatePoint.ToString(string
format = null, System.IFormatProvider formatProvider = {}) Line 222
[External Code]
I don't see an entry for NUnit.Framework.Assert.That().
Charlie