maintainable testable sharepoint components spsbe 2014
DESCRIPTION
My slides from the session on SharePoint Saturday Belgium 2014TRANSCRIPT
![Page 1: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/1.jpg)
How to Build Maintainable and Testable Custom SharePoint Components#SPSBE24Edin KapićApril 26th, 2014
![Page 2: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/2.jpg)
Thanks to our sponsors!
Gold
Silver
![Page 3: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/3.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/4.jpg)
Introduction
![Page 5: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/5.jpg)
SharePoint code should be...
![Page 6: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/6.jpg)
![Page 7: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/7.jpg)
Deployment structure
Code structure
Source code management
Unit testing SharePoint
Agenda for today
Maintainable
Testable
![Page 8: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/8.jpg)
Deployment structure
![Page 9: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/9.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/10.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/11.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/12.jpg)
MySolution.Specific1.wsp
MySolution.Common.wsp
MySolution.Specific2.wsp
Shared WSP + Feature WSPs
![Page 13: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/13.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/14.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/15.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/16.jpg)
Code architecture
![Page 17: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/17.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/18.jpg)
SharePoint project only Simple Not really flexible
WebParts
![Page 19: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/19.jpg)
SharePoint + Library project Some separation of concerns
WebParts Business
![Page 20: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/20.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/21.jpg)
Multiple solutions Excluding extra projects Reuse projects across solutions
WebParts Business WebParts Business Tests
NoTests Full
![Page 22: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/22.jpg)
Demo: Simple to Complex
![Page 23: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/23.jpg)
Source code management
![Page 24: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/24.jpg)
Source code management Centralized • Distributed
![Page 25: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/25.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/26.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/27.jpg)
Single release branch
![Page 28: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/28.jpg)
Two branches (dev + release)
![Page 29: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/29.jpg)
Feature branches
![Page 30: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/30.jpg)
Unit testing SharePoint
![Page 31: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/31.jpg)
Unit tests
![Page 32: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/32.jpg)
Testing levels Unit
Isolated functionality
Integration Coordinated functionality
Acceptance End-user functionality
![Page 33: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/33.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/34.jpg)
Demo: Adding unit testing
![Page 35: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/35.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/36.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/37.jpg)
Summary
![Page 38: Maintainable Testable SharePoint Components SPSBE 2014](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/38.jpg)
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](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54c85b354a7959d7758b47a3/html5/thumbnails/39.jpg)
Dank jullie wel!Merci beaucoup!
@ekapicwww.edinkapic.co
m