Character copier

We use this kata to demonstrate the concepts of test doubles.

Overview

The character copier is a simple class that reads characters from a source and copies them to a destination one character at a time.

When the Copy() method is called on the copier, it should read characters from the source and copy them to the destination until the source returns a newline (ā€˜\n’). Implement the character copier using test doubles for the source and the destination as follows.

Start from these definitions:

Copier.cs
public class Copier
{
	public Copier(ISource source, IDestination destination) {}
	public void Copy() {}
}
ISource.cs
public interface ISource
{
	char GetChar();
}
IDestination.cs
public interface IDestination
{
	void SetChar(char character);
}

Objectives

  1. Write a stub for source and a spy for destination in your test project.

  2. Repeat the kata but use a mocking framework to create mocks for source and destination.

Examples

Source characters: "abc\n" (string) or {'a', 'b', 'c', '\n'} (array of char)

Copier.Copy();

Destination characters: "abc" (string) or {'a', 'b', 'c'} (array of char)

Last updated