alexanderzeitler.com - REST using the WCF Web API – getting RESTful the BDD way (Part 4)









Search Preview

REST using the WCF Web API – getting RESTful the BDD way (Part 4) | Alexander Zeitler

alexanderzeitler.com

.com > alexanderzeitler.com

SEO audit: Content analysis

Language Error! No language localisation is found.
Title REST using the WCF Web API – getting RESTful the BDD way (Part 4) | Alexander Zeitler
Text / HTML ratio 41 %
Frame Excellent! The website does not use iFrame solutions.
Flash Excellent! The website does not have any flash contents.
Keywords cloud test = method class REST MachineFakes BDD contacts inside API Web WCF Part Establish MSpec => ContactsResource concrete list called
Keywords consistency
Keyword Content Title Description Headings
test 15
= 12
method 9
class 9
REST 8
MachineFakes 8
Headings
H1 H2 H3 H4 H5 H6
1 0 1 0 0 0
Images We found 3 images on this web page.

SEO Keywords (Single)

Keyword Occurrence Density
test 15 0.75 %
= 12 0.60 %
method 9 0.45 %
class 9 0.45 %
REST 8 0.40 %
MachineFakes 8 0.40 %
BDD 8 0.40 %
contacts 7 0.35 %
inside 7 0.35 %
API 7 0.35 %
Web 7 0.35 %
WCF 7 0.35 %
Part 6 0.30 %
Establish 6 0.30 %
MSpec 6 0.30 %
=> 6 0.30 %
ContactsResource 5 0.25 %
concrete 5 0.25 %
list 5 0.25 %
called 5 0.25 %

SEO Keywords (Two Word)

Keyword Occurrence Density
of the 10 0.50 %
Web API 7 0.35 %
inside the 6 0.30 %
REST using 6 0.30 %
using the 6 0.30 %
the WCF 6 0.30 %
WCF Web 6 0.30 %
the test 6 0.30 %
test class 5 0.25 %
in the 5 0.25 %
to the 4 0.20 %
our ContactsResource 4 0.20 %
As you 4 0.20 %
the Establish 4 0.20 %
want to 4 0.20 %
is the 4 0.20 %
by the 3 0.15 %
Name = 3 0.15 %
which is 3 0.15 %
on a 3 0.15 %

SEO Keywords (Three Word)

Keyword Occurrence Density Possible Spam
WCF Web API 6 0.30 % No
REST using the 6 0.30 % No
using the WCF 6 0.30 % No
the WCF Web 6 0.30 % No
Contact Id = 3 0.15 % No
mapped to the 3 0.15 % No
new Contact Id 3 0.15 % No
name of the 3 0.15 % No
the Establish delegate 3 0.15 % No
the magic of 2 0.10 % No
don't want to 2 0.10 % No
Web API getting 2 0.10 % No
Establish delegate method 2 0.10 % No
we don't want 2 0.10 % No
the Get method 2 0.10 % No
Get method of 2 0.10 % No
from the previous 2 0.10 % No
inside the test 2 0.10 % No
method of our 2 0.10 % No
the test runner 2 0.10 % No

SEO Keywords (Four Word)

Keyword Occurrence Density Possible Spam
REST using the WCF 6 0.30 % No
using the WCF Web 6 0.30 % No
the WCF Web API 6 0.30 % No
new Contact Id = 3 0.15 % No
inside the test runner 2 0.10 % No
RESTful the BDD way 2 0.10 % No
the Get method of 2 0.10 % No
the Establish delegate method 2 0.10 % No
As you can see 2 0.10 % No
is mapped to the 2 0.10 % No
BDD way Part 4 2 0.10 % No
the BDD way Part 2 0.10 % No
getting RESTful the BDD 2 0.10 % No
name of the test 2 0.10 % No
we don't want to 2 0.10 % No
the name of the 2 0.10 % No
of our test class 2 0.10 % No
inside the Establish delegate 2 0.10 % No
WCF Web API getting 2 0.10 % No
and so the circle 1 0.05 % No

Internal links in - alexanderzeitler.com

Fixing Chrome 58+ [missing_subjectAltName] with openssl when using self signed certificates
Fixing Chrome 58+ [missing_subjectAltName] with openssl when using self signed certificates | Alexander Zeitler
Accessing an HTTP API running on your MacBook in a Docker container from your iPhone/iPad using dnsmasq
Accessing an HTTP API running on your MacBook in a Docker container from your iPhone/iPad using dnsmasq | Alexander Zeitler
Deploying Ubuntu Mate Desktop as a developer environment in a Azure VM
Deploying Ubuntu Mate Desktop as a developer environment in a Azure VM | Alexander Zeitler
Deploying Ubuntu Mate Desktop as a developer environment in AWS EC2
Deploying Ubuntu Mate Desktop as a developer environment in AWS EC2 | Alexander Zeitler
Debugging mocha tests in a Docker container using Visual Studio Code
Debugging mocha tests in a Docker container using Visual Studio Code | Alexander Zeitler
Debugging mocha tests with Visual Studio Code when Node.js is installed using nvm
Debugging mocha tests with Visual Studio Code when Node.js is installed using nvm | Alexander Zeitler
Debugging a ES6 Node.js application in a Docker container using Visual Studio Code
Debugging a ES6 Node.js application in a Docker container using Visual Studio Code | Alexander Zeitler
Some thoughts on Open Source Software
Some thoughts on Open Source Software | Alexander Zeitler
Resizing a VMware Workstation VM partition using GParted - get the swap partition out of my way!
Resizing a VMware Workstation VM partition using GParted - get the swap partition out of my way! | Alexander Zeitler
Workflows: using Docker Machine and Docker Compose together in development
Workflows: using Docker Machine and Docker Compose together in development | Alexander Zeitler
Chrome crashes on Ubuntu in VMware Workstation
Chrome crashes on Ubuntu in VMware Workstation | Alexander Zeitler
Rename Visual Studio project including files, folders and namespaces
Rename Visual Studio project including files, folders and namespaces | Alexander Zeitler
A lap around AWS and docker-machine
A lap around AWS and docker-machine | Alexander Zeitler
Integration-testing ASP.NET 5 / MVC 6 Controllers on DNX Beta 4
Integration-testing ASP.NET 5 / MVC 6 Controllers on DNX Beta 4 | Alexander Zeitler
Deploying a ASP.NET MVC 6 API as Azure API App in Azure App Services
Deploying a ASP.NET MVC 6 API as Azure API App in Azure App Services | Alexander Zeitler
lowerCamelCase JSON with ASP.NET MVC 6
lowerCamelCase JSON with ASP.NET MVC 6 | Alexander Zeitler
Running ASP.NET 5 Beta 4 in Docker with DNX runtime #aspnet5 #docker
Running ASP.NET 5 Beta 4 in Docker with DNX runtime #aspnet5 #docker | Alexander Zeitler
Stop complaining or improve yourself
Stop complaining or improve yourself | Alexander Zeitler
#NodeJS / #ExpressJS: Adding routes dynamically at runtime
#NodeJS / #ExpressJS: Adding routes dynamically at runtime | Alexander Zeitler
mongoose: Referencing schema in properties or arrays
mongoose: Referencing schema in properties or arrays | Alexander Zeitler
MongoDB development environment journal size management using mongoctl
MongoDB development environment journal size management using mongoctl | Alexander Zeitler
Farewell...
Farewell... | Alexander Zeitler
Inspecting AngularJS $scope using Firebug and Chrome Developer Tools
Inspecting AngularJS $scope using Firebug and Chrome Developer Tools | Alexander Zeitler
Useful @Brackets extensions for Web Developers
Useful @Brackets extensions for Web Developers | Alexander Zeitler
.NET User Group Karlsruhe: StreamInsight: Complex Event Processing by Microsoft
.NET User Group Karlsruhe: StreamInsight: Complex Event Processing by Microsoft | Alexander Zeitler
“Commit all must be called when a managed buffer has focus” in Microsoft SQL Server Data Tools
“Commit all must be called when a managed buffer has focus” in Microsoft SQL Server Data Tools | Alexander Zeitler
.NET User Group Karlsruhe: Git
.NET User Group Karlsruhe: Git | Alexander Zeitler
Open Source Windows 8 App: Sprudelsuche
Open Source Windows 8 App: Sprudelsuche | Alexander Zeitler
Open Source– Scheissegal?
Open Source– Scheissegal? | Alexander Zeitler
Lowercase JSON with ASP.NET Web API
Lowercase JSON with ASP.NET Web API | Alexander Zeitler
.NET Usergroup Karlsruhe: Think Big – Entwicklung skalierbarer Anwendungen mit Windows Azure
.NET Usergroup Karlsruhe: Think Big – Entwicklung skalierbarer Anwendungen mit Windows Azure | Alexander Zeitler
ASP.NET Web API and RavenDb
ASP.NET Web API and RavenDb | Alexander Zeitler
ASP.NET Web API Round-Up Slides
ASP.NET Web API Round-Up Slides | Alexander Zeitler
ASP.NET MVC 4 public beta including ASP.NET Web API
ASP.NET MVC 4 public beta including ASP.NET Web API | Alexander Zeitler
Hash Bang Urls in Single Page Applications mit ASP.NET MVC
Hash Bang Urls in Single Page Applications mit ASP.NET MVC | Alexander Zeitler
.NET User Group Karlsruhe: Know your Tools
.NET User Group Karlsruhe: Know your Tools | Alexander Zeitler
Git flow init liefert: flags: FATAL unable to determine getopt version unter Cygwin
Git flow init liefert: flags: FATAL unable to determine getopt version unter Cygwin | Alexander Zeitler
Using JsonValue and JsonArray in WCF Web API
Using JsonValue and JsonArray in WCF Web API | Alexander Zeitler
.NET User Group Karlsruhe: PowerShell 3.. 2.. 1..
.NET User Group Karlsruhe: PowerShell 3.. 2.. 1.. | Alexander Zeitler
What’s new in WCF Web API Preview 5 – introducing the test client
What’s new in WCF Web API Preview 5 – introducing the test client | Alexander Zeitler
Externe Templates in KnockoutJS laden
Externe Templates in KnockoutJS laden | Alexander Zeitler
WCF Web API: Role based access control with basic authentication
WCF Web API: Role based access control with basic authentication | Alexander Zeitler
.NET User Group Karlsruhe: Produce Cleaner Code with Aspect-Oriented Programming (AOP)
.NET User Group Karlsruhe: Produce Cleaner Code with Aspect-Oriented Programming (AOP) | Alexander Zeitler
REST using the WCF Web API – POST it!
REST using the WCF Web API – POST it! | Alexander Zeitler
REST using the WCF Web API – getting more RESTful responses (Part 5)
REST using the WCF Web API – getting more RESTful responses (Part 5) | Alexander Zeitler
TypeLoadException when mocking COM objects - Could not load type … from assembly. The type is marked…
TypeLoadException when mocking COM objects - Could not load type … from assembly. The type is marked… | Alexander Zeitler
REST using the WCF Web API – getting RESTful the BDD way (Part 4)
REST using the WCF Web API – getting RESTful the BDD way (Part 4) | Alexander Zeitler
REST using the WCF Web API – refactoring to IoC style (Part 3)
REST using the WCF Web API – refactoring to IoC style (Part 3) | Alexander Zeitler
REST using the WCF Web API – Basics (Part2)
REST using the WCF Web API – Basics (Part2) | Alexander Zeitler
Microsoft Web API – the REST is done by WCF (Part 1)
Microsoft Web API – the REST is done by WCF (Part 1) | Alexander Zeitler
Microsoft Web API – den REST macht WCF (Teil 1)
Microsoft Web API – den REST macht WCF (Teil 1) | Alexander Zeitler
.NET User Group Karlsruhe: Flexible Softwarearchitekturen mit Inversion of Control (IoC)
.NET User Group Karlsruhe: Flexible Softwarearchitekturen mit Inversion of Control (IoC) | Alexander Zeitler
machine.fakes ReSharper Templates
machine.fakes ReSharper Templates | Alexander Zeitler
CreateCert.cmd aus dem Windows Azure Platform Training Kit funktioniert nicht
CreateCert.cmd aus dem Windows Azure Platform Training Kit funktioniert nicht | Alexander Zeitler
JSON via jQuery direkt an einen ASP.NET MVC 3 Controller senden
JSON via jQuery direkt an einen ASP.NET MVC 3 Controller senden | Alexander Zeitler
POSTing Json data using the HttpClient from WCF Web API
POSTing Json data using the HttpClient from WCF Web API | Alexander Zeitler
Using the new WCF Web APIs HttpClient with ASP.NET Forms Authentication
Using the new WCF Web APIs HttpClient with ASP.NET Forms Authentication | Alexander Zeitler
Keyboard Jedi unter x64
Keyboard Jedi unter x64 | Alexander Zeitler
Using WCF Web APIs / WCF Http with ASP.NET Forms Authentication
Using WCF Web APIs / WCF Http with ASP.NET Forms Authentication | Alexander Zeitler
WCF Web APIs / WCF Http mit ASP.NET Forms Authentication verwenden
WCF Web APIs / WCF Http mit ASP.NET Forms Authentication verwenden | Alexander Zeitler
ILSpy – Open Source .NET Assembly Browser und Decompiler
ILSpy – Open Source .NET Assembly Browser und Decompiler | Alexander Zeitler

Alexanderzeitler.com Spined HTML


REST using the WCF Web API – getting RESTful the BDD way (Part 4) | Alexander Zeitler Toggle navigation Home Feed REST using the WCF Web API – getting RESTful the BDD way (Part 4) Written on April 20, 2011 Postings published on this series so far: Microsoft Web API -- the REST is washed-up by WCF (Part 1) REST using the WCF Web API -- Basics (Part2) REST using the WCF Web API -- refactoring to IoC style (Part 3) REST using the WCF Web API -- getting RESTful the BDD way (Part 4) -- this one REST using the WCF Web API -- getting increasingly RESTful responses (Part 5) REST using the WCF Web API -- Post it! (Part 6) RESTless testing Not only does REST wilt increasingly and increasingly important but moreover Test DrivenMinutiae(TDD) has wilt state of the art in professional software development. A less worldwide "sub type" of TDD is Behavior DrivenMinutiae(BDD) which is a wiry software minutiae technique that encourages collaboration between developers and non-developers. BDD is focused on a largest understanding of the software to be written by discussing with stakeholders in their natural language combined with the so tabbed ubiquitous language of the stakeholders problem domain. Yet there are a lot of BDD frameworks misogynist for .NET . The one I like most of them is Machine.Specifications (short: MSpec) with the newish Machine.Fakes (short: MFakes) on top which allows a lean way of BDD by providing an integration layer between MSpec and variegated Mock/Fake/Substitute frameworks such as Rhino.Mocks or Moq and others. Thus Machine.Fakes simplifies the usage of these frameworks on top of MSpec. To cut a long story short, lets write the first test. As you may once suspect: Machine.Fakes is misogynist on NuGet by subtracting a Package Library Reference to "Machine.Fakes.RhinoMocks": As you can see, there are moreover implementations misogynist for FakeItEasy, Moq and NSubstitute. Choosing "Machine.Fakes.RhinoMocks" installs all required dependencies to our project and we're ready to enjoy the magic of Machine.Fakes. As we haven't tested the Get method of our ContactsResource until now, we'll reservation up on this. Here's the test lawmaking (we prefer to speak of "specifications" in MSpec): public matriculation Given_a__ContactsResource__when_requesting_all_contacts : WithSubject<ContactsResource> { static List<Contact> _actualContacts; Establish context = () => { With<TheMicrosoftGangContactList>(); With(new FakeContactRepository(The<IList<IContact>>())); }; Because of = () => { _actualContacts = Subject.Get(); }; It should_return_the_microsoft_gang = () => { _actualContacts.Count.ShouldEqual(3); }; } The result of the specification stuff run in the ReSharper test runner: Now let's see what happened in detail. BDD and thus MSpec follows the AAA syntax for unit tests which ways that tests are run in the pursuit order: Arrange Act Assert Whereas in BDD we use the terms Given When Then which are mapped to the pursuit methods of MSpec: Establish (context) Because (of) It (should something) The name of the test matriculation is mapped to the name of the test inside the test runner and the name of the It-delegate is mapped to the interjection unravelment inside the test runner.Moreoverthe underscores in matriculation and consul name have been replaced by white spaces in order to modernize readability for non-developers. As you can see, our matriculation derives from WithSubject which allows us to work with so tabbed BehaviorConfigs. BehaviorConfigs are classes you can implement to set up dependencies for our system under test (a.k.a. SUT, tabbed Subject in Machine.Fakes terminology). You can use an wrong-headed number of BehaviorConfigs inside your test class. Using the With() or With(new BehaviorConfig()) method inside the Establish consul Machine.Fakes is told to use them. The reasonable question at this point is: what's the use? As you may remember from the previous posting, our ContactsResource has a dependency on the IContactRepository which handles the CRUD operations on the database. When it comes to testing our ContactsResource, we don't want to setup a database having the proper test data ready every time we want to run our tests. Besides that we don't want to test our ContactRepository (which would be the specimen if it were the touchable implementation when testing the ContactsResource) -- we just want to rely on a ContactRepository working properly instead. The way to get rid of the touchable ContactRepository implementation is the usage of Mocks or Stubs and so the whirligig is complete. Mocks/Stubs (or in terms of Machine.Fakes: Fakes) created the Machine.Fakes way are set up inside the BehaviorConfigs (or directly inside the Establish consul method) to be reusable and alimony the Establish method soul short and clear. In order to test our ContactsResource without having a dependency on a touchable ContactRepostory implementation we will use two Fakes: FakeContactRepository, which returns a touchable list of contacts when calling it's Get method TheMicrosoftGangContactList which is the touchable list of three contacts stuff return form the Get method of the FakeContactRepository Now lets take a squint inside the TheMicrosoftGangContactList BehaviorConfig: public matriculation TheMicrosoftGangContactList { OnEstablish context = fakeAccessor => { List<IContact> contacts = new List<IContact>() { new Contact() { Id = 1, Name = "Glenn Block" }, new Contact() { Id = 2, Name = "Scott Hanselman" }, new Contact() { Id = 3, Name = "Scott Guthrie" } }; fakeAccessor.Configure( config => config .For<IList<IContact>>() .Use(() => contacts)); }; } Most of it is similar to the lawmaking from the previous parts of the post series. The main resurgence is the OnEstablish consul whose parameter fakeAccessor is _Configure_d to Use our list tabbed contacts For any request on IList. OnEstablish then is executed in the Establish consul method of our test matriculation later on. This is the magic of BehaviorConfigs explained in well-nigh three words. Did you notice by the way, that you don't have to implement anything to get this to work? Yet, there's flipside BehaviorConfig tabbed FakeContactRepository which is passed into the test matriculation by the second form of With by using parameters. In wing FakeContactRepository itself has a parameter of type IList. At closer inspection you should notice that the undeniability of IList is surrounded by the The<>() method. The intention overdue this method is to get a singleton mock for the given type in the context of our test class. By Configure-ing our IList mock to return the contacts list in the TheMicrosoftGangContactList BehaviorConfig we'll get when the contacts list now by calling The