Telligent assemblies in unit tests

Telligent assemblies in unit tests

This question is answered

I've run into a problem that I’m hoping someone has experienced before, and has a solution to...

I’m creating unit tests which test functionality of components in an assembly.

The method I’m testing makes use of the Telligent.Evolution.Users.GetUser() which gives  the error “System.InvalidOperationException: The service locator has not been initialized”.

I believe that the services have not been initialized as it is being executed from a test app as opposed to the Telligent website.

This appears to be related to the fact that the services are somehow initialized in the CommunityServer.Global Application_Start handler as called from Global.asax.

Is there a way to get the Telligent assemblies to run out of the web context? What is the recommendation for working with Telligent and unit tests?

Verified Answer
  • I actually managed to do this and have it running. It's slow to run, but it works.

    On visual studio I created a test project just for these kinds of tests, with "file links" to:

    - the .config files

    - language files

    - modules

    I also had to start the Services kernel manually, but that might be because in testing I replace some services to assert some conditions (like that an email was sent with the correct format).

All Replies
  • You can do this by copying the modules and languages folders into the directory where your unit test project is running from.  This will allow you to create the CSContext with the required dependencies.

  • I actually managed to do this and have it running. It's slow to run, but it works.

    On visual studio I created a test project just for these kinds of tests, with "file links" to:

    - the .config files

    - language files

    - modules

    I also had to start the Services kernel manually, but that might be because in testing I replace some services to assert some conditions (like that an email was sent with the correct format).

  • Hi Bruno,

    I am trying to set this up also but have had no success. I still get "The service locator has not been initialized".

    I have added the config files from the web project as links. I have also added the module and languages folders as links (I tried doing it this way too but it won't work: http://stackoverflow.com/questions/3610845/add-as-link-for-folders-in-visual-studio-projects). So I created the folders myself (and sub-folders) and added each group of files as links.

    I can't get this to work though. It errors on: Telligent.Evolution.Extensibility.Caching.Version1.CacheService.Get()


    Full details of the error it throws are below:

    System.InvalidOperationException was unhandled by user code
    Message=The service locator has not been initialized
    Source=Telligent.Common
    StackTrace:

    at Telligent.Common.Services.’()
    at Telligent.Common.Services.Get[T]()
    at Telligent.Evolution.Extensibility.Caching.Version1.CacheService.‹()
    at Telligent.Evolution.Extensibility.Caching.Version1.CacheService.Get(String key, CacheScope scope)
    at Extensions.BusinessLogic.ContentMethods.GetContent(Int32 postId) in C:\Projects\Test\Extensions\BusinessLogic\ContentMethods.cs:line 35

    InnerException:

    Thanks

    Adam

  • Hey Adam,

    Is that on Telligent 6 or 7?

    On Telligent 6 this class might be able to help you: gist.github.com/.../89781fcfd8c12e4bd0aff791c6fc1584e544c6e6 . It's a test base class for our integration tests that bootstraps the services stack and implements a small hook to intercept emails for testing.

    On 7 I've been hitting on some issues that I haven't debugged fully, but so far I noticed that the Ninject kernel needs to be built up differently. If you want, my current work is up at gist.github.com/.../dfa04db3028a34bbbfbe984e532cbd7f0e23ebae . To me it looks like I'm missing a reference or something ( System.IO.FileNotFoundException : Could not load file or assembly 'Telligent.Evolution.AspNetMemberRole' or one of its dependencies. ), but that's just from a cursory look.

    Let me know if any of this helps.

  • This approach worked for us too (Telligent 7)