nunit-core team mailing list archive
-
nunit-core team
-
Mailing list archive
-
Message #03482
Re: [Bug 1172247] Re: Improve DateTime equality assertions to include DateTimeKind
Hi Simone,
You're right, I changed the problem to converting to UTC before comparing.
While this might be of some use, it's not what Adam was asking.
For Adam's specific request, I'm not in favor of a new modifier because I
don't think it really has wide application.
I suggest creating a custom comparer and using the Using modifier with
it.
Charlie
On Apr 26, 2013 4:55 PM, "Simone Busoli" <1172247@xxxxxxxxxxxxxxxxxx> wrote:
> Hi, yes that would be possible, but I'm not sure it would work as you
> showed. Here we're talking about DateTime (so no timezone offset) and its
> Kind property. What Adam is asking for, and it would also be the only
> option in my opinion, is a modifier which requires the value of the Kind
> property to be the same. Frankly I don't see much value in it because
> checking equality of the Kind property is meaningful only in case its value
> is Utc, rather meaningless in case the value is either Local or
> Unspecified. Plus, I appreciate we have the IgnoreCase modifier already,
> which I assume applies to strings only right now (I can't check, but it
> could work just fine over StringBuilders or chars), but without generic
> constraints I don't like very much the idea of cluttering the API with
> members which apply to a single type but show up in the intellisense all
> the time. I concur it's not a big deal though.
>
> Simone
>
>
> On Fri, Apr 26, 2013 at 8:58 PM, Charlie Poole <charlie@xxxxxxxxx> wrote:
>
> > Hey Guys...
> >
> > I'm visiting family and so not answering as quickly as usual...
> >
> > I agree with Simone that the only good solution is to add a modifier to
> the
> > EqualConstraint, which would change how it compares DateTime objects. I
> > guess we should also add a comparison of DateTimeOffsets, even though it
> > wouldn't help Adam.
> >
> > It's not necessary to implement generic constraints to use a modifier. We
> > already have modifiers like IgnoreCase, which which is only used when
> > strings are compared, so we could do the same thing here. Generics would
> be
> > nicer, but that's for the future.
> >
> > One possibility: Assert.That(dt1, Is.EqualTo(dt2).AsUtc);
> >
> > Note that this would have to work with the Within modifier:
> > Assert.That(dt1, Is.EqualTo(dt2).Within(5).Minutes.AsUtc);
> >
> > There are exceptions possible when converting to UTC, but we could just
> > pass them on.
> >
> > The alternative is to not support it and require prior conversion to UTC
> by
> > the caller.
> >
> > Charlie
> >
> >
> > On Thu, Apr 25, 2013 at 1:05 AM, Adam Brengesjö <ca.brengesjo@xxxxxxxxx
> > >wrote:
> >
> > > Yea, I was inspired by your post and checked out the current
> > > implementation and noticed that TimeSpan has tolerance constraints in
> > > this way.
> > >
> > > But I agree it would by far would be better if it was context aware by
> > > using generics and the 'StrictDatetimeKind' (or what ever name) or the
> > > current tolerance properties for that matter, was not not available if
> > > not using the correct type.
> > >
> > > But on the other hand, if comparing two System.Object, the equality
> > > comparer should be able to detect that they are boxed value types, just
> > > as the current implementation does. This is a drawback of generics.
> > >
> > > --
> > > You received this bug notification because you are a member of NUnit
> > > Developers, which is subscribed to NUnit V2.
> > > https://bugs.launchpad.net/bugs/1172247
> > >
> > > Title:
> > > Improve DateTime equality assertions to include DateTimeKind
> > >
> > > Status in NUnit V2 Test Framework:
> > > New
> > >
> > > Bug description:
> > > The following test will fail, even if the two DateTime structs are
> not
> > > equal.
> > > (I know it's because the equality members of the DateTime type does
> the
> > > evaluation which doesn't care of the Kind property)
> > >
> > > [Test]
> > > public void Foo()
> > > {
> > > var localDate = new DateTime(2013, 04, 24, 13, 17, 44, 678,
> > > DateTimeKind.Local);
> > > var systemDate = new DateTime(2013, 04, 24, 13, 17, 44, 678,
> > > DateTimeKind.Utc);
> > >
> > > Assert.AreNotEqual(localDate, systemDate);
> > > }
> > >
> > > But I always extracts my assertions to a helper method which also
> > > checks the Kind property.
> > >
> > > public static class AssertX
> > > {
> > > public static void AreEqual(DateTime expected, DateTime actual)
> > > {
> > > Assert.AreEqual(expected, actual);
> > > Assert.AreEqual(expected.Kind, actual.Kind);
> > > }
> > > }
> > >
> > > I would like to have NUnit help me with this instead of always
> calling
> > > my own helper class.
> > >
> > > However, I'm not sure how this best could be implemented in NUnit.
> > > A simple overload of AreEqual(object, object) to AreEqual(DateTime,
> > > DateTime) risk breaking compability with existing tests out there.
> > >
> > > One way would be to instead use another name, Assert.Identical or
> > > similar.
> > >
> > > To manage notifications about this bug go to:
> > > https://bugs.launchpad.net/nunitv2/+bug/1172247/+subscriptions
> > >
> > > _______________________________________________
> > > Mailing list: https://launchpad.net/~nunit-core
> > > Post to : nunit-core@xxxxxxxxxxxxxxxxxxx
> > > Unsubscribe : https://launchpad.net/~nunit-core
> > > More help : https://help.launchpad.net/ListHelp
> > >
> >
> > --
> > You received this bug notification because you are a member of NUnit
> > Developers, which is subscribed to NUnit V2.
> > https://bugs.launchpad.net/bugs/1172247
> >
> > Title:
> > Improve DateTime equality assertions to include DateTimeKind
> >
> > Status in NUnit V2 Test Framework:
> > New
> >
> > Bug description:
> > The following test will fail, even if the two DateTime structs are not
> > equal.
> > (I know it's because the equality members of the DateTime type does the
> > evaluation which doesn't care of the Kind property)
> >
> > [Test]
> > public void Foo()
> > {
> > var localDate = new DateTime(2013, 04, 24, 13, 17, 44, 678,
> > DateTimeKind.Local);
> > var systemDate = new DateTime(2013, 04, 24, 13, 17, 44, 678,
> > DateTimeKind.Utc);
> >
> > Assert.AreNotEqual(localDate, systemDate);
> > }
> >
> > But I always extracts my assertions to a helper method which also
> > checks the Kind property.
> >
> > public static class AssertX
> > {
> > public static void AreEqual(DateTime expected, DateTime actual)
> > {
> > Assert.AreEqual(expected, actual);
> > Assert.AreEqual(expected.Kind, actual.Kind);
> > }
> > }
> >
> > I would like to have NUnit help me with this instead of always calling
> > my own helper class.
> >
> > However, I'm not sure how this best could be implemented in NUnit.
> > A simple overload of AreEqual(object, object) to AreEqual(DateTime,
> > DateTime) risk breaking compability with existing tests out there.
> >
> > One way would be to instead use another name, Assert.Identical or
> > similar.
> >
> > To manage notifications about this bug go to:
> > https://bugs.launchpad.net/nunitv2/+bug/1172247/+subscriptions
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~nunit-core
> > Post to : nunit-core@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~nunit-core
> > More help : https://help.launchpad.net/ListHelp
> >
>
> --
> You received this bug notification because you are subscribed to NUnit
> Extended Testing Platform.
> https://bugs.launchpad.net/bugs/1172247
>
> Title:
> Improve DateTime equality assertions to include DateTimeKind
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunitv2/+bug/1172247/+subscriptions
>
--
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/1172247
Title:
Improve DateTime equality assertions to include DateTimeKind
Status in NUnit V2 Test Framework:
New
Bug description:
The following test will fail, even if the two DateTime structs are not equal.
(I know it's because the equality members of the DateTime type does the evaluation which doesn't care of the Kind property)
[Test]
public void Foo()
{
var localDate = new DateTime(2013, 04, 24, 13, 17, 44, 678, DateTimeKind.Local);
var systemDate = new DateTime(2013, 04, 24, 13, 17, 44, 678, DateTimeKind.Utc);
Assert.AreNotEqual(localDate, systemDate);
}
But I always extracts my assertions to a helper method which also
checks the Kind property.
public static class AssertX
{
public static void AreEqual(DateTime expected, DateTime actual)
{
Assert.AreEqual(expected, actual);
Assert.AreEqual(expected.Kind, actual.Kind);
}
}
I would like to have NUnit help me with this instead of always calling
my own helper class.
However, I'm not sure how this best could be implemented in NUnit.
A simple overload of AreEqual(object, object) to AreEqual(DateTime, DateTime) risk breaking compability with existing tests out there.
One way would be to instead use another name, Assert.Identical or
similar.
To manage notifications about this bug go to:
https://bugs.launchpad.net/nunitv2/+bug/1172247/+subscriptions
References