Stubbing Properties

Stubbing properties makes it possible for a dependency's property to return a given value. The syntax is a little different from stubbing a function in that the compiler needs to be given the type of the property. For example:

[TestMethod]
public void StubbingPropertiesRequiresReturnTypeSpecification()
{
  Given.That<IName, string>(n => n.FirstName).Returns("Peter");

  var firstName = When.Calling.FirstName;

  Assert.AreEqual("Peter", firstName);
}

The code above states that that the property FirstName on dependency IName which is of type string, should return "Peter" when called. This syntax works the same for properties with and without setters.

Last edited Jul 4, 2011 at 6:08 PM by RasmusTherkelsen, version 4

Comments

No comments yet.