Created
February 10, 2011 13:25
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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