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

Implementing a test version of the interface

In order to create an interface named IGravatarService, there first must be a need within the application. Create a test within a SpeakerServiceTests Get class entitled ItTakesGravatarService:

[Fact]public void ItTakesGravatarService(){  // Arrange  var fakeGravatarService = new FakeGravatarService();  var service = new SpeakerService(_fakeRepository, fakeGravatarService);           }

This will cause a compilation error. Create an IGravatarService and modify the constructor of the SpeakerService so that this is a parameter.

Interface:

public interface IGravatarService{}

SpeakerService method:

public SpeakerService(IRepository repository, IGravatarService gravatarService){  _repository = repository;}

In order ...

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