Skip to main content


Showing posts from November, 2017

FakeDb, Layout tests and Sitecore 9

Following the previous post on this blog involving an issue we ran into upgrading a Sitecore project from 8.2 to 9, this one is also on the same subject. The issue this time was some unit tests that make use of the FakeDb  library began to fail following the upgrade. Noticing that it was just tests that involved checking the status of layout related fields, with the help of some de-compilation, it was clear that a change had occurred in the Sitecore.Data.Fields.LayoutField.GetFieldValue method that now involve the use of a pipeline components. I found it was possible to resolve this by adding the following to the app.config file, within the &lgt;sitecore&ggt; element, for the test projects containing the failing tests: <pipelines> <getLayoutSourceFields> <processor type="Sitecore.Pipelines.GetLayoutSourceFields.GetFinalLayoutField, Sitecore.Kernel" /> <processor type="Sitecore.Pipelines.GetLayoutSourceFiel

Unit testing HttpRequestArgs with Sitecore 9

Working on a project currently with Sitecore CMS, which is currently undergoing an upgrade to version 9. We had this piece of code, used in the context of unit testing classes that inherit from HttpRequestProcessor , such as custom page resolvers. To use these classes you override a method Process() that takes an instance of HttpRequestArgs . Constructing these classes from a unit test isn't straightforward and up to now had relied on a method detailed by James-West Sadler on his blog here . public static HttpRequestArgs CreateHttpRequestArgs(string url) { var httpRequest = new HttpRequest(string.Empty, url, string.Empty); var httpResponse = new HttpResponse(new StringWriter()); var httpContext = new HttpContext(httpRequest, httpResponse); var requestArgs = new HttpRequestArgs(new HttpContextWrapper(httpContext), HttpRequestType.End); // Reflection used to call the private Initialize method on the HttpRequestArgs obj