O'Reilly logo

Practical Test-Driven Development using C# 7 by Clayton Hunt, John Callaway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Service tests

To build on the previous example, start with an ItExists test.

[Fact]public void ItHasGetAllMethod(){  var speakerService = new SpeakerService();  speakerService.GetAll();}

Since this method was previously added to the SpeakerService, although with a NotImplementedException, it would be best to see this test fail for the proper reason. Delete the GetAll method from the SpeakerService so that the application will fail to compile. Now, add the method back to see that the application once again compiles, and therefore this test passes. This time, have the method return null instead of throwing a new NotImplementedException.

public IEnumerable<SpeakerSummary> GetAll(){  return null;}

Now, ensure that the GetAll method returns a collection ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required