Skip to main content

Notifications

Supply chain | Supply Chain Management, Commerce
Suggested answer

When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?

Posted on by
Hi all,
 
In FNO, we have a logic to modify the session date, in order to operate on backdate.
 
Now, I want to create some test data in a past period in unit tests.
 
For example, table InventDim has a system field CreatedDateTime. I need to create bundle of InventDim records with CreatedDateTime = one year ago.
 
How can I achieve this?
 
I tried with DateTimeUtil::setSystemDateTimeWithCascadeOption(transDateTime, true), but it is not helpful.
 
Thanks.
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    That's irrelevant. You see classes in AOT even if they internal, and you see classes for unit testing (e.g. SysTestRunner) there as well. Therefore this is not an answer.
     
    I guess they're either not included in the standard application (it's internal development of your company and useless as a suggestion here, or they actually aren't X++ classes. Maybe they're .NET classes and you forgot to mentioned their namespace (at least). It would have been clear if you actually answered my previous question.
     
    Please clarify that, otherwise your answer is not useful. If you have no idea, allow us to help you by providing more information, such as mentioning when you see these classes used.
  • Kai Cheng Profile Picture
    Kai Cheng on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    Hi, Martin,
    I think these codes are for internal usage only. They are used for unit tests of functionality.
  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    Kai, My application (10.0.37) doesn't contain these classes (AtlDateTimeHelper and InventTransferOrderCreateFromSalesLineTest).
    What is your version and which model(s) contains these classes?
  • Suggested answer
    Kai Cheng Profile Picture
    Kai Cheng on at
    When writing Unit Tests, how to initialize the CreatedDateTime of test data to a past DateTime?
    Found a class AtlDateTimeHelper, not sure whether this can apply to my scenario.
     
    Refer to InventTransferOrderCreateFromSalesLineTest.xml

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans