fake-xrm-easy icon indicating copy to clipboard operation
fake-xrm-easy copied to clipboard

This / Next / Last Week Condition Operator Tests failing

Open bwmodular opened this issue 3 years ago • 6 comments

Describe the bug The Condition Operator Tests for This/Next/Last week are failing, even though I've not changed anything since last running all of the tests in the solution.

I will take a look and try and work out why, but has anyone else experienced this?

To Reproduce Open the Solution, run all tests. 18 of them fail - see screenshot below.

** FakeXrmEasy and Dynamics 365 / CRM version ** All versions - in the FakeXrmEasy solution itself

Screenshots If applicable, add screenshots to help explain your problem. image

bwmodular avatar Jan 14 '21 14:01 bwmodular

Thanks Ben, I've found out this wasn't working as expected when migrating to v2 so I fixed it there, it was calculating more than 7 days really...

The code is substantially different in the way is structured between the 2 versions so I'll post it here if you want to try in your own fork?

I've changed it to this in v2:

case ConditionOperator.ThisWeek:
   fromDate = today.ToFirstDayOfWeek();
   toDate = fromDate?.AddDays(6);
   break;
case ConditionOperator.LastWeek:
   fromDate = today.AddDays(-7).ToFirstDayOfWeek();
   toDate = fromDate?.AddDays(6);
   break;
case ConditionOperator.NextWeek:
   fromDate = today.AddDays(7).ToFirstDayOfWeek();
   toDate = fromDate?.AddDays(6);
   break;

With this new DateTime extension:

public static DateTime ToFirstDayOfWeek(this DateTime dateTime)
{ 
    var dayOfWeekDelta = (int)dateTime.DayOfWeek - (int)CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek;
    var delta = (7 - dayOfWeekDelta) % 7;
    return dateTime.AddDays(- delta);
}

jordimontana82 avatar Jan 14 '21 23:01 jordimontana82

Thanks Jordi - I'll have a go at implementing in my own v1 fork and let you know,,,

bwmodular avatar Jan 15 '21 09:01 bwmodular

Hi Jordi, I added your datetime extension and re-implemented the ConditionOperaters as you have in v2, but notice that the same tests are still failing randomly. If I run one of the tests 10 times in a row, they fail about half of the time - I suspect something to do with the getRandomDateOfWeek function. So... I started to rewrite the tests themselves, but then noticed something about the ToFirstDayOfWeek method you've posted. I'm writing this on Saturday and it's telling me that the first day of this week is last Thursday. Here's a little LINQPad script I wrote to test: image Am I misunderstanding something, or is the method not working as you'd expect? Unless Brexit has brought about some strange alterations to our calendars I'd expect the First day of the week to be Sunday, or Monday, but definitely not Thursday! Are the tests working OK in v2? ...and here's the same script run on a Friday, and it thinks the first day of the week is now Tuesday: image I'll take a look and see if I can work out why its not working...

bwmodular avatar Jan 16 '21 17:01 bwmodular

This seems to work. I'll use it in my local instance and see if I can get the tests working again: image

bwmodular avatar Jan 22 '21 16:01 bwmodular

Sorry for the delay Ben, I'll revisit this in v2 and will get back to you.

jordimontana82 avatar Jan 24 '21 02:01 jordimontana82

I have something working in v1 - I'll do a PR in the next couple of days and you can take a look.

bwmodular avatar Jan 24 '21 17:01 bwmodular