MoqAutoMocker and primitive constructor options

I am an avid user of StructureMap MoqAutoMocker, sometimes, however, we come across an "old friend" of ours. Assume the class is "Validator"

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

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

The class above does not matter, in fact it will probably raise a few eyebrows, I just do it for this post, since I could not come up with a better example from the tip of my nose. The fact is that it contains a mixture of primitive data types (connectionString) and interfaces (eventMachine) - during unit testing, I usually set my expectations, for example:

[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());        
}

, : , MoqAutoMocker connectionString, ( , ). : MoqAutoMocker, ?

.

+3
1

, , - AutoMocker.

(. )

+2

Source: https://habr.com/ru/post/1791453/


All Articles