Download - SharePoint 2010 Patterns & Practices

Transcript
Page 1: SharePoint 2010  Patterns & Practices

SharePoint 2010 Patterns & Practices

Serge Lucahttp://redwood.beKarine Boschhttp://karinebosch.wordpress.com

Page 2: SharePoint 2010  Patterns & Practices

Audience

• Audience : SharePoint developers & architects• Level : 300

Page 3: SharePoint 2010  Patterns & Practices

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

Page 4: SharePoint 2010  Patterns & Practices

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

Page 5: SharePoint 2010  Patterns & Practices

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

Page 6: SharePoint 2010  Patterns & Practices

(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

Page 7: SharePoint 2010  Patterns & Practices

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

Page 8: SharePoint 2010  Patterns & Practices

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)

Page 9: SharePoint 2010  Patterns & Practices

The Service Locator Pattern

9

Class A

Service A

Service B

Class A

Service A

Service B

Locator

Uses

Uses

Uses

Locates

Locates

Page 10: SharePoint 2010  Patterns & Practices

DEMOThe Service Locator Pattern

Page 11: SharePoint 2010  Patterns & Practices

MVP (Model View Presenter) pattern

11

View Presenter

Model

Page 12: SharePoint 2010  Patterns & Practices

DEMOThe MVP Pattern

Page 13: SharePoint 2010  Patterns & Practices

The Repository pattern

13

Client Business Logic

Your list repository

YourSharePointLists + other storages…

Business Entity

Business Entity? ?

Page 14: SharePoint 2010  Patterns & Practices

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

Page 15: SharePoint 2010  Patterns & Practices

DEMOThe Repository Pattern

Page 16: SharePoint 2010  Patterns & Practices

Linq To SharePoint DSL extension

• To automatically generate a Repository, you can tryLinq To SharePoint DSL Extension from Olivier Carpentier (MCS France)

Page 17: SharePoint 2010  Patterns & Practices

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

Page 18: SharePoint 2010  Patterns & Practices

DEMOMVVM

Page 19: SharePoint 2010  Patterns & Practices

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

Page 20: SharePoint 2010  Patterns & Practices

SPG Reusable libraries

• Service Locator• Settings Manager• SharePoint Logger

20

Page 21: SharePoint 2010  Patterns & Practices

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

Page 22: SharePoint 2010  Patterns & Practices

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

Page 23: SharePoint 2010  Patterns & Practices

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

Page 24: SharePoint 2010  Patterns & Practices

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

Page 25: SharePoint 2010  Patterns & Practices

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

Page 26: SharePoint 2010  Patterns & Practices

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

Page 27: SharePoint 2010  Patterns & Practices

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

Page 28: SharePoint 2010  Patterns & Practices

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

Page 29: SharePoint 2010  Patterns & Practices

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

Page 30: SharePoint 2010  Patterns & Practices

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

Page 31: SharePoint 2010  Patterns & Practices

DEMOUnit testing SharePoint 2010 with Microsoft Pex

Page 32: SharePoint 2010  Patterns & Practices

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

Page 33: SharePoint 2010  Patterns & Practices

DEMOUnit testing SharePoint 2010 with Microsoft Pex and Moles

Page 34: SharePoint 2010  Patterns & Practices

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

Page 35: SharePoint 2010  Patterns & Practices

DEMOUnit testing SharePoint 2010 with Behaved Types

Page 36: SharePoint 2010  Patterns & Practices

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

Page 37: SharePoint 2010  Patterns & Practices

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

Page 38: SharePoint 2010  Patterns & Practices

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

Page 39: SharePoint 2010  Patterns & Practices

THANK YOU