maintainable testable sharepoint components spsbe 2014

39
How to Build Maintainable and Testable Custom SharePoint Components #SPSBE24 Edin Kapić April 26 th , 2014

Upload: edin-kapic

Post on 28-Jan-2015

120 views

Category:

Technology


3 download

DESCRIPTION

My slides from the session on SharePoint Saturday Belgium 2014

TRANSCRIPT

Page 1: Maintainable Testable SharePoint Components SPSBE 2014

How to Build Maintainable and Testable Custom SharePoint Components#SPSBE24Edin KapićApril 26th, 2014

Page 2: Maintainable Testable SharePoint Components SPSBE 2014

Thanks to our sponsors!

Gold

Silver

Page 3: Maintainable Testable SharePoint Components SPSBE 2014

Works for Beezy in Barcelona, Spain

President of Catalonian SharePoint User Group (SUG.CAT)

Geek, sailor, philosopher

sug.cat

Ik vraag me af of dit bier

compatibel is met SharePint

@ekapicwww.edinkapic.com

Edin Kapić

Page 4: Maintainable Testable SharePoint Components SPSBE 2014

Introduction

Page 5: Maintainable Testable SharePoint Components SPSBE 2014

SharePoint code should be...

Page 6: Maintainable Testable SharePoint Components SPSBE 2014
Page 7: Maintainable Testable SharePoint Components SPSBE 2014

Deployment structure

Code structure

Source code management

Unit testing SharePoint

Agenda for today

Maintainable

Testable

Page 8: Maintainable Testable SharePoint Components SPSBE 2014

Deployment structure

Page 9: Maintainable Testable SharePoint Components SPSBE 2014

Deployment structure “How the solution pieces will be deployed to SharePoint”

Monolithic WSP Shared WSP + Feature WSPs Framework WSP + Shared WSPs + Feature WSPs

Page 10: Maintainable Testable SharePoint Components SPSBE 2014

Monolithic WSP

Simpler Retraction of one WSP removes shared libraries from BIN/GACOnly one version path for componentsNot granular enough

MySolution.wsp

Page 11: Maintainable Testable SharePoint Components SPSBE 2014

Shared WSP + Feature WSPs

Functionality can be separately versioned and managedRetracting one functionality doesn’t break shared libraries

More complexLimited reusability

Page 12: Maintainable Testable SharePoint Components SPSBE 2014

MySolution.Specific1.wsp

MySolution.Common.wsp

MySolution.Specific2.wsp

Shared WSP + Feature WSPs

Page 13: Maintainable Testable SharePoint Components SPSBE 2014

Framework + Shared + Feature WSPsCommon SharePoint code can be versioned separatelyMore control over code reuse and management over multiple solutions

Even more complex

Page 14: Maintainable Testable SharePoint Components SPSBE 2014

MySolution1.Specific1.wsp

MySolution1.Common.wsp

MySolution1.Specific2.wsp

MyFramework.wsp

MySolution2.Specific1.wsp

MySolution2.Common.wsp

MySolution2.Specific2.wsp

Framework + Shared + Feature WSPs

Page 15: Maintainable Testable SharePoint Components SPSBE 2014

Custom services Can be deployed to various places in SharePoint

Layouts folder ISAPI folder (recommended) Separate IIS site

Page 16: Maintainable Testable SharePoint Components SPSBE 2014

Code architecture

Page 17: Maintainable Testable SharePoint Components SPSBE 2014

Code structure “How your VS solutions and projects are organized”

SharePoint project only SharePoint + Library project SharePoint + Multiple library projects Multiple solutions

Page 18: Maintainable Testable SharePoint Components SPSBE 2014

SharePoint project only Simple Not really flexible

WebParts

Page 19: Maintainable Testable SharePoint Components SPSBE 2014

SharePoint + Library project Some separation of concerns

WebParts Business

Page 20: Maintainable Testable SharePoint Components SPSBE 2014

SharePoint + Multiple library projects Recommended for maximum abstraction Don’t overdo the abstraction :-)

WebParts Business Repositories Tests

Page 21: Maintainable Testable SharePoint Components SPSBE 2014

Multiple solutions Excluding extra projects Reuse projects across solutions

WebParts Business WebParts Business Tests

NoTests Full

Page 22: Maintainable Testable SharePoint Components SPSBE 2014

Demo: Simple to Complex

Page 23: Maintainable Testable SharePoint Components SPSBE 2014

Source code management

Page 24: Maintainable Testable SharePoint Components SPSBE 2014

Source code management Centralized • Distributed

Page 25: Maintainable Testable SharePoint Components SPSBE 2014

Source code management Centralized • Distributed

“The Truth”

Developer 1

Developer 2

Developer 3 Developer 1

Developer 2

Build Server

Corporate Repository

Page 26: Maintainable Testable SharePoint Components SPSBE 2014

Branching Standard guidance still applies

ALM Rangers Branching Guidance on CodePlex

Branch whenever you can’t check in yet

With DVCS branching is much easier

Page 27: Maintainable Testable SharePoint Components SPSBE 2014

Single release branch

Page 28: Maintainable Testable SharePoint Components SPSBE 2014

Two branches (dev + release)

Page 29: Maintainable Testable SharePoint Components SPSBE 2014

Feature branches

Page 30: Maintainable Testable SharePoint Components SPSBE 2014

Unit testing SharePoint

Page 31: Maintainable Testable SharePoint Components SPSBE 2014

Unit tests

Page 32: Maintainable Testable SharePoint Components SPSBE 2014

Testing levels Unit

Isolated functionality

Integration Coordinated functionality

Acceptance End-user functionality

Page 33: Maintainable Testable SharePoint Components SPSBE 2014

Click to insert photo.

Depends on abstractionsSeparates concernsInversion of Control (IoC)Dependency Injection (DI)Repository patternService Locator patternMVP/MVC

Testing-friendly code

Page 34: Maintainable Testable SharePoint Components SPSBE 2014

Demo: Adding unit testing

Page 35: Maintainable Testable SharePoint Components SPSBE 2014

Testing strategies Test the coordinating code first (presenters, controllers, business logic) with mock/stub/fake dependencies

Test the concrete repositories (the ones that hit SharePoint or a database) apart

Don’t forget your CUT

Page 36: Maintainable Testable SharePoint Components SPSBE 2014

SharePoint “quirks” with unit testing SP* objects have no interfaces, are sealed or have no public constructors You can use SharePoint Emulator or Typemock Isolator to get around

it But, your “coordinating code” shouldn’t have dependencies on them

IDs of SharePoint objects are not fixed You can’t access SharePoint server OM remotely

Page 37: Maintainable Testable SharePoint Components SPSBE 2014

Summary

Page 38: Maintainable Testable SharePoint Components SPSBE 2014

Maintainable, testable SharePoint Decide your deployment and code structure and be consistent

Decentralize source code management for greater flexibility

Add abstractions and IoC/DI to your code, but don’t get lost in it

Test, test, test

Page 39: Maintainable Testable SharePoint Components SPSBE 2014

Dank jullie wel!Merci beaucoup!

@ekapicwww.edinkapic.co

m