390 likes | 483 Views
SharePoint 2010 Patterns & Practices. Serge Luca http://redwood.be Karine Bosch http://karinebosch.wordpress.com. Audience. Audience : SharePoint developers & architects Level : 300. Topics. Introduction to SharePoint Patterns and Practices Guidance (SPG)
E N D
SharePoint 2010 Patterns & Practices Serge Luca http://redwood.be Karine Bosch http://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
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
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
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 Uses Service A Class A Uses Service B Locates Service A Uses Locator Class A Service B Locates
MVP (Model View Presenter) pattern View Presenter Model
The Repository pattern Business Entity Client Business Logic Your SharePoint Lists + other storages… ? ? Your list repository Business Entity
Choosing a SharePoint Data Access Technology REST APIs Strongly-typed ClientOM Weakly-typed Client-side Data Platform Farm Site List Data External Lists ServerOM Server-side Weakly-typed LINQ New in 2010 Improved Strongly-typed
Linq To SharePoint DSL extension • To automatically generate a Repository, you can try Linq 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 Model change Events UI Events View Model Property changedI Events Model View Update Read ViewModel data
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
SPG Reusable libraries • Service Locator • Settings Manager • SharePoint Logger
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
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
Manage Application Lifecycle Management with Team Foundation Server 2010 • Analyze business requirements • Enter use cases and split into work items • Enter test scenarios and link to work items • Develop the application in iterations • Develop iteration and link to work items • Branching/merging • Test the application • Nightly builds • Innovation: Lab Management • Unit Tests • Write complete test suite or use parameterized tests • mock SharePoint objects • Integration tests • Performance tests • Tools for Code Coverage and Code metrics
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 constructors
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
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
Unit testing SharePoint 2010 using Pex and Moles • 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… • 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 • 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
Unit testing SharePoint 2010 using Microsoft Moles • Visual Studio 2010 add-in • Provides isolation using stubs • Can be used together with Microsoft Pex • Creates a mole for each SharePoint class
Unit testing SharePoint 2010 with Microsoft Pex and Moles
Behaved Types for SharePoint • 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
Conclusion • 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 DownloadMSDN/TechNet Desktop Gadgethttp://bit.ly/msdntngadget
TechDays 2011 On-Demand • Watchthis 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