Unit Testing Sitecore

Unit testing is a very popular topic, and is a very good practice to adopt.  Unfortunately, as anyone who has worked with it will know, some common Sitecore classes (Sitecore.Data.Items.Item to name one) can’t be mocked with some popular mocking frameworks, and can’t be directly instantiated.  So, the logical solution (to me) is to let your unit tests access the Sitecore API and databases (some others abstract the detail away, but as the saying goes: “Who guards the guards?”).  There have been quite a few different blog articles written about this topic, and people have approached the problem differently. So I thought that I’d share my approach to writing unit tests for Sitecore solutions. Continue reading Unit Testing Sitecore

Setting Sitecore ImageField

Update: this post uses an older version of the Sitecore API. For an up-to-date solution, please see this updated article.

Recently I had to write something to allow users to upload their own content on a Sitecore site. Not an unusual, or especially difficult, piece of functionality but one thing that did give me a bit of trouble was associating uploaded images (in the media library) with the Sitecore item’s image field. Continue reading Setting Sitecore ImageField