c# - Converting Model to list in an MVC test -
i'm running tests using nsubstitute in vs2012 , i'm trying convert model list, or can count. here's code:
[testmethod] public void startedgame() { // arrange var repo = substitute.for<igamerepository>(); ienumerable<game> expectedgames = new list<game> { new game{ gametypeid = 1, hasstarted = false, id = 1, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 1, hasstarted = false, id = 2, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 2, hasstarted = false, id = 3, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 2, hasstarted = false, id = 4, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 1, hasstarted = false, id = 5, isover = false, ispublic = true, maxplayers = 2, someonereported = false} }; repo.getgames().returns(expectedgames); var sut = new gamecontroller(repo); // act var actual = sut.gamemenustart(); // assert //assert.isinstanceoftype(actual, typeof(viewresult)); var viewresult = actual viewresult; assert.isnotnull(viewresult); }
when debug, can hover on 'viewresult' , see model , there see entries , 'count', how can reach it? i've tried casting 'game' object so:
game[] themodel = (game[])viewresult.model;
and list , more, fails. ideas?
edit: viewresult of type: system.web.mvc.viewresult
here rest of code inside function:
var repo = substitute.for<igamerepository>(); ienumerable<game> expectedgames = new list<game> { new game{ gametypeid = 1, hasstarted = false, id = 1, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 1, hasstarted = false, id = 2, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 2, hasstarted = false, id = 3, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 2, hasstarted = false, id = 4, isover = false, ispublic = true, maxplayers = 2, someonereported = false}, new game{ gametypeid = 1, hasstarted = false, id = 5, isover = false, ispublic = true, maxplayers = 2, someonereported = false} }; repo.getgames().returns(expectedgames); var sut = new gamecontroller(repo);
var thelist = viewresult.model ienumerable<game>;
this did trick.
Comments
Post a Comment