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

Creating a speaker

The chicken and egg scenario mentioned earlier has us in a predicament. We can't read a speaker from the repository if no speakers have been created. We also can't verify that a speaker has in fact been created unless we can retrieve a speaker from the repository.

One way to solve this problem is by using a special kind of test double that exposes the internal functionality of a class for the purposes of asserting on that information. For Create, we will use this approach. In the Create.cs file, let's add a test that assumes the testable class already exists:

[Fact]public void ItAddsASpeakerToTheRepository(){  // Arrange  var repo = new TestableSpeakerRepository();  // Act  var result = repo.Create(new Speaker()); // Assert ...

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