SlideShare une entreprise Scribd logo
1  sur  25
Test-first
Functional-first
Web API
Ryan Riley


Software Developer WebApiContrib
Logos Bible Software WebApiKoans
                     F#x
                     Frank
A Brief History of
Web API
What is Web
API?
MVC


      http://blogs.msdn.com/b/kiranchalla/archive/2012/05/05
      /asp-net-mvc4-web-api-stack-diagram.aspx
What is Web
API?
System.Net.Http


      http://blogs.msdn.com/b/kiranchalla/archive/2012/05/05
      /asp-net-mvc4-web-api-stack-diagram.aspx
What is Web
API?
Hosting


      http://blogs.msdn.com/b/kiranchalla/archive/2012/05/05
      /asp-net-mvc4-web-api-stack-diagram.aspx
Unit Testing with
HttpClient &
HttpServer
Too many
concerns
1.   Routing
2.   Authentication/Authorization
3.   Other HttpConfiguration settings
4.   Action selection
5.   Action result
6.   Use of MessageHandlers
7.   HttpResponseMessage details
8.   Content formatting
Focus Your Tests
What’s the base?

HttpRequestMessage ->
HttpResponseMessage
Coincidence?
Coincidence?
Why focus on
this one
function?
The Boundary


               Service
     Client   Boundary   Domain
               (HTTP)
Is this really
useful?
Building with
functions
Contact Manager
Redux
Re-integration
Going Deeper
ApiRouter

One of many contributions from Darrel Miller
Routing via HttpMessageHandler
            (a.k.a. function)
Goal: full control over resource routing
Goal: nested resources
Functions all the
way!
Could you build an API using only Message
Handlers?

Could you build an API with functions only?
Frank

Wrap in an HttpMessageHandler
F# for first-class function support
Barely scratches the surface
Summary
Questions?
Thank you


       http://spkr8.com/t/13571

Contenu connexe

Tendances

Angular Owin Katana TypeScript
Angular Owin Katana TypeScriptAngular Owin Katana TypeScript
Angular Owin Katana TypeScriptJustin Wendlandt
 
API design principles for accelerated development
API design principles for accelerated developmentAPI design principles for accelerated development
API design principles for accelerated developmentJonathan LeBlanc
 
ASP.NET 5 Overview for Apex Systems
ASP.NET 5 Overview for Apex SystemsASP.NET 5 Overview for Apex Systems
ASP.NET 5 Overview for Apex SystemsShahed Chowdhuri
 
Using Cookies to Store Your Postman Secrets
Using Cookies to Store Your Postman SecretsUsing Cookies to Store Your Postman Secrets
Using Cookies to Store Your Postman SecretsPostman
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovMongoDB
 
API Security with Postman and Qualys
API Security with Postman and QualysAPI Security with Postman and Qualys
API Security with Postman and QualysPostman
 
Building Faster With Your Team's UI Kit
Building Faster With Your Team's UI KitBuilding Faster With Your Team's UI Kit
Building Faster With Your Team's UI KitAtlassian
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Roy de Kleijn
 
How to Wield Kentico 9 in the Real World
How to Wield Kentico 9 in the Real WorldHow to Wield Kentico 9 in the Real World
How to Wield Kentico 9 in the Real WorldBrian McKeiver
 
Postman: An Introduction for API Ops Professionals
Postman: An Introduction for API Ops ProfessionalsPostman: An Introduction for API Ops Professionals
Postman: An Introduction for API Ops ProfessionalsPostman
 
What is Spring Boot and Why Spring Boot ?
What is Spring Boot and Why Spring Boot ?What is Spring Boot and Why Spring Boot ?
What is Spring Boot and Why Spring Boot ?narendrachinnu
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
API Test Automation
API Test Automation API Test Automation
API Test Automation SQALab
 
ASP.NET 5 Overview - Post Build 2015
ASP.NET 5 Overview - Post Build 2015ASP.NET 5 Overview - Post Build 2015
ASP.NET 5 Overview - Post Build 2015Shahed Chowdhuri
 
KKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - AntonyKKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - AntonyLiyao Chen
 
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabnerPerformance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabnerStephen Thair
 
Drive API Adoption: Reach Over 13 Million Developers
Drive API Adoption: Reach Over 13 Million DevelopersDrive API Adoption: Reach Over 13 Million Developers
Drive API Adoption: Reach Over 13 Million DevelopersPostman
 
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API LifecyclePostman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API LifecyclePostman
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScriptkoppenolski
 

