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

SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

  • Upload
    biwug

  • View
    178

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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

Page 2: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Thanks to our sponsors!

Gold

Silver

Page 3: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Introduction

Page 5: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

SharePoint code should be...

Page 6: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components
Page 7: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Deployment structure

Code structure

Source code management

Unit testing SharePoint

Agenda for today

Maintainable

Testable

Page 8: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Deployment structure

Page 9: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Monolithic WSP

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

MySolution.wsp

Page 11: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Shared WSP + Feature WSPs

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

More complexLimited reusability

Page 12: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

MySolution.Specific1.wsp

MySolution.Common.wsp

MySolution.Specific2.wsp

Shared WSP + Feature WSPs

Page 13: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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

Even more complex

Page 14: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Custom services Can be deployed to various places in SharePoint

Layouts folder ISAPI folder (recommended) Separate IIS site

Page 16: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Code architecture

Page 17: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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

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

Page 18: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

SharePoint project only Simple Not really flexible

WebParts

Page 19: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

SharePoint + Library project Some separation of concerns

WebParts Business

Page 20: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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

WebParts Business Repositories Tests

Page 21: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Multiple solutions Excluding extra projects Reuse projects across solutions

WebParts Business WebParts Business Tests

NoTests Full

Page 22: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Demo: Simple to Complex

Page 23: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Source code management

Page 24: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Source code management Centralized • Distributed

Page 25: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Source code management Centralized • Distributed

“The Truth”

Developer 1

Developer 2

Developer 3 Developer 1

Developer 2

Build Server

Corporate Repository

Page 26: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Single release branch

Page 28: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Two branches (dev + release)

Page 29: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Feature branches

Page 30: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Unit testing SharePoint

Page 31: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Unit tests

Page 32: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Testing levels Unit

Isolated functionality

Integration Coordinated functionality

Acceptance End-user functionality

Page 33: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Click to insert photo.

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

Testing-friendly code

Page 34: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Demo: Adding unit testing

Page 35: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Summary

Page 38: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

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: SharePoint Saturday Belgium 2014 Building maintainable testable SharePoint components

Dank jullie wel!Merci beaucoup!

@ekapicwww.edinkapic.co

m