Question: This is C# using MSTest: In the following doubling exercise the class under test is the Copier class. When the class's Copy method is called

This is C# using MSTest: In the following doubling exercise the class under test is the Copier class. When the class's
Copy method is called it should copy a string from the ISource interface to the IDestination
interface one character at a time.
Calling GetChar on the ISource the first time returns the first char in its string. When
GetChar is called a second time it returns the second char in its string, and so on.
When it reaches the end of the string GetChar will return a newline.
Calling SetChar on the IDestination interface takes the char parameter and appends it
to its string.
The Copier class's Copy method contains a loop that will repeatedly calls GetChar and
SetChar until the destination string is the same as the source string, minus the newline.
Copier
Class
Fields
destination : IDestination
source : ISource
Methods
Copier(IDestination destination, ISource source)
Copy() : void
ISource
IDestination
Interface
Interface
Methods
Methods
SetChar(char c): void 1 public class Copier
3 IDestination destination;
4, ISource source;
6, public Copier(IDestination destination, ISource source)
7{
8, this.destination = destination;
9 this. source = source;
12 public void Copy()
14 char c= source.GetChar();
while(c !='
')
{
destination.SetChar(c);
c = source.GetChar();
}
}
} Here is another simple mocking exercise. As in the previous exercise you might want to
implement it first using roll your own Source and Destination classes. Doubling them
yourself first gives you a clearer idea of what variables the classes are actually going to
need in order to fulfill the requirements of the exercise. That makes it a little easier when
you go on and double them with the Moq library.
Copier.Copy copies an empty string (except for the newline.)
Copier.Copy copies a string with 1 character.
Copier.Copy copies a string with 2 characters.
Copier.Copy copies a string with 3 characters.
Copier.Copy throws an IndexOutOfRangeException when the newline is missing.
Copier.Copy throws a NullReferenceException when source is null.
Copier.Copy throws a NullReferenceException when destination is null.
Because mocking allows for behaivor testing as well as state testing you should also write a
few additional tests such as:
Copier.Copy calls the source's GetChar at least once.
Copier Copy calls the destination's SetChar at least once.
Please feel free to add any additional tests you think might be necessary.In the following doubling exercise the class under test is the Copier class. When the class's Copy method is called it should copy a string from the ISource interface to the IDestination interface one character at a time.
Calling GetChar on the ISource the first time returns the first char in its string. When GetChar is called a second time it returns the second char in its string, and so on.
When it reaches the end of the string GetChar will return a newline.
Calling SetChar on the IDestination interface takes the char parameter and appends it to its string.
The Copier class's Copy method contains a loop that will repeatedly calls GetChar and SetChar until the destination string is the same as the source string, minus the newline.
C#
public class Copier
{
IDestination destination;
ISource source;
public Copier(IDestination destination, ISource source)
{
this.destination = destination;
this.source = source;
}
public void Copy()
{
char c = source.GetChar();
while(c !='
')
{
destination.SetChar(c);
c = source.GetChar();
}
}
}
Here is another simple mocking exercise. As in the previous exercise you might want to implement it first using roll your own Source and Destination classes. Doubling them yourself first gives you a clearer idea of what variables the classes are actually going to need in order to fulfill the requirements of the exercise. That makes it a little easier when you go on and double them with the Moq library.
Copier.Copy copies an empty string (except for the newline.)
Copier.Copy copies a string with 1 character.
Copier.Copy copies a string with 2 characters.
Copier.Copy copies a string with 3 characters.
Copier.Copy throws an IndexOutOfRangeException when the newline is missing.
Copier.Copy throws a NullReferenceException when source is null.
Copier.Copy throws a NullReferenceException when destination is null.
Because mocking allows for behaivor testing as well as state testing you should also write a few additional tests such as:
Copier.Copy calls the source's GetChar at least once.
Copier Copy calls the destination's SetChar at least once.
Please feel free to add any additional tests you think might be necessary.
This is C# using MSTest: In the following

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!