Post on 22-Feb-2016
description
SharePoint 2010 Patterns & Practices
Serge Lucahttp://redwood.beKarine Boschhttp://karinebosch.wordpress.com
Audience
• Audience : SharePoint developers & architects• Level : 300
Topics
• Introduction to SharePoint Patterns and Practices Guidance (SPG)• Main Patterns covered by the SPG• Reusable libraries• Application Lifecycle Management for SharePoint 2010• Unit testing with Pex & Moles• Conclusions
3
Topics
• Introduction to SharePoint Patterns and Practices Guidance (SPG)• Patterns covered by the SPG• Reusable libraries• Application Lifecycle Management for SharePoint 2010• Unit testing with Pex & Moles • Conclusions
4
Introduction to SharePoint 2010 Patterns and Practices Guidance (SPG)
• Team for Microsoft and others (MDSN & CodePlex)• Provides:• Guidance & documentation• Patterns & reference implementations• Reusable Libraries• Discussions lists• Hands –on Labs
(Coding)Challenges when creating enterprise applications
• Testability • Can you isolate your classes
• Flexibility• Can you update or replace code without recompiling
• Configuration• How do you manage configuration settings ? Scalability ?
• Logging and Exception handling• How do you log ? Consistent across the team
• Maintainability• How can you maintain code that is always evolving
• Can your code run in the Cloud? (Office 365 & the Sandbox)• Without Full trust proxy
Topics
• Introduction to SharePoint Patterns and Practices Guidance (SPG)• Patterns covered by the SPG• Reusable libraries• Application Lifecycle Management for SharePoint 2010• Unit testing with Pex & Moles • Conclusions
7
Patterns covered by the SPG
• Mains patterns illustrated (with reference applications in the SPG)• Service Locator pattern• MVP pattern (Model View Presenter)• Repository pattern• MVVM pattern (Model View View Model)
The Service Locator Pattern
9
Class A
Service A
Service B
Class A
Service A
Service B
Locator
Uses
Uses
Uses
Locates
Locates
DEMOThe Service Locator Pattern
MVP (Model View Presenter) pattern
11
View Presenter
Model
DEMOThe MVP Pattern
The Repository pattern
13
Client Business Logic
Your list repository
YourSharePointLists + other storages…
Business Entity
Business Entity? ?
Choosing a SharePoint Data Access Technology
LINQ
Farm Site List Data External Lists
Data Platform
Client-side
Server-side
Strongly-typed
Weakly-typed
Strongly-typed
Weakly-typedServer OM
Client OM
REST APIs
New in 2010
Improved
DEMOThe Repository Pattern
Linq To SharePoint DSL extension
• To automatically generate a Repository, you can tryLinq To SharePoint DSL Extension from Olivier Carpentier (MCS France)
MVVM (Model View ViewModel) pattern
• Model : entities• View Model : bind model• Well adapted to RIA :
• Optimize benefits of Silverlight & WPF (statefull, 2 ways databinding)• Data changed->one or several views should be updated • Data stays in memory for longer in RIA->interesting to notify that data
changes
17
ViewView Model
Model
UI EventsModel change Events
Property changedI Events
Update
ReadViewModel data
DEMOMVVM
Topics
• Introduction to SharePoint Patterns and Practices Guidance (SPG)• Patterns covered by the SPG• Reusable libraries• Application Lifecycle Management for SharePoint 2010• Unit testing with Pex & Moles • Conclusions
19
SPG Reusable libraries
• Service Locator• Settings Manager• SharePoint Logger
20
Topics
• Introduction to SharePoint Patterns and Practices Guidance (SPG)• Patterns covered by the SPG• Reusable libraries• Application Lifecycle Management for SharePoint 2010• Unit testing with Pex & Moles • Conclusions
21
Application Lifecycle Management
• Collect and analyze business requirements• Establish the technical design• Develop the application in iterations• Deploy to test environment• Perform integration tests and performance test
• Deploy to user acceptance test environment• Perform functional tests
• Deploy to production• Manage bug fixes and change requests
22
Manage Application Lifecycle Management with Team Foundation Server 2010
• Analyze business requirementsEnter use cases and split into work itemsEnter test scenarios and link to work items
• Develop the application in iterationsDevelop iteration and link to work itemsBranching/merging
• Test the applicationNightly buildsInnovation: Lab ManagementUnit Tests
• Write complete test suite or use parameterized tests• mock SharePoint objects
Integration testsPerformance tests
• Tools for Code Coverage and Code metrics 23
Application Lifecycle Management for SharePoint 2010
• Develop Features and Solutions• Feature dependencies• Solution dependencies• Feature versioning• Feature.xml changes• <VersionRange>• <AddContentTypeField>• <ApplyElementManifest>• <CustomAction>
• FeatureUpgrading event
Unit Testing SharePoint 2010
• What?• Isolate testable pieces of code • Determine whether it behaves exactly as you expect• Tedious to write• Large percentage of defects are identified during its use• Rerun after bug fixes can detect newly introduced bugs
• Problem with SharePoint: • Unit test should run isolated• SharePoint objects like SPSite need connection to SharePoint• A lot of SharePoint object classes are sealed types with non-
public constructors25
Unit Testing with Visual Studio 2010
• Visual Studio 2010 • Provide test project template for .NET Framework 4
applications
• SP1• Unit test projects that target the .NET Framework 3.5• Support for 64 bits Intellitrace for SharePoint 2010 • Unit Test Host for SharePoint 2010
26
Topics
• Introduction to SharePoint Patterns and Practices Guidance (SPG)• Patterns covered by the SPG• Reusable libraries• Application Lifecycle Management for SharePoint 2010• Unit testing with Pex & Moles • Conclusions
27
Unit testing SharePoint 2010 using Pex and Moles
28
• Microsoft Pex:• Visual Studio 2010 add-in Visual Studio add-in for testing .NET
applications• Parameterized test suites • High code coverage• Can be included in nightly builds because of command line
utility • Microsoft Moles:• Allows you to mock objects• Behaviors
Getting started with Pex and Moles…
29
• Download• Using your MSDN Subscription• Microsoft Research site:
http://research.microsoft.com/en-us/projects/pex/downloads.aspx
• MSDN forum: http://social.msdn.microsoft.com/Forums/en/pex/threads
Peli de Halleux rocks !!!
• Install • Documentation, source code and binaries can be found• C:\Program Files\Microsoft Pex• C:\Program Files\Microsoft Moles
Create Parameterized Unit Tests with Microsoft Pex
30
• What is a parameterized unit test?• A unit test allowing parameters
• A parameterized unit test is organized in 3 sections:
• Arrange• Set up the unit under test
• Act• Exercise the unit under test,
capturing any resulting state• Assert• Verify the behavior through
assertions
DEMOUnit testing SharePoint 2010 with Microsoft Pex
Unit testing SharePoint 2010 using Microsoft Moles
32
• Visual Studio 2010 add-in• Provides isolation using stubs • Can be used together with Microsoft Pex• Creates a mole for each SharePoint class
DEMOUnit testing SharePoint 2010 with Microsoft Pex and Moles
Behaved Types for SharePoint
34
• Moles ask for a lot of coding
• Behaved types provide an in-memory model of SharePoint that can be used in the context of unit testing
• Provides a set of behaviors that mimic the behavior of that instance
• Provides a way to instantiate an instance of a type• Part of the Moles project: • behaviors.samples.zip• Microsoft.SharePoint.Behaviors.dll
• Extend behaved types using Moles
DEMOUnit testing SharePoint 2010 with Behaved Types
Conclusion
36
• More layered approach in SharePoint development needed• Accustom yourself with the SPG• Focus on the main patterns• Include FeatureUpgrading event in your deployment procedure• Use Microsoft Pex to reduce the number of unit tests• Use Microsoft Moles to typeMock (your SharePoint OM…)• Integrate the Cloud in your governance plan
Stay up to date with MSDN Belux
• Register for our newsletters and stay up to date:http://www.msdn-newsletters.be• Technical updates• Event announcements and registration• Top downloads
• Follow our bloghttp://blogs.msdn.com/belux
• Join us on Facebookhttp://www.facebook.com/msdnbehttp://www.facebook.com/msdnbelux
• LinkedIn: http://linkd.in/msdnbelux/ • Twitter: @msdnbelux
Download MSDN/TechNet Desktop Gadget
http://bit.ly/msdntngadget
TechDays 2011 On-Demand
• Watch this session on-demand via Channel9http://channel9.msdn.com/belux
• Download to your favorite MP3 or video player• Get access to slides and recommended resources by the speakers
THANK YOU