Skip to content

Instantly share code, notes, and snippets.

@patrik-hagne
Created February 10, 2011 13:25
Show Gist options
  • Select an option

  • Save patrik-hagne/820505 to your computer and use it in GitHub Desktop.

Select an option

Save patrik-hagne/820505 to your computer and use it in GitHub Desktop.
This is how I would test that a decorator delegates to the wrapped object in FakeItEasy.
public interface IRobot
{
string Name { get; set; }
}
public class RoboCop
: IRobot
{
private readonly IRobot robot;
public RoboCop(IRobot robot)
{
this.robot = robot;
}
public string Name
{
get { return string.Concat("Officer ", this.robot.Name); }
set { this.robot.Name = value; }
}
}
public class RoboCopTests
{
[Test]
public void Should_set_name_property_to_wrapped_object()
{
// Arrange
var wrapped = A.Fake<IRobot>();
var cop = new RoboCop(wrapped);
// Act
cop.Name = "John";
// Assert
Assert.That(wrapped.Name, Is.EqualTo("John"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment