0

I am trying to instantiate the Content API like below

 Ektron.Cms.ContentAPI contentApi = new Ektron.Cms.ContentAPI();

I have added all required references but I am getting below error.

An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Ektron.Cms.ObjectFactory.dll but was not handled in user code

Additional information: Resolution of the dependency failed, type = "Ektron.Cms.Settings.ISite", name = "(none)".

Community
  • 1
  • 1
venkatesh
  • 11
  • 1
  • 5

1 Answers1

3

There are quite a few config files that the Ektron API depends on. This particular error message for the resolution of ISite is resolved in ektron.cms.framework.unity.config.

Using the Ektron API from a non-web project is tricky, to say the least. (reference: Unable to use Ektron Framework API from class library)

It could be that you are confusing unit tests with integration tests. Here are a few SO resources:

Unit testing Ektron code is hard, since the public-facing API doesn't implement an interface. You could write a facade that sits on top of the FrameworkAPI and implements the methods you need to call. Something like this:

public interface IContentManagerFacade
{
    ContentData GetItem(long id, bool returnMetadata);
}

public class ContentManagerFacade : IContentManagerFacade
{
    public ContentData GetItem(long id, bool returnMetadata)
    {
        var cm = new ContentManager();
        return cm.GetItem(id, returnMetadata);
    }
}

This way, you can create a mock implementation of IContentManagerFacade to use in your unit tests. Your facade(s) can get as complex as they need to. If this is the only api method you use, then you're done. If you use more of the API, then your class would grow as well. Perhaps you would also need a TaxonomyManagerFacade or something else.

If you really want to call the Ektron API from your test project, then I wish you luck. You may be able to cobble something together by adding all the config files and probably also referencing System.Web. Alternatively, you could use the 3-tier dlls to call into the Framework API.

update:

Although my answer here uses the FrameworkAPI as its example, the same applies to building facades around the older legacy api classes, such as the ContentAPI class. The only difference is that I do not believe ContentAPI is available as part of the 3-tier api.

Community
  • 1
  • 1
Brian Oliver
  • 1,392
  • 2
  • 14
  • 25