Tendances (20)

Angular Owin Katana TypeScript
Angular Owin Katana TypeScriptAngular Owin Katana TypeScript
Angular Owin Katana TypeScript
 
API design principles for accelerated development
API design principles for accelerated developmentAPI design principles for accelerated development
API design principles for accelerated development
 
ASP.NET 5 Overview for Apex Systems
ASP.NET 5 Overview for Apex SystemsASP.NET 5 Overview for Apex Systems
ASP.NET 5 Overview for Apex Systems
 
Using Cookies to Store Your Postman Secrets
Using Cookies to Store Your Postman SecretsUsing Cookies to Store Your Postman Secrets
Using Cookies to Store Your Postman Secrets
 
Develop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val KarpovDevelop a Basic REST API from Scratch Using TDD with Val Karpov
Develop a Basic REST API from Scratch Using TDD with Val Karpov
 
API Security with Postman and Qualys
API Security with Postman and QualysAPI Security with Postman and Qualys
API Security with Postman and Qualys
 
Building Faster With Your Team's UI Kit
Building Faster With Your Team's UI KitBuilding Faster With Your Team's UI Kit
Building Faster With Your Team's UI Kit
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
How to Wield Kentico 9 in the Real World
How to Wield Kentico 9 in the Real WorldHow to Wield Kentico 9 in the Real World
How to Wield Kentico 9 in the Real World
 
Postman: An Introduction for API Ops Professionals
Postman: An Introduction for API Ops ProfessionalsPostman: An Introduction for API Ops Professionals
Postman: An Introduction for API Ops Professionals
 
What is Spring Boot and Why Spring Boot ?
What is Spring Boot and Why Spring Boot ?What is Spring Boot and Why Spring Boot ?
What is Spring Boot and Why Spring Boot ?
 
ASP.NET Core
ASP.NET CoreASP.NET Core
ASP.NET Core
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
API Test Automation
API Test Automation API Test Automation
API Test Automation
 
ASP.NET 5 Overview - Post Build 2015
ASP.NET 5 Overview - Post Build 2015ASP.NET 5 Overview - Post Build 2015
ASP.NET 5 Overview - Post Build 2015
 
KKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - AntonyKKBOX WWDC17 Security - Antony
KKBOX WWDC17 Security - Antony
 
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabnerPerformance testing automation with Dynatrace  @LDNWebPerf - AndreasGrabner
Performance testing automation with Dynatrace @LDNWebPerf - AndreasGrabner
 
Drive API Adoption: Reach Over 13 Million Developers
Drive API Adoption: Reach Over 13 Million DevelopersDrive API Adoption: Reach Over 13 Million Developers
Drive API Adoption: Reach Over 13 Million Developers
 
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API LifecyclePostman Webinar: How Ping Identity Uses Postman across the API Lifecycle
Postman Webinar: How Ping Identity Uses Postman across the API Lifecycle
 
Intro JavaScript
Intro JavaScriptIntro JavaScript
Intro JavaScript
 

En vedette

Introduction to F#x
Introduction to F#xIntroduction to F#x
Introduction to F#xRyan Riley
 
The Functional Web
The Functional WebThe Functional Web
The Functional WebRyan Riley
 
HTTP: the Other ESB
HTTP: the Other ESBHTTP: the Other ESB
HTTP: the Other ESBRyan Riley
 
Types Of Ecosystems
Types Of EcosystemsTypes Of Ecosystems
Types Of EcosystemsUTS
 
Os utopistas thomas more
Os utopistas thomas moreOs utopistas thomas more
Os utopistas thomas moreJorge Miklos
 
Os utopistas thommaso campanella
Os utopistas thommaso campanellaOs utopistas thommaso campanella
Os utopistas thommaso campanellaJorge Miklos
 

En vedette (7)

Rx workshop
Rx workshopRx workshop
Rx workshop
 
Introduction to F#x
Introduction to F#xIntroduction to F#x
Introduction to F#x
 
The Functional Web
The Functional WebThe Functional Web
The Functional Web
 
HTTP: the Other ESB
HTTP: the Other ESBHTTP: the Other ESB
HTTP: the Other ESB
 
Types Of Ecosystems
Types Of EcosystemsTypes Of Ecosystems
Types Of Ecosystems
 
Os utopistas thomas more
Os utopistas thomas moreOs utopistas thomas more
Os utopistas thomas more
 
