What steps will reproduce the problem? The View interface: public interface IView { void SetList(IList<string> stringList); }
The implementing View: public partial class Form1 : Form, IView { public Form1() { InitializeComponent(); }
public void SetList(IList<string> stringList)
{
//
}
}
The view presenter: public sealed class ViewPresenter { private readonly IView view;
public ViewPresenter(IView view)
{
this.view = view;
var list = new List<string>();
list.Add("item1");
list.Add("item2");
this.view.SetList(list);
}
}
The test: [TestClass] public class ViewPresenterFixture { private ViewPresenter testee; private Mock<IView> mockView; private IList<string> stringList;
[TestInitialize]
public void TestInitialize()
{
this.mockView = new Mock<IView>(MockBehavior.Strict);
this.stringList = new List<string>();
this.stringList.Add("Item1");
this.stringList.Add("Item2");
this.mockView.Setup(mock => mock.SetList(this.stringList));
}
[TestMethod]
public void TestMethod1()
{
this.testee = new ViewPresenter(this.mockView.Object);
}
}
What is the expected output? What do you see instead? Moq should not fire
Test method MoqTest.Test.ViewPresenterFixture.TestMethod1 threw exception: Moq.MockException: IView.SetList(System.Collections.Generic.List`1[System.String]) invocation failed with mock behavior Strict. All invocations on the mock must have a corresponding setup.
What version of the product are you using? On what operating system? Moq 4.0.10827.0, MSTest, Visual Studio 2010 Ultimate, Windows 7 64-Bit
Please provide any additional information below.
Comment #1
Posted on Jul 7, 2011 by Quick MonkeyYour class under test (the presenter) is doing:
var list = new List<string>();
Hence, that list will never be the same that you setup for your mock. You need to use It.Is<> or It.IsAny<>.
Could you please send these questions to the discusion mailing list or stackoverflow instead of creating issues?
Status: Invalid
Labels:
Type-Defect
Priority-Medium