linq - Unit test setup never invoked -


i'm trying write unit test test method takes in data groups , runs method. reason setup never invoked. i've debugged , i've checked types passed in , out , data , same after grouping. ideas why wouldn't work?

this in test:

myarray[] grouped = myarray                     .selectmany(x => x.accountvalues)                     .groupby(x => x.timestamp)                     .select(g2 =>                          new accountvalue {                                  amount = g2.sum(x => x.amount),                                  timestamp = g2.key })                     .toarray();  helper    .setup(s => s.compute(grouped, grouped.count())    .returns(somevalue);  var result = _engine.get(accountnumbers, startdate, enddate, code);  helper.verify(v => v.compute(grouped, grouped.count()), times.exactly(1)); 

the actual method i'm testing follows:

public decimal? get(long[] accountnumbers,                            datetime startdate,                            datetime enddate,                            long code) {         var accountnumbersint = array.convertall(accountnumbers, => (int)i);          var myarray = transactionmanager                              .get(accountnumbersint, startdate, enddate, code);          var accountvalues = groupdata(myarray);         var result= helper.compute(accountvalues, accountvalues.count());         return result; }  internal myarray[] groupdata(account[] myarray) {     var grouped = myarray                        .selectmany(x => x.accountvalues)                        .groupby(x => x.timestamp)                        .select(g2 =>                            new accountvalue {                                     amount = g2.sum(x => x.amount),                                     timestamp = g2.key })                        .toarray();     return grouped; } 

edit: helper set follows in test setup

[setup] public void setup() {     _engine = new calcengine();     helper = new mock<ihelper>();     _engine.helper = helper.object; } 

this part here, doesn't invoke method:

helper    .setup(s => s.compute(grouped, grouped.count())    .returns(somevalue); 

the way test written, presume you're testing _engine.get() method. idea create mock, pass method you're testing (different ways that) call method you're testing , observe else called result (side effects).

i see in get() method you're doing following:

var result= helper.compute(accountvalues, accountvalues.count()); 

presuming helper same you're trying verify need pass unit test, like:

helper    .setup(s => s.compute(grouped, grouped.count())    .returns(somevalue);  _engine.helper = helper.object;  // verifications here ... 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -