Вопрос

I am an avid user of the StructureMap MoqAutoMocker, sometimes, however, we run into an "old friend" of ours. Assume a class "Validator"

public class Validator
{
   private string _connectionString;
   private IEventMachine _eventMachine;

   public Validator(string connectionString, IEventMachine eventMachine)
   {
      _connectionString = connectionString;
      _eventMachine = eventMachine;
   }
} 

The class above doesn't really matter, in fact, it will probably raise a few eyebrows, I'm just making it for this post, as I could not think of a better example off the tip of my nose. The point is that it contains a mix of primitive datatypes ( connectionString) and interfaces (eventMachine) - during unit testing, I typically set my expectations, such as:

[TestMethod]
public void Validate_WhenCalled_PublishesEnterEvent()
{
    // Arrange
    var Instance = new MoqAutoMocker<Validator>();
    var eventMachineMock = Mock.Get(AutoMock.Get<IEventMachine>());

    // Act
    Instance.Validate();

    // Assert
    eventMachineMock.Verify(m => m.Publish( It.IsAny<string>(), Times.Once());        
}

So, the question is: The above will not work, because MoqAutoMocker fails to accept the connectionString argument, as it cannot find an interface for it (or any other primitive for that matter). My question is simply: Is there a way to tell MoqAutoMocker what this value should be?

In advance, thanks for reading.

Это было полезно?

Решение

No, I dont beleive there is a way - it is a limitation of the AutoMocker.

We tend to avoid primitive constructor params in favor of settings objects (see How we handle application configuration)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top