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

Updating a speaker

We can now create and retrieve speakers. We have also ensured that we cannot update them by accident. So, let's make sure we can update them on purpose:

[Fact]public void ItUpdatesASpeaker(){  // Arrange  var repo = new SpeakerRepository();  var speaker = repo.Create(new Speaker {Name = "Test Name"});  speaker.Name = "New Name";  // Act  var result = repo.Update(speaker);  // Assert  Assert.Equal(speaker.Name, result.Name);}

Playing devil's advocate again, this is a simple update to the repository:

public Speaker Update(Speaker speaker){  return speaker;}

This is clearly the wrong solution; let's write another, more specific test:

[Fact]public void ItUpdatesASpeakerInTheRepository(){  // Arrange var repo = new SpeakerRepository(); ...

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