Samstag, 9. Mai 2009

Moq and abstract classes

Today i experimented a little bit with moq and abstract classes.

Lessons learned:

- It is possible, to mock abstract classes and usual classes, it is impossible, to mock sealed classes.
- Only abstract and virtual methods can be mocked.
- Properties can be mocked the following way


public abstract class Entity
{
public abstract int Id { get; protected set; }
}

...
var mock = new Mock<Entity>();
mock.SetupProperty(entity => entity.Id, 5);

Keine Kommentare:

Kommentar veröffentlichen