3

I have an application which uploads a file to SharePoint via client object model. Now I need to write unit test cases for this application. The problem is, I how do I write test cases for the scenarios when

  1. a folder exists
  2. a folder does not exist

since this scenario can change anytime i cannot hardcore a folder name. I need to use Microsoft fakes framework. But can I use shims? If so... how to use it?

Thanks for the help!

3

This article has a very detailed inatruction how to use tests and fakes with SharePoint: http://msdn.microsoft.com/en-us/library/jj822928.aspx

| improve this answer | |
  • 2
    Hi Max! If you extend this answer with more details regarding the users specific question it do qualify as an answer. As it stands now it is more of a comment :) – Robert Lindgren Jan 2 '14 at 11:17
1

According to article Using emulators to isolate unit tests for Sharepoint 2010 applications, Microsoft SharePoint Emulators provide a set of shims including SPFolder object, so the following test case could be used:

[TestMethod]
private bool CheckFolderExists(sting url,string folderName) 
{
    using (new SharePointEmulationScope(EmulationMode.Enabled))      
    {      
        SPSite site = new SPSite(url);

        //act    
        SPFolder folder = site.RootWeb.GetFolder(folderName);
        var success = folder.Exists;

        // assert 
        Assert.IsTrue(success);

        // cleanup  
        site.Dispose(); 
}
| improve this answer | |
  • 1
    This is not relevant to client side object model though. – Falak Mahmood Jun 2 '15 at 20:11
  • It is a pity they do not have anything like that for CSOM. – Santhos Oct 27 '16 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.