Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
};
share|improve this question
    
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. –  user6466 Jan 18 '12 at 21:02
    
@user6466 I went ahead and edited your sample code into the original question since you have the same question. –  Kit Menke Jan 18 '12 at 23:38

2 Answers 2

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

share|improve this answer

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

share|improve this answer
    
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. –  Share Jan 19 '12 at 18:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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