SlideShare a Scribd company logo
Writing Testable Code in SharePoint
                           Tim McCarthy
                Senior Technical Architect
                                Perficient
Agenda
•   Introduction
•   Repository Pattern
•   IoC and Dependency Injection Patterns
•   Model View Presenter Pattern
•   Unit Testing strategies
•   Summary
Introduction
•   Tightly-coupled SharePoint Code
•   Difficult to test Web Parts and Pages
•   Need a better way to organize the code
•   The answer: Design Patterns!
What is the Repository Pattern?
•   Isolates the domain model from data access
•   Encapsulates the domain object persistence
•   Persistence Ignorance is bliss!
•   Works well when used with interfaces…
Demo
Repository Pattern
What is IoC?
• Inversion of Control
• Depend upon abstract types, not concrete
  types
Benefits of Inversion of Control
• Can swap out implementations later (such as
  different repositories)
• Allows parts of the application to be built
  independently with no complicated
  dependencies
• Can work in ASP.NET and switch over to
  SharePoint later
What is DI?
• DI = Dependency Injection
• One solution to the problem instantiating
  abstract types
• Available DI frameworks
  – Castle
  – Unity
  – MEF
  – Etc.
Benefits of Dependency Injection
• Can write more granular unit tests
• Don’t need to hit the database for testing UI
  logic
• Allows parts of an application to be easily
  swapped out without re-compiling
• Using a DI framework makes it almost
  seamless!
Demo
IoC and Dependency Injection
Model View Presenter Pattern
• Gets the logic out of your UI so it can be
  tested!
• Forced separation of concerns
• Can enable UI logic to be shared
• Side Point: Why not use MVC in SharePoint?
Demo
Model View Presenter
Unit Testing Strategies
• Test the presenters separately
• Use mock views and mock repositories when
  testing the presenters
• Test the concrete repositories separately
Demo
Unit Tests
Summary
• Design Patterns are the key to better
  SharePoint code!
• Repository, IoC and DI patterns make testing
  way easier
• MVP pattern gets the logic out of your UI code
Get the Source Code!
        Source Code Link
Contact Info
             Tim McCarthy
tim.mccarthy@perficient.com
We want your feedback!
                   Use this QR code or visit:
                   http://sps.la/feedback

                   Silver Sponsors:
Victory Lap- social event
  "SharePoint Victory Lap" Social Event for
     SPSLA will be at: 5:30pm to 8pm at
Di Piazzas (5205 E. Pacific Coast Hwy, 90804)

More Related Content

What's hot

Inside Story: Scratching the Black Box - API
Inside Story: Scratching the Black Box - APIInside Story: Scratching the Black Box - API
Inside Story: Scratching the Black Box - API
Ravisuriya .
 
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
Nordic APIs
 
Gauge from an end user's perspective-fathima harris
Gauge from an end user's perspective-fathima harrisGauge from an end user's perspective-fathima harris
Gauge from an end user's perspective-fathima harris
VodqaBLR
 
Automating functional testing of Flex applications.
Automating functional testing of Flex applications.Automating functional testing of Flex applications.
Automating functional testing of Flex applications.Gokuldas Pillai
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
Аліна Шепшелей
 
Selenium training eduxfactor
Selenium training   eduxfactorSelenium training   eduxfactor
Selenium training eduxfactor
KapilSai3
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
Yan Cui
 
Microsoft Azure Logic Apps - easy way to serverless
Microsoft Azure Logic Apps - easy way to serverlessMicrosoft Azure Logic Apps - easy way to serverless
Microsoft Azure Logic Apps - easy way to serverless
Marcin Tyborowski
 
#MFSummit2016 Build: Innovation and the next generation of COBOL applications
#MFSummit2016 Build: Innovation and the next generation of COBOL applications#MFSummit2016 Build: Innovation and the next generation of COBOL applications
#MFSummit2016 Build: Innovation and the next generation of COBOL applications
Micro Focus
 
The UX of Security
The UX of SecurityThe UX of Security
The UX of Security
Mark Congiusta
 
Api Design
Api DesignApi Design
Api Design
Jason Harmon
 
A better approach for testing microservices - introducing test kits in practice
A better approach for testing microservices - introducing test kits in practiceA better approach for testing microservices - introducing test kits in practice
A better approach for testing microservices - introducing test kits in practice
Maxim Novak
 