Os utopistas thommaso campanella
Os utopistas thommaso campanellaOs utopistas thommaso campanella
Os utopistas thommaso campanella
 

Similaire à Test first

Introduction to ASPNET Core
Introduction to ASPNET CoreIntroduction to ASPNET Core
Introduction to ASPNET CorePuja Pramudya
 
Dot net-course-curriculumn
Dot net-course-curriculumnDot net-course-curriculumn
Dot net-course-curriculumnAmit Sharma
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIKevin Hazzard
 
JavaPerformanceChapter_10
JavaPerformanceChapter_10JavaPerformanceChapter_10
JavaPerformanceChapter_10Saurav Basu
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET PresentationRasel Khan
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCBarry Gervin
 
PHP on Windows 2008
PHP on Windows 2008PHP on Windows 2008
PHP on Windows 2008jorke
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0Buu Nguyen
 
Get going with CakePHP Framework at gnuNify 2010
Get going with CakePHP Framework at gnuNify 2010Get going with CakePHP Framework at gnuNify 2010
Get going with CakePHP Framework at gnuNify 2010Abbas Ali
 
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidLaravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidEndive Software
 
Spring MVC
Spring MVCSpring MVC
Spring MVCyuvalb
 

Similaire à Test first (20)

Introduction to ASPNET Core
Introduction to ASPNET CoreIntroduction to ASPNET Core
Introduction to ASPNET Core
 
Web api
Web apiWeb api
Web api
 
Dot net-course-curriculumn
Dot net-course-curriculumnDot net-course-curriculumn
Dot net-course-curriculumn
 
Web api
Web apiWeb api
Web api
 
Enjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web APIEnjoying the Move from WCF to the Web API
Enjoying the Move from WCF to the Web API
 
JavaPerformanceChapter_10
JavaPerformanceChapter_10JavaPerformanceChapter_10
JavaPerformanceChapter_10
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
PHP on Windows 2008
PHP on Windows 2008PHP on Windows 2008
PHP on Windows 2008
 
New Features of ASP.NET 4.0
New Features of ASP.NET 4.0New Features of ASP.NET 4.0
New Features of ASP.NET 4.0
 
ASP.NET 4.0 Roadmap
ASP.NET 4.0 RoadmapASP.NET 4.0 Roadmap
ASP.NET 4.0 Roadmap
 
ASP.NET WEB API Training
ASP.NET WEB API TrainingASP.NET WEB API Training
ASP.NET WEB API Training
 
Get going with CakePHP Framework at gnuNify 2010
Get going with CakePHP Framework at gnuNify 2010Get going with CakePHP Framework at gnuNify 2010
Get going with CakePHP Framework at gnuNify 2010
 
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidLaravel : A Fastest Growing Kid
Laravel : A Fastest Growing Kid
 
Cakephp
CakephpCakephp
Cakephp
 
Cakephp
CakephpCakephp
Cakephp
 
Cakephp
CakephpCakephp
Cakephp
 
ASP.NET Core Overview
ASP.NET Core OverviewASP.NET Core Overview
ASP.NET Core Overview
 
RoR guide_p1
RoR guide_p1RoR guide_p1
RoR guide_p1
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 

