Here’s the interface:
public interface IFacebookChatClient
{
Action OnLogin { get; set; }
bool Login(string apiKey, string accessToken);
void SendMessage(string message, string receiverId);
void Close();
}
Here’s a sample usage:
client.Login("...", "...");
client.OnLogin = () =>
{
client.SendMessage("Testing", "Hello World!");
client.Close();
};
In the unit test, I would like to verify that SendMessage was called with particular values. Is this possible?
This is possible by attaching property behavior to
OnLoginproperty:Normally, attempt to call property getter results in
NullReferenceExceptionunlessSetupGetwas called as part of mock initialization. Problem here is, we don’t want to return fixed value from getter as it is set by tested code. We need property to behave as property, without Moq in the way. And that’s whatSetupPropertydoes – tells Moq that property setter/getter should be left intact.