Saturday, 15 March 2014

c# - PrivateObject Invoke throwing MissingMethodException -



c# - PrivateObject Invoke throwing MissingMethodException -

i have next code, in unit test in visual studio 2012. trying test private method gatherdata method in excelfile class. when run test getting missingmethodexception. how can invoke private method in class can unit test?

excelfile xfile = new excelfile("pathhere"); privateobject po = new privateobject(xfile); var retval = po.invoke("gatherdata");

here of excelfile class:

public class excelfile { private fileinfo excelfileinfo; private excelworksheet worksheet; private dictionary<string, string> info = new dictionary<string, string>(); public excelfile(string path) { this.excelfileinfo = new fileinfo(path); } private dictionary<string, string> gatherdata(excelworksheet worksheet) { dictionary<string, string> info = new dictionary<string, string>(); int enddatarow = worksheet.dimension.rows; (int rownumber = 2; rownumber <= enddatarow; rownumber++) { if (validaterow(rownumber)) { string columnonevalue = worksheet.cells[rownumber, 1].value.tostring().trim(), columntwovalue = worksheet.cells[rownumber, 2].value.tostring().trim(); data.add(columnonevalue, columntwovalue); } } homecoming data; } }

the method gatherdata requires argument of type excelworksheet in order work. if create object of excelworksheet , utilize code:

excelfile xfile = new excelfile("pathhere"); privateobject po = new privateobject(xfile); var retval = po.invoke("gatherdata", new object[] {excelworksheetobject});

it should work you.

check out post more details: running system.missingmethodexception: method not found privateobject

cheers!

c# unit-testing visual-studio-2012

No comments:

Post a Comment