.net - How to use Moq to Mock an index property with that has two indexes -
this question shows how can mock index property moq: how moq setting indexed property
however, if have 2 index?
for instance, let's have _worksheet object (from vsto)
var mockworksheet = new mock<_worksheet>();
you want create property called cells, such can utilize so:
var range = worksheet.cells[1,1];
note: range can mock, mocked with: var mockrange = new mock();
any suggestions?
you mock property indexers else. they're treated property accessors, you'd utilize setupget
:
var mockworksheet = new mock<worksheet>(); var mockrange = new mock<range>(); var mockcell = new mock<range>(); // setup cells property homecoming range mockworksheet.setupget(p => p.cells).returns(mockrange.object); // setup range homecoming expected "cell" mockrange.setupget(p => p[1, 2]).returns(mockcell.object); var expectedcell = mockworksheet.object.cells[1, 2]; // expectedcell == mockcell.object
.net excel mocking vsto moq
No comments:
Post a Comment