Try our conversational search powered by Generative AI!

Unit test fails with ioc-error after upgrade to 7.5

Vote:
 

We have some unittest that has start to fail after upgrading to EPiServer 7.5.

The error message we get is this:

{"StructureMap Exception Code:  202\nNo Default Instance defined for PluginFamily System.Web.Hosting.VirtualPathProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}

We get it in our extensionclass of PageController (looks like this:)

public abstract class BasePageController : PageController where T : PageData
    {
        private readonly XFormPageUnknownActionHandler _xformHandler;

        private string _contentId;

        private const string _viewDataKeyFormat = "ViewData_{0}";

        private string ViewDataKey
        {
            get
            {
                return string.Format(_viewDataKeyFormat, _contentId);
            }
        }

        protected BasePageController()
        {
            _xformHandler = new XFormPageUnknownActionHandler();
            _contentId = string.Empty;
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!string.IsNullOrEmpty(_contentId))
            {
                if (TempData[ViewDataKey] != null)
                {
                    ViewData = (ViewDataDictionary)TempData[ViewDataKey];
                }
            }

            base.OnActionExecuting(filterContext);
        }

        protected override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (!string.IsNullOrEmpty(_contentId))
            {
                TempData[ViewDataKey] = ViewData;
            }

            base.OnResultExecuting(filterContext);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult Success(XFormPostedData xFormPostedData)
        {
            return Redirect(Request.UrlReferrer.ToString());
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult Failed(XFormPostedData xFormPostedData)
        {
            return Redirect(Request.UrlReferrer.ToString());
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public virtual ActionResult XFormPost(XFormPostedData xFormpostedData, string contentId)
        {
            _contentId = contentId;

            return _xformHandler.HandleAction(this);
        }
    }

And the error comes on this line:

_xformHandler = new XFormPageUnknownActionHandler();

I guess something has changed for that setup that we has missed to implement. Anyone know what?

#90100
Sep 02, 2014 10:35
Vote:
 

Found this when doing some reflection

Version 7.13.0

 /// 
        /// Default constructor that fetches dependencies from IOC container.
        /// 
        public XFormPageUnknownActionHandler() : this(ServiceLocator.get_Current().GetInstance())
        {
        }

        /// 
        /// Constructor with dependencies
        /// 
        /// The url resolver to use.
        public XFormPageUnknownActionHandler(UrlResolver urlResolver)
        {
            this._urlResolver = urlResolver;
        }

Version 7.0.586.24

/// 
        /// Creates a .
        /// 
        public XFormPageUnknownActionHandler()
        {
        }

So I need to think of some way to fake this interface in my test

#90105
Sep 02, 2014 11:00
Vote:
 

Could you not take in UrlResolver as a dependency in your controller and then just pass that instance to XFormPageUnknownActionHandler using the constructor that takes it as argument. The whenever you create your controller in your test you can pass in a mock of UrlResolver.

#90106
Sep 02, 2014 11:06
Vote:
 

Thanks Johan, I just tried to do that and it seems to work.

Well, what to learn from this..... Never extend if you not in great need....

#90107
Sep 02, 2014 11:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.