moq: How do I setup behaviour of constructor in generated proxy?

I have an abstract class (let's call it AbstractOutputter). When I derive from it, I make calls to a protected method in the constructor of the derived class.


public abstract class IOutputter<T>
  protected void Write(Func<T, string> output)

Derived class

public class WotsitOutputter: AbstractOutputter<Wotsit>
  public WotsitOutputter()
    Write(x => x.Property1.ToString());
    Write(x => x.Property2.ToString());

The pattern is identical to creating validator classes in FluentValidation:

I would like Moq to create me a class deriving from AbstractOutputter, in order to unit test how it responds to various permutations of calls to Write().. I would need to do something like this:

Mock<AbstractOutputter<Wotsit>> mockOutputter = new Mock<AbstractOutputter<Wotsit>>();
// Instruct Moq to make various calls to protected method in constructor of mock class

Is it possible to do this? Can I somehow tell Moq to perform certain actions within the constructor of the proxy it creates? Or will I need to define real classes extending AbstractOutputter just for unit testing?


I'm going to put this to bed: I conclude that Moq cannot do this.

In the end I just defined some simple implementations of AbstractOutputter<Wotsit> for the purpose of testing.

Need Your Help

Cordova + XCTest results in 'Undefined symbols for architecture i386'

cordova i386 xctest

I'm getting an error when I try to integrate XCTest with a Cordova project. It happens in a fresh cordova app, no customizations. Just add XCTest and tests fail with the following errors:

CGContextDrawImage + CGContextClipToMask performance

iphone ios ipad core-graphics quartz-graphics

I am using CGContextDrawImage and am not happy with the performance.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.