November Happy Hour will be moved to Thursday December 5th.

Can I moq carthelper class?

Vote:
 

Class seems to obsolete now, but we are using it in lot of places in our projects. I can't see any way to write unit test cases to the methods containing carthelper implementation. It seems be connecting to dbcontext. Is there a way?

#268391
Edited, Dec 14, 2021 15:33
Vote:
 

Hi Dhanush,

To moq CartHelper, you would need to create a Cart Helper wrapping class with a custom interface.

Note that CartHelper is not support when you upgrade to Commerce 13 so you would have to discard the unit tests you are writing now when you upgrade. Consider upgrading before writing the unit tests if possible.

#268392
Dec 14, 2021 16:59
Johnny Mullaney - Dec 15, 2021 10:28
If you'd like to proceed with unit testing the cart helper, there is a good blog post on the wrapper approach here:

https://www.jondjones.com/learn-episerver-cms/episerver-developers-tutorials/episerver-unit-testing/how-to-unit-test-episerver-commerce/?google=amp

Let me know how you go with this
Vote:
 

I strongly suggest to take a look at this Quicksilver/CartService.cs at master · episerver/Quicksilver · GitHub and see if you can convert your code. Beside making your code more futureproof, it also means you get your unit tests with ease

#268433
Dec 15, 2021 13:21
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.