Products

Solutions

Learn More

Partners

Community

Blog

About

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDNN 8/9 - MVC - Unit Testing with DNN functions - There must be a better wayDNN 8/9 - MVC - Unit Testing with DNN functions - There must be a better way
Previous
 
Next
New Post
2/15/2017 5:54 PM
 

I've been converting one of the modules we work on to MVC so that I can integrate Unit Testing (the plan is to convert all of the modules we work on). I've been running into some snags working with DNN-specific functions and I'm looking for some general advice on what have others done in this type of situation. So far I've been creating Fake functions but some of the functionality I need is pretty extensive: stuff like DataProvider and getting Portal Vocabulary. For the DNN DataProvider I just created a Fake DataProvider that only has the one function I've run into (so far) but I would much rather leverage DNN's actual DataProvider instead of piece-mealing it as I come across function usage in my code.

 

Currently, I'm stuck on getting the Portal Vocabularies as everything is either an Interface or a Read-Only property, specifically the DotNetNuke.Entities.Content.Taxonomy.Vocabulary.Terms property (I think I can fake the rest of what I need for Vocabulary if this property could be set).

 

So far this is what I have for my Fake functions:

            DotNetNuke.Entities.Portals.Fakes.ShimPortalSettings.CurrentGet = () =>

              new PortalSettings { PortalId = TestPortalId, PortalName = "My Portal Name", PortalAlias = PortalAlias };

            DotNetNuke.Common.Utilities.Fakes.ShimDataCache.GetCacheString = new FakesDelegates.Func<string, object>(GetCacheStringTest);

            DotNetNuke.Common.Utilities.Fakes.ShimDataCache.SetCacheStringObject = new FakesDelegates.Action<string, object>(SetCacheStringTest);

            DotNetNuke.Common.Utilities.Fakes.ShimConfig.GetDataBaseOwner = () => "dbo.";

            DotNetNuke.Common.Utilities.Fakes.ShimConfig.GetObjectQualifer = () => "";

            DotNetNuke.Data.Fakes.ShimDataProvider.Instance = new FakesDelegates.Func<DotNetNuke.Data.DataProvider>(GetDataProvider);

            //DotNetNuke.Entities.Users.UserController.Instance.GetCurrentUserInfo();

            DotNetNuke.Entities.Users.Fakes.ShimUserController.GetCurrentUserInfo = new FakesDelegates.Func<DotNetNuke.Entities.Users.UserInfo>(GetUserInfo);

            DotNetNuke.Entities.Portals.Fakes.ShimPortalController.GetPortalSettingsDictionaryInt32 = new FakesDelegates.Func<int, System.Collections.Generic.Dictionary<string, string>>(GetPortalSettingsDirectoryTest);

            //DotNetNuke.Entities.Content.Taxonomy.VocabularyController().GetVocabularies()

            DotNetNuke.Entities.Content.Taxonomy.Fakes.ShimVocabularyController.AllInstances.GetVocabularies = new FakesDelegates.Func<DotNetNuke.Entities.Content.Taxonomy.VocabularyController, System.Linq.IQueryable<DotNetNuke.Entities.Content.Taxonomy.Vocabulary>>(GetVocabulariesTest);

 

Which, quite frankly, seems ridiculous: I feel like there has to be a better way of doing these functions then to just recreate every piece of DNN I need to use. I welcome any advice or suggestions with trying to utilize DNN functionality in my Unit Tests as I'm just stumped on how to do it without faking literally everything.

 
New Post
2/24/2017 12:25 AM
 
Sorry I can't offer any suggestions, but please do note any solutions you do come up with as any suggestions will certainly help others!
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesDNN 8/9 - MVC - Unit Testing with DNN functions - There must be a better wayDNN 8/9 - MVC - Unit Testing with DNN functions - There must be a better way


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out