Dernier

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Dernier (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Test first

Notes de l'éditeur

  1. Desire for first-class HTTP infrastructureREST Starter KitStarted in WCF as WCF Web APIBecame more alike to MVCAdopted into ASP.NET
  2. MVC-style framework for building HTTP-based web services
  3. Builds on top of the new, first-class HTTP support in System.Net.Http, available in .NET 4.5 or via NuGet.
  4. Abstracts hosting model so you can run on IIS or self-hostHttpServer can also run as an in-memory host
  5. BecauseHttpServer can run in-memory, testing is really easy. You can use HttpClient, another part of System.Net.Http, or the even lighter-weight HttpMessageInvoker.DEMO: Create a test for the default Web API project
  6. This is great. I’m sure you’ll agree that this is far simpler than what is generally required for testing, such as WatiN or Selenium.However, we are also testing far more than just the server action.That’s a lot of things to verify.On a recent project using Web API, this bit me hard. I tested a number of these pieces, but having so many parts in play at one time distracted me from identifying all the things I wanted to test.In particular, routing, security, and IoC distracted me enough that I neglected to test some basic properties of my HttpResponseMessages, such as correctly returning 201 Created when a new item was created. I eventually remembered to set those tests and identified the problem, but I would much prefer to have identified those first and resolved any issues in the other items later.Action selection may seem a bit odd, as that should be part of the framework. However, if you try to get creative with your routing or add more than one Get/Post/etc. method to your controller, you’ll find this isn’t always trivial.I don’t want to imply that testing all of these things is unimportant. You may want to test all of these; you may only care about the higher or lower levels (integration vs. unit). That’s up to you.
  7. What I want to highlight is an approach I’ve found useful.I want to gain a level of understanding of where my problems are occurring, so I focus my tests on multiple levels.Most of the time, I find my problems are in routing or other HttpConfiguration settings.That’s difficult to diagnose, however, when you are only testing at the highest level.We need to focus our tests to verify the behavior we want in the request -> response interaction.
  8. I like to focus my lowest level tests on the Request -> Response interaction.This is the base for HTTP, and all of this can happen easily within one test.In the end, this is what my API should be exposing.This is also a very simple function, and functions are easy to test.
  9. It should come as no surprise that the most basic ApiController action is one that takes a request and returns a response. Of course, you can write simpler methods, but this is the most fundamental version.
  10. It’s the most fundamental (or nearly so) because the entire Web API framework is based on HttpMessageHandlers, as shown in the diagrams earlier.This is the signature of an HttpMessageHandler. The only difference is the requirement that the response be returned in a Task.You can certainly return a Task<HttpResponseMessage> from an ApiController, as well.However, you most likely won’t typically need a Task in your controller action, so we’ll generally stick to the Request -> Response signature.These two signatures will be our constant allies as we continue.
  11. You are likely asking yourself, why focus on this one function?Your app needs to do a lot more than just serve HTTP requests with responses.NEXT: The Boundary
  12. Your Web API project should be a boundary between your domain and your client.If you want to test your domain, test it before this boundary.Tests for the boundary should be testing the boundary itself.In other words, we want to isolate the boundary’s distribution mechanism.
  13. If you unit test your controllers, you’ll often miss some important details such as correct status codes or various headers that you should expect or send.You’ll hit those when you work on integration testing, but by that point, you are likely focused on cross-cutting concerns like routing and auth.Discuss the pros/cons of using ApiController action selectors and model binders:Pros:GET requests can be simpler. URI parameters can be pulled in for you. Otherwise use UriTemplate.Other developers can determine expectations by reading the action method signatures.Can alleviate a line of code or two, such as not having to read the request body.Cons:In anything other than a GET, URI parameters are often only support for routing.The ApiController.Request property is not immediately visible.Reading the request body from Request.Content gives more control and is sometimes required anyway.Hides the fact that you are really dealing with a request/response interaction.From experience, you almost always have to return an HttpResponseMessage anyway to support various status codes.YMMV
  14. Why the emphasis on functions?Functions are really easy to test.Functions can easily be composed.Functions can easily be wrapped.Functions generally help you avoid shared, mutable state, which in turn helps you avoid hard to detect bugs.These are all lessons from functional programming.Let’s test-drive this approach.
  15. Rebuild the Post method using test-first/functional-first.Note that you can remove IoC use by means of closures.What about shared, mutable state?You always have that somewhere; just push it to the edges.Note: there are certainly limitations here.We cannot leverage the UrlHelper when testing only functions.That doesn’t mean you can’t use these.Think of function-first as an evolutionary testing approach. Build out from a simple function to include the rest of what you need as you go.
  16. Eventually, you will likely want to evolve back to using HttpClient and HttpServer.Only HttpServer takes an HttpConfiguration, and you will need this for hosting your API on one of the out-of-the-box hosting models.Demo: use the valid Location header test as an example
  17. We just saw an example of using this approach merely as a way of helping us focus on ensuring our request -> response interactions were correct.However, you don’t have to stop there.NEXT: ApiRouter
  18. Show the GitHub API demo
  19. Discuss how this is the approach taken by ApiRouter, though that eventually loads a controller.Why do we need controllers at all?What about functions composed together in such a way as to effectively route directly to the appropriate function?
  20. Show the use of simple functions composed into a larger application
  21. We covered testing in Web API.I showed you how you can better focus your testing so that you don’t let configuration distractions make you miss something in the request -> response interactions.We looked at a few ways to take these ideas further and then brought it all back together.Is this approach for everyone? Probably not.No project is the same; however, I have found that better focus on the separate components helps test code more accurately.
  22. One thing I’ve been asked in the past relates to performance.I have yet to do any performance analysis on this technique as I’ve not had any performance problems.