SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch

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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Kürzlich hochgeladen

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
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
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
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
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 

Kürzlich hochgeladen (20)

The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
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
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
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
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 

Test first

Hinweis der Redaktion

  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.