Use Automation to Assist -Not Replace- Manual Testing
Use Automation to Assist -Not Replace- Manual TestingUse Automation to Assist -Not Replace- Manual Testing
Use Automation to Assist -Not Replace- Manual Testing
SmartBear
 
Continuous Everything @ dotnet cologne 2019
Continuous Everything @ dotnet cologne 2019Continuous Everything @ dotnet cologne 2019
Continuous Everything @ dotnet cologne 2019
Tobias Hoppenthaler
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Enea Gabriel
 
Test automation_strategy_for_legacysystems
Test automation_strategy_for_legacysystemsTest automation_strategy_for_legacysystems
Test automation_strategy_for_legacysystems
VodqaBLR
 
New Enterprisre Capabilities in Telerik Platform
New Enterprisre Capabilities in Telerik PlatformNew Enterprisre Capabilities in Telerik Platform
New Enterprisre Capabilities in Telerik Platform
Lohith Goudagere Nagaraj
 
How to Effectively Test Your Chatbot | Rasa Summit
How to Effectively Test Your Chatbot  | Rasa SummitHow to Effectively Test Your Chatbot  | Rasa Summit
How to Effectively Test Your Chatbot | Rasa Summit
Rasa Technologies
 
Accelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol developmentAccelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol development
Micro Focus
 

What's hot (19)

Inside Story: Scratching the Black Box - API
Inside Story: Scratching the Black Box - APIInside Story: Scratching the Black Box - API
Inside Story: Scratching the Black Box - API
 
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
The Magic Behind Faster API Development, Testing and Delivery with API Virtua...
 
Gauge from an end user's perspective-fathima harris
Gauge from an end user's perspective-fathima harrisGauge from an end user's perspective-fathima harris
Gauge from an end user's perspective-fathima harris
 
Automating functional testing of Flex applications.
Automating functional testing of Flex applications.Automating functional testing of Flex applications.
Automating functional testing of Flex applications.
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
 
Selenium training eduxfactor
Selenium training   eduxfactorSelenium training   eduxfactor
Selenium training eduxfactor
 
Introduction to Aspect Oriented Programming
Introduction to Aspect Oriented ProgrammingIntroduction to Aspect Oriented Programming
Introduction to Aspect Oriented Programming
 
Microsoft Azure Logic Apps - easy way to serverless
Microsoft Azure Logic Apps - easy way to serverlessMicrosoft Azure Logic Apps - easy way to serverless
Microsoft Azure Logic Apps - easy way to serverless
 
#MFSummit2016 Build: Innovation and the next generation of COBOL applications
#MFSummit2016 Build: Innovation and the next generation of COBOL applications#MFSummit2016 Build: Innovation and the next generation of COBOL applications
#MFSummit2016 Build: Innovation and the next generation of COBOL applications
 
The UX of Security
The UX of SecurityThe UX of Security
The UX of Security
 
Api Design
Api DesignApi Design
Api Design
 
A better approach for testing microservices - introducing test kits in practice
A better approach for testing microservices - introducing test kits in practiceA better approach for testing microservices - introducing test kits in practice
A better approach for testing microservices - introducing test kits in practice
 
Use Automation to Assist -Not Replace- Manual Testing
Use Automation to Assist -Not Replace- Manual TestingUse Automation to Assist -Not Replace- Manual Testing
Use Automation to Assist -Not Replace- Manual Testing
 
Continuous Everything @ dotnet cologne 2019
Continuous Everything @ dotnet cologne 2019Continuous Everything @ dotnet cologne 2019
Continuous Everything @ dotnet cologne 2019
 
Elements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code FirstElements of DDD with ASP.NET MVC & Entity Framework Code First
Elements of DDD with ASP.NET MVC & Entity Framework Code First
 
Test automation_strategy_for_legacysystems
Test automation_strategy_for_legacysystemsTest automation_strategy_for_legacysystems
Test automation_strategy_for_legacysystems
 
New Enterprisre Capabilities in Telerik Platform
New Enterprisre Capabilities in Telerik PlatformNew Enterprisre Capabilities in Telerik Platform
New Enterprisre Capabilities in Telerik Platform
 
How to Effectively Test Your Chatbot | Rasa Summit
How to Effectively Test Your Chatbot  | Rasa SummitHow to Effectively Test Your Chatbot  | Rasa Summit
How to Effectively Test Your Chatbot | Rasa Summit
 
Accelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol developmentAccelerating time to delivery modern tools for cobol development
Accelerating time to delivery modern tools for cobol development
 

Similar to Writing Testable Code in SharePoint

Acing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointAcing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointJeremy Thake
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
Alfresco Software
 
Lean-Agile SharePoint Development
Lean-Agile SharePoint DevelopmentLean-Agile SharePoint Development
Lean-Agile SharePoint DevelopmentBill Ayers
 
Lifecycle Management with SharePoint Apps and Solutions
Lifecycle Management with SharePoint Apps and SolutionsLifecycle Management with SharePoint Apps and Solutions
Lifecycle Management with SharePoint Apps and Solutions
SPC Adriatics
 
Vs11 overview
Vs11 overviewVs11 overview
Vs11 overview
ravclarke
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
Milan Vukoje
 
Software Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuable
Comsysto Reply GmbH
 
2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it
Mark Windholtz
 
Cloud native
Cloud nativeCloud native
Cloud native
Ken Owens
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
Inhacking
 
Crafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectCrafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an Architect
ColdFusionConference
 
Leveraging Force.com: What, Why & Hows?
Leveraging Force.com: What, Why & Hows?Leveraging Force.com: What, Why & Hows?
Leveraging Force.com: What, Why & Hows?
CloudSense
 
Ten Advices for Architects
Ten Advices for ArchitectsTen Advices for Architects
Ten Advices for Architects
Eberhard Wolff
 
Object-Relational Mapping and Dependency Injection
Object-Relational Mapping and Dependency InjectionObject-Relational Mapping and Dependency Injection
Object-Relational Mapping and Dependency Injection
Shane Church
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
10 Hinweise für Architekten
10 Hinweise für Architekten10 Hinweise für Architekten
10 Hinweise für Architekten
adesso AG
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 apps
Phil Leggetter
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
SPC Adriatics
 
Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
Peter Nazarov
 

Similar to Writing Testable Code in SharePoint (20)

Acing application lifecycle management in SharePoint
Acing application lifecycle management in SharePointAcing application lifecycle management in SharePoint
Acing application lifecycle management in SharePoint
 
CUST-3 Document Management with Share
CUST-3 Document Management with ShareCUST-3 Document Management with Share
CUST-3 Document Management with Share
 
Lean-Agile SharePoint Development
Lean-Agile SharePoint DevelopmentLean-Agile SharePoint Development
Lean-Agile SharePoint Development
 
Lifecycle Management with SharePoint Apps and Solutions
Lifecycle Management with SharePoint Apps and SolutionsLifecycle Management with SharePoint Apps and Solutions
Lifecycle Management with SharePoint Apps and Solutions
 
Vs11 overview
Vs11 overviewVs11 overview
Vs11 overview
 
Coding Standard And Code Review
Coding Standard And Code ReviewCoding Standard And Code Review
Coding Standard And Code Review
 
Software Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuableSoftware Architecture and Architectors: useless VS valuable
Software Architecture and Architectors: useless VS valuable
 
2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it2019-Nov: Domain Driven Design (DDD) and when not to use it
2019-Nov: Domain Driven Design (DDD) and when not to use it
 
Cloud native
Cloud nativeCloud native
Cloud native
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
Crafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an ArchitectCrafting ColdFusion Applications like an Architect
Crafting ColdFusion Applications like an Architect
 
SharePoint Custom Development
SharePoint Custom DevelopmentSharePoint Custom Development
SharePoint Custom Development
 
Leveraging Force.com: What, Why & Hows?
Leveraging Force.com: What, Why & Hows?Leveraging Force.com: What, Why & Hows?
Leveraging Force.com: What, Why & Hows?
 
Ten Advices for Architects
Ten Advices for ArchitectsTen Advices for Architects
Ten Advices for Architects
 
Object-Relational Mapping and Dependency Injection
Object-Relational Mapping and Dependency InjectionObject-Relational Mapping and Dependency Injection
Object-Relational Mapping and Dependency Injection
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
 
10 Hinweise für Architekten
10 Hinweise für Architekten10 Hinweise für Architekten
10 Hinweise für Architekten
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 apps
 
Lean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill AyersLean-Agile Development with SharePoint - Bill Ayers
Lean-Agile Development with SharePoint - Bill Ayers
 
Sitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helixSitecore development approach evolution – destination helix
Sitecore development approach evolution – destination helix
 

Recently uploaded

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 

Recently uploaded (20)

State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 

Writing Testable Code in SharePoint

  • 1. Writing Testable Code in SharePoint Tim McCarthy Senior Technical Architect Perficient
  • 2. Agenda • Introduction • Repository Pattern • IoC and Dependency Injection Patterns • Model View Presenter Pattern • Unit Testing strategies • Summary
  • 3. Introduction • Tightly-coupled SharePoint Code • Difficult to test Web Parts and Pages • Need a better way to organize the code • The answer: Design Patterns!
  • 4. What is the Repository Pattern? • Isolates the domain model from data access • Encapsulates the domain object persistence • Persistence Ignorance is bliss! • Works well when used with interfaces…
  • 6. What is IoC? • Inversion of Control • Depend upon abstract types, not concrete types
  • 7. Benefits of Inversion of Control • Can swap out implementations later (such as different repositories) • Allows parts of the application to be built independently with no complicated dependencies • Can work in ASP.NET and switch over to SharePoint later
  • 8. What is DI? • DI = Dependency Injection • One solution to the problem instantiating abstract types • Available DI frameworks – Castle – Unity – MEF – Etc.
  • 9. Benefits of Dependency Injection • Can write more granular unit tests • Don’t need to hit the database for testing UI logic • Allows parts of an application to be easily swapped out without re-compiling • Using a DI framework makes it almost seamless!
  • 11. Model View Presenter Pattern • Gets the logic out of your UI so it can be tested! • Forced separation of concerns • Can enable UI logic to be shared • Side Point: Why not use MVC in SharePoint?
  • 13. Unit Testing Strategies • Test the presenters separately • Use mock views and mock repositories when testing the presenters • Test the concrete repositories separately
  • 15. Summary • Design Patterns are the key to better SharePoint code! • Repository, IoC and DI patterns make testing way easier • MVP pattern gets the logic out of your UI code
  • 16. Get the Source Code! Source Code Link
  • 17. Contact Info Tim McCarthy tim.mccarthy@perficient.com
  • 18. We want your feedback! Use this QR code or visit: http://sps.la/feedback Silver Sponsors:
  • 19. Victory Lap- social event "SharePoint Victory Lap" Social Event for SPSLA will be at: 5:30pm to 8pm at Di Piazzas (5205 E. Pacific Coast Hwy, 90804)

Editor's Notes

  1. Many developers forget good object-oriented design techniques when developing in SharePoint, most of the time because they get overwhelmed by the framework. Unit testing often gets thrown out of the window, and most of the time the application becomes very tightly coupled to the SharePoint object model. This talk will demonstrate how to overcome these obstacles and build solid SharePoint application code that is much more testable and is easier to maintain.The vehicle for this goodness is design patterns!
  2. Using the repository pattern will allow you to develop outside of the SharePoint environment "up until the last minute"
  3. Depend on abstract types (interfaces) instead of concrete classes!Don’t need a big bulky 64-bit Windows 2008 Server virtual machine until much later!
  4. MVP is good for web forms projects, which is what SharePoint is based uponModel: Defines the data to be displayed or acted upon in the UIView: UI that displays data from the Model and routes user commands to the Presenter to act upon the dataPresenter: Acts upon the model and the ViewWith MVP, the idea is to strip as much logic and code out of the UI and make it do simple things, like data binding and and acting as a facade to the various UI element properties, i.e. expose TextBox.Text property as FirstName.This pattern really pays for itself when you find bugs in the UI logic…just write a failing unit test and fix the code so it passes the test!Very difficult to use MVC in SharePoint, not worth the effort
  5. Doing TDD by the letter takes a lot of discipline. Once you start doing it, it can become a habit. But even if you don't write your tests first, if you use DI + MVP + tests later, you still will benefit from the modularity and freedom to refactor your code.Writing tests can take up time initially, but the payoff happens in spades once you have to identify and fix bugs, or refactor your code with confidence of not breaking anything else.Mock up your views and repositories so you only test what is necessary...that way your tests are really focused. You can (and should) do integration tests later where you use the real repositories. Once you have a pretty good suite of tests developed, you can freely make changes to your code and see if your tests still pass. Refactor, compile, re-test.Rinse, lather, repeat!