vendredi 22 mai 2015

Nsubstitute Calls Method of DoNotCallBase in When Method

I am partially mocking a class that has these two methods:

public void EmitTo(string connectionId, ChatMessage message)
{
    Clients.Client(connectionId).broadcastMessage(message.User.UserName, message.Message);
}

public virtual void Broadcast(ChatMessage message)
{
    Clients.All.broadcastMessage(message.User.UserName, message.Message);
}

In my test [SetUp] I have these calls:

hub = Substitute.ForPartsOf<ChatHub>(myMockedClient, context, groupManager);
hub.When(x => x.Broadcast(Arg.Any<ChatMessage>())).DoNotCallBase();
hub.When(x => x.EmitTo(Arg.Any<string>(), Arg.Any<ChatMessage>())).DoNotCallBase();

I have no issues with the Broadcast call on this line or later on when I call the method (they do not do anything as expected) but oddly my third line throws an error:

System.ArgumentException : Argument cannot be null or empty Parameter name: connectionId

I am a bit lost as I did the exact same thing for both methods and get a different behaviour, why does my when method call the EmitTo?

Aucun commentaire:

Enregistrer un commentaire