私は以下の方法を持っています:
public void Enqueue(ICommand itemToQueue)
{
    if (itemToQueue == null)
    {
        throw new ArgumentNullException("itemToQueue");
    }
    // Using the dynamic keywork to ensure the type passed in to the generic
    // method is the implementation type; not the interface.
    QueueStorage.AddToQueue((dynamic)itemToQueue);
}
QueueStorage は、IQueueStorage を実装する依存関係です。単体テストをしたいのですが、(dynamic) キーワードが Moq の適切なバインドを妨げているようです。このキーワードは、キューに追加されるときに、ICommand インターフェイス タイプではなく具象クラス タイプを正しく割り当てるために使用されます。
単体テストは次のようになります。
[Test]
public void Enqueue_ItemGiven_AddToQueueCalledOnQueueStorage()
{
    int timesAddToQueueCalled = 0;
    var dummyQueueStorage = new Mock<IQueueStorage>();
    var testCommand = new TestCommand();
    var queueManager = new AzureCommandQueueManager();
    dummyQueueStorage
        .Setup(x => x.AddToQueue(It.IsAny<TestCommand>()))
        .Callback(() => timesAddToQueueCalled++);
    queueManager.QueueStorage = dummyQueueStorage.Object;
    queueManager.Enqueue(testCommand);
    Assert.AreEqual(1, timesAddToQueueCalled);
}
テスト コマンドは ICommand の空の実装ですが、次のようになります。
private class TestCommand : ICommand
{
}
public interface ICommand
{
}
はtimesAddedToQueuCalledインクリメントされていません。使ってみましIt.IsAny<ICommand>た(testCommand)がダメでした。Callback メソッドが実行されていないようです。誰かが私が間違っていることを見ることができますか?
編集: IQueueStorage コード:
public interface IQueueStorage
{
    void AddToQueue<T>(T item) where T : class;
    T ReadFromQueue<T>() where T : class;
}