There is a class whose constructor initializes the local object:
RSZKmodelManager_201638.cs
public class RSZKmodelManager_201638 { private RSZKmodel model; public RSZKmodelManager_201638(Excel.Range rows) { model = new RSZKmodel(); int number = 0; foreach (Excel.Range row in rows) { model.Exercises.Add(new Exercise { Number = number++, Parts = row.Cells[1, 1].Value2.ToString(), ... }); } } } Now in the unit test I would like to test this constructor and check whether initialization is correct:
TestRSZKmodelManager_201638.cs
[TestClass] public class TestRSZKmodelManager_201638 { private IEnumerator RowCollection() { var row1 = new Mock<Excel.Range>(); var row2 = new Mock<Excel.Range>(); row1.Setup(x => x.Cells[1, 1].Value2).Returns("something"); //здесь VS показывает ошибку yield return row1.Object; yield return row2.Object; } [TestMethod] public void TestPopulateModel() { // Arrange var moqRange = new Mock<Excel.Range>(); moqRange.Setup(x => x.GetEnumerator()).Returns(RowCollection); //Act RSZKmodelManager_201638 manager = new RSZKmodelManager_201638(moqRange.Object); // Assert //Assert.IsNotNull(manager); } } Wednesday on the row row1.Setup(x => x.Cells[1, 1].Value2).Returns("something"); shows:
The problem is that the Range.Value2 property Range.Value2 dynamic. Without this, I would somehow get out.) Perhaps Moq does not support such properties? I read something about the Rhino.Mocks framework, but I never used it.
How do I properly lock an Excel.Range object in general?
