Monday 28 March 2011

What Browsers do SharePoint People use

I was looking at the stats from this blog of browsers that visitors used in March 2011, below is a summary:
 BrowserPercent
 IE 841.23%
 FireFox 317.59%
Chrome 1011.58%
 IE 97.96%
 IE 77.27%
 Chrome 95.76%


The most amazing stat was I had 1 visitor using IE4 at least that what their http header provided :)

Update 2 May 2011 - Browsers visting this blog breakdown for last week in April 2011.

Sunday 27 March 2011

SPMetal Jbg Presentation evening

Thank-you to everyone that came to the presentation and Singular who sponsored the event.  I enjoyed doing the 2 sessions and meeting some new SharePoint folk.

Slide decks:

Session 1 - PowerPoint SP2010 Data Access (includes the introduction to LINQ to SharePoint)
Session 2 - PowerPoint presentation on LINQ to SharePoint with the demo

I'll record the slides and if i can get the presentation to a reasonable size I'll add the downloads here - more info to follow.

Code Download:
VS2010 solution - This solution contains 3 projects with the code used for this presentation.
  1. SPDemoLists - Pragmatically deploy the Customers and Order lists with a list lookup and populate the 2 lists with seed data.  Sandbox solution.
  2. SPDemoUI - C# sandbox solution that contains a visual user control (web part) that allows a customer to be selected in a drop down and then display the related orders for that customer.  Additionally there is a button to delete the selected customer. 
  3. SPDemonUnit - is an NUnit blank C# project setup ready to start adding unit tests.
SharePoint 2010 Johannesburg Knowledge Group Meeting Post
Event details: http://sp2010jbg.eventbrite.com/
Session summary's
Session 1
Presentation - Overview of data access in SharePoint. What are your options? Is SharePoint storage always the answer? What is LINQ to SharePoint? What is LINQ to SharePoint not good at? The 8 caveats to LINQ to SharePoint.
Session 2
Demonstrate LINQ to SharePoint 2010. Using Visual Studio creating a visual web part to perform CRUD operations on SharePoint lists.

Saturday 26 March 2011

Cannot delete related SP2010 lists

Problem: You cannot delete either of 2 lists if they are related through a lookup column.  I tried deleting the list instances using Powershell and the SP2010 UI.  The List definition and corresponding content types are being deployed and retracted successfully.  PS error message when deleting either list instance is:
Exception calling "Delete" with "0" argument(s): "This list cannot be deleted because one or more lists are related to it. A relationship between two lists occurs when one of the lists contains a lookup column enforcing a relationship behavior on the other list."
 
Initial Hypothesis:  As I am deploying my lists using content types and there is a lookup column, it is important that they are created in the appropriate order.  As I am chaning my features elements manifest file building out my lists it appears to be that I have got my lists instances tangled so they can't be deleted. 

Resolution: I deployed my solution so that the CT and list definitions were present, I deleted the lookup column using the list setting in the UI.  I could then delete the list instances. 

Friday 25 March 2011

SPMetal - Specified cast is not valid

Problem:  I am using LINQ to SharePoint to retrieve data.  A specific SPMetal list request generates the error "Specified cast is not valid".  Additional error information shown in the UI:
Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.
From the stack trace:
"at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcess.ExecuteDelegate.EndInvoke(IAsyncResult result)"
Hypothesis: The error message is a standard error thrown in a SharePoint sandbox solution. The underlying issue is that the proxy is working on lists using SPMetal however only 1 list is causing the problem.  I remembered that I had altered the list using Powershell.   Obviously the entity proxy class generated is based on the old list.  Generate the proxy with the latest lists.
Resoultion: Run SPMetal again to correct the proxy code as the proxy classes do not match the backend SharePoint lists. 

Tuesday 22 March 2011

SharePoint 2010 Search

SharePoint 2010 Edition comparison

Problem: Setup search securely from scratch
Initial Hypothesis: The setup wizard is not precise enough so it is a better idea to setup search using Powershell or even by creating a new Search Service Application using the UI.  The crawl account used by your Search Service Application can be seen under the "Default content access account" property.
When you create the new Search Service application you loose your existing search data such as indexing, scopes and search settings.
Resolution:
Corey Roth has a good post on permissions for the crawl account.

Security Trimming: Search only returns the results the current user has access to in SharePoint.  File servers work the same way.  Any outside content source you crawl using a specified account will not have security permissions and therefore will show all results.

Tuesday 15 March 2011

Presenting in Johannesburg on 4 April 2011

I'm presenting on Monday the 4th of  April at Corlett Drive for SharePoint 2010 Johannesburg Knowledge Group at 18:00 in the evening so if you are in the area, it will be good to see you. 

Event book and details: http://sp2010jbg.eventbrite.com/
Session summarys
Session 1
Presentation - Overview of data access in SharePoint. What are your options? Is SharePoint storage always the answer? What is LINQ to SharePoint? What is LINQ to SharePoint not good at? The 8 caveats to LINQ to SharePoint.
Session 2
Demonstrate LINQ to SharePoint 2010. Using Visual Studio creating a visual web part to perform CRUD operations on SharePoint lists.

Reference Material:
Project to create Lookup lists

Thursday 10 March 2011

Unit Testing for SharePoint 2010 - Part 2

Part 1 of Unit Testing for SharePoint 2010

Overview:  Part 1 discusses setting up nUnit and TDD.NET on you dev machine and writing a simple unit test.  This post looks at using TypeMock Isolator to unit test SharePoint dependent code.
//Arrange
//Act
//Assert
Background:  I haven't used TypeMock Isolator in the last 2 years but the latest version still is a good candidate for testing SharePoint 2010 based applications.   The TypeMock Isolator allows you to fake calls to SharePoint so that you can run unit testing against the SharePoint object model with actually having SharePoint installed or going to a specific instance of SharePoint 2010.  The full version (i.e. not the SharePoint only version of TypeMoch Isolator) also allows you to do create isolation mocks of you code (see Rhino Mocks is a good Isolator Framework).  So pretty useful for testing SharePoint or Entity Framework.  You simply mock out the expected behaviour and don't need to test the Entity Framework by connecting to it.

Tip:  You can use this exact same technique to test MOSS.
Tip: TypeMock needs a separate build server licence from the developer licences.  You can use the full product that includes the ability to do SharePoint testing or just the SharePoint TypeMock isolator.  As of 6 March 2011 the SharePoint edition costs 249 euros per year.  Licencing is expensive especially for large dev teams with multiple build servers but the returns are good if your organisation buys into TDD.
Tip: The SharePoint edition is fine for testing SharePoint calls but you can't mock your own .NET methods so you can't simply use a factory pattern and then mock your entire .NET method call as was shown to me by Ketul Patel (@Pateketu).

Objectives: Create a unit test that uses TypeMock Isolator that mocks the call to SharePoint.
TypeMock to Isolate a method call:
Add 4 reference for nUnit and TypeMock frameworks.
Add a reference to the library you are testing in my case "MagicBall.dll".
Create a new unit test, I isolate a call to the method "GetSPQuestions" and return a list of strings (this has allowed me to override the normal call that would be made to SharePoint).
My business logic for the "Magic 8 Ball" is shown below.  The key take away is I fake the method call GetSPQuestions() using TypeMock so it doesn't try access SharePoint.  This allows me to test my business logic using SharePoint's object model.
TypeMock to Isolate a SharePoint call:
The previous technique works if the return data is not SharePoint objects, so TypeMock allows you to mock up SharePoint objects.  Whereas this example shows how to unit test by faking SharePoint objects.
  • As you can see the code fakes the SPSite Object, then we fake the "Contracts" SPList object (fakeContractList). 
  • At this point all properties inside the objects are null.  So our list would simple return a list with no objects.
  • The next step is to create 3 fake list items that are added to the "fakeContractList".
The code below shows the business logic/code of my "Magic 8 Ball":
The method QuestionSPList() has child methods that use SharePoint objects.  This example directly fakes the SharePoint object model to allow for unit testing.
Summary:  I prefer to build my calls to the SharePoint API or any external API's in a low level private service method.  Then all I need to do it stub out the entire method as shown in the 1st example.  Faking the SharePoint object model using TypeMock is a good option for testing SharePoint reliant code. 

More Info:
Paul Hunt has done 3 great blogs on Andrew Woodward's SPRetreat so this will give you another viewpoint on unit testing for SharePoint 2010.

Andrew Woodward has a codeplex project (SharePoint Magic 8 Ball) that will give you tons of example code on unit testing.