jordimontana82 / fake-xrm-easy

The testing framework for Dynamics CRM and Dynamics 365 which runs on an In-Memory context and deals with mocks or fakes for you
https://dynamicsvalue.com/get-started/overview?source=git
Other
263 stars 182 forks source link

ConditionOperator.LastMonth should ignore time of date #551

Open bwmodular opened 3 years ago

bwmodular commented 3 years ago

Describe the bug The ConditionOperator.LastMonth condition operator brings back different results depending on the time component of the date being queried.

To Reproduce Today is the 31st March 2021.

If I create a record with a date column with this value: 28/02/2021 00:00:00 then the condition operator ConditionOperator.LastMonth retreives the record.

If I create a record with a date column with this value: 28/02/2021 12:06:18 then the condition operator does not return the record.

Expected behavior Both of these dates should be found by the query, as they are both in the last month: February. Both of these dates are found when querying a real v9 instance of CRM.

FakeXrmEasy and Dynamics 365 / CRM version v9

Screenshots Here's a screenshot of a query where the date is set to an exact date, no time component - 28/02/2021 00:00:00 You can see that the query returns one row: image

Here's a screenshot of a query where the date is set to date with a time - 28/02/2021 12:11:25 You can see that no rows are returned: image

Both of these queries should return one row when using the 'last month' criteria.

jordimontana82 commented 3 years ago

Thanks for raising this Ben. Much appreciated.

bwmodular commented 3 years ago

I can't quite work out why this is happening. These tests have been working for weeks, and suddenly stopped working. I think it must either be because we're near a month boundary and the number of days in the previous month is less than the number of days in this month, or because we (in the uk) have just switched to daylight saving, or something like that. Date related tests are always tricky - they have a habit of working on some days and not others! I'll try to remember to test it every day and see if they start working again on 1st of April...

jordimontana82 commented 3 years ago

That could well be Ben, if you try inititalising the date fields as Utc, does it make any difference?

bwmodular commented 3 years ago

The tests are succeeding again this morning, no doubt because it is the first of a new month (1st April). I will reinstate the tests in my build pipeline and see if/when they fail in the future, although we may not see this for a while because we don't commit to this pipeline every day. I may have to just rewrite the tests by making sure the date I create is on (say) the 1st of the previous month, rather than using Today.addmonths(-1). That would stop the build failing but it wouldn't fix the problem with FakeXrmEasy.