In my day to day work with Sitecore i often have to change Database context to either Core or Web, and using the Database selector is of course, quickly becomes irritating and cumbersome. Then you one could create a custom command that open the content editor with the parameters “sc_lang=*Database*”. But in this post i will show how you can get the same two shortcuts without writing any code.
First you need to go to the core database, and navigate to the this folder:
“/sitecore/content/Documents and settings/All users/Start menu/Left”
Duplicate the link “Content Editor” Name it something meaningful fx. “Web Content Editor”
In the Parameters field add the following “&sc_content=web” for the web database and “&sc_content=core” for the core database. See example image below.
Now go back to the Master database and see the two new shortcuts in the startmenu. Now with these two shortcuts it is really easy to switch between the databases
in this post I will give a simple guide that can get you started on using Sitecore Fakes. So you can start doing unit testing with Sitecore. You can use Sitecore fakes with any testing framework for example Nunit Xunit o any like those.
1. First you should go and download the the code from github :
2. Once you have downloaded the code start it up in Visual Studio, and fix the missing reference for the Sitecore.Kernel.dll see image below, and then build the project. If the test project fails you can, if you like, fix the missing references for Sitecore.Kernel and Sitecore.Nexus all other references can be updated through nuget. But it is not required to get Sitecore.Fakes to work.
3. Now open the solution that holds the code you want to test and add a new “class library” to the solution. To the newly created project you will need to add an app.config file and a references off course to the Sitecore .Fakes.dll you just build in step 2. The App.config filles is ONLY REQUIRED if you need to access anything else but the the “Item.Fields” for example the database child colletion and so on. The content for the app.config you can copy in from test project that Sitecore Fakes comes with and has on Github, but as a service i will give it here.
</pre> <?xml version="1.0"?> <configuration> <configSections> <section name="sitecore" type="Sitecore.Configuration.ConfigReader, Sitecore.Kernel"/> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Sitecore.Logging"/> </configSections> <sitecore database="SqlServer"> <itemManager defaultProvider="default"> <providers> <clear/> <add name="default" type="Sitecore.Fakes.FakeItemProvider,Sitecore.Fakes"/> </providers> </itemManager> <databases> <database id="web" singleInstance="true" type="Sitecore.Fakes.FakeDatabase, Sitecore.Fakes"> <param desc="name">$(id)</param> </database> </databases> <mediaLibrary> <mediaProvider type="Sitecore.Fakes.FakeMediaProvider, Sitecore.Fakes"/> </mediaLibrary> <settings> <setting name="LicenseFile" value="C:\license.xml"/> </settings> </sitecore> <log4net> </log4net> </configuration> <pre>
4. Next add a reference to Sitecore kernel and Sitecore Nexus in the newly created class.
6. Write your first test and see is Fail …. or Pass