TASK: DefaultPortalAlias unit test#1769
TASK: DefaultPortalAlias unit test#1769johnhenley wants to merge 30 commits intoDNNCommunity:devfrom
Conversation
|
@valadas @bdukes want to get your help if possible. I am trying to add some unit tests to the forums module. I've successfully added a bunch over the years and have stumbled my way through setting up the required mocks and DI containers to support the tests that access portal, user, module, etc. entities as required for some tests. However, I'm stumped on this one. No matter what I try in the TestBase.cs setup, I always get a NullReference Exception when accessing DefaultPortalAlias in PortalSettings. Since some of the key code in the forums module accesses this property, I want to ensure unit tests around that code but can't until I can figure this out.... Here's a screenshot of the exception: When I look at the platform code, I see this: And in my TestBase, I'm setting up:
Any help greatly appreciated ! |
…eption-url-1768 FIX: VirtualPath exception when retrieving badge image
…ding-comma-taglist-1771 FIX: remove leading comma in list of topic tags in TopicView
|
Unfortunately some of those DNN objects are not easy to mock as they lack proper abstractions in DNN. It is something I would like to contribute to DNN when I have some time. One of the ways I have been dealing with this in the past is to build an adapter that my code uses in order to call those external hard to test things. See https://github.com/DNNCommunity/DNN.UserVoice/blob/develop/Adapters/UserControllerAdapter.cs for an example. DNN does have IUserInfo but most APIs return UserInfo instead. So this does exactly call the DNN implementation but returns the IUserInfo abstration. Then in my tests, I call the easy to mock IUserControllerAdapter instead of the real UserController so that I can mock easily. Once we have proper abstractions for TabInfo and ModuleInfo, I plan to contribute this https://github.com/DNNCommunity/DNN.UserVoice/blob/develop/Controllers/Context/DnnRequestContext.cs to DNN so make it really easy to get all that information out of anything that has an httpContext. Then you can request IDnnRequestContext anywhere to receive all the very popular DNN stuff in an very easy to mock way... |
…ep-1766 TASK: Release Prep
Thanks @valadas. I was hoping there was an easy solution since DefaultPortalAlias is a property of PortalSettings and should return a value which is the case for other properties like PortalID. I will add a method (GetDefaultPortalAlias) to deal with it so it can be testable. |
…tpost-friendly-urls-1776 FIX: Refactor URL code for consistency
…t-post-is-reply-1774 FIX: Last post should include a reply if newer than a topic
…up-friendly-url-1775 FIX: Isolate group in friendly URL rewriter
…riter-tweaks-1780 FIX: Friendly URL issues
…actor-journal-integration-1782 TASK: Refactor journal integration to avoid code duplication
…iendly-urls-1786 FIX: Friendly URLs on alternate URLs
…dden-forums-1789 FIX: Hidden child forums showing in forum view
…endar.css TASK: Remove legacy calendar.css reference
…dule.css-viewer-1792 TASK: Use ClientResourceManager for loading module.css for Viewer module
|
Replaced by PR #1798 |




Adding unit tests and they are failing when portalsettings.DefaultPortalAlias is accessed.
Here is a simple example to demonstrate