1

Recently I have been assigned a task to implement Unit Testing for my SharePoint object model code. I have gone through the "MSDN" reference. I am stuck now.

I would like to know the difference between MSPSite and BSPSite? When do we need to use one over another?

Code example:

string url = "http://someURL";
Guid listId = Guid.Empty;
int listItemId = -1;
MSPSite.BehaveAsNotImplemented();
BSPSite site = null;
BSPListItem item = null;
MSPSite.ConstructorString = (siteInstance, _url) =>
{
    // Given a site and given the Default Web 
    site = new BSPSite(siteInstance);
    BSPWeb web = site.SetRootWeb();

    // That contains a list 
    BSPList list = web.Lists.SetOne();

    // … with ID = ListId 
    list.ID = listId;

    // … with two fields ContentType, Title
    list.Fields.SetAll("ContentType", "Title");
    item = list.Items.SetOne();

    // Which contain a list item with ID = listItemId 
    item.ID = listItemId;

    // with a value in ContentType 
    item.Items.SetAll(content, null);
};
2
  • I have the same question. I have a sample code here (edited into question above), but I don't understand what is the difference between MSPSite and BSPSite. Commented Jan 18, 2012 at 21:02
  • @user6466 I went ahead and edited your sample code into the original question since you have the same question. Commented Jan 18, 2012 at 23:38

2 Answers 2

1

MSPSite is a Mole type and BSPSite is a Behaved type.Behaved types have prefix BSP and the moles types have MSP.

Mole types are strongly typed wrappers that allow you to redirect any .NET method to a user defined delegate.

Behaved types are wrappers around mole types that provide a way to specify a state and a behavior for the environment in a reusable way.

The use of behaved types leads to simpler and more resilient unit tests, and it's preferable to use behaved types instead of moles wherever possible. To understand how, Please check : http://msdn.microsoft.com/en-us/library/ff798457.aspx

0

The BSPSite is a behaved type and is to be used to instantiate an instance of a type in a desired state. i.e. you may instantiate an BSPWeb to have various lists and libraraies instantiated too.

That is what the code is doing as posted by user6466. Setting up a SharePoint web to have a list, which in turn has two fields configured. Also has an item in the list.

"Behaved types allow you to specify the state of the environment and can be reused in all tests."

This will be of use

1
  • When i run the "Build SharePoint 2010 behaviors using Visual Studio 2010", it created behavior dll's for SharePoint. But it did not created for UserProfile dll's.. where can i get those dll's to test my User Profile applications. Commented Jan 19, 2012 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.