Click here to Skip to main content
12,627,190 members (34,079 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

7.1K views
2 bookmarked
Posted

How to Use SharePoint Emulator to Test SharePoint List Creation, Update

, 19 Feb 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
How to use SharePoint Emulator to test SharePoint list creation,Update

Open Visual Studio 2012 and add empty SharePoint project.

image 

Then create the project as farm solution by giving the testing SharePoint server URL (you can give sandbox solution as per your requirement).

image

Then I'm going to add a feature; which is going to create a SharePoint list in feature activation.

image

(adding a feature receiver to the feature)

image

Now I'm going to add a class (SPController.cs) which is used in Feature Activation event for creating the list in SharePoint. SPController class having a method called AddListSample() that is used for creating a list in SharePoint.

public class SPController
    {
        public void AddListSample(String siteURL, String listName, String description)
        {
            using (SPSite site = new SPSite(siteURL))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    Guid listguide = web.Lists.Add(listName, description, SPListTemplateType.GenericList);
                    SPList list = web.Lists[listguide];

                    list.Fields.Add("CustomerName", SPFieldType.Text, true);
                    list.Fields.Add("DOB", SPFieldType.DateTime, false);

                    list.Update();
                }
            }
        }
    }

Now we are adding the code to Feature to create the list.

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
    SPController spcontroller = new SPController();
    spcontroller.AddListSample(SPContext.Current.Site.Url, "SampleList", "List Description");
}

Now we are going to test our code using SharePoint simulator.

For that, we need to create a Test Project First (Framework 3.5).

image

Then, we need to create a test class for test SPContollerClass. So I'm adding SPControllerTest Class to the test Project.

image

image

Before coding, we need to install SharePoint Simulator using NuGet Manager. (This will download fake DLLs for emulation purposes).

image

image

Now, you are going to test the AddListSample method.

image

Note: By using Emulation.Mode.Enabled, this code will test in the Emulated SharePoint environment.

You can go to Test Menu and can Run or Debug the code.

image

image

Test result will display on left side of the screen. It will show failed test as well as passed ones.

image

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Melick
Sri Lanka Sri Lanka
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 19 Feb 2013
Article Copyright 2013 by Melick
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid