asp.net mvc - Testing issues with MVC Controller using IOC -


i testing controller code using ioc unity. issue initialisation of model passing constructor of controller.

here code in test project

  [testmethod]         public void testhomecontrollerindexmethod()         {             homecontroller controller = new homecontroller(new stubpeopleservice());             viewresult result = controller.index() viewresult;              assert.areequal(0, result);         } 

below code of stubpeopleservice have created pass controller constructor above

  public class stubpeopleservice : ipeople         {              public int age             {                 get;                 set;             }              public string birthplace             {                 get;                 set;             }              public datetime dateofbirth             {                 get;                 set;             }              public int getage(datetime reference, datetime birthday)             {                 int age = reference.year - birthday.year;                 if (reference < birthday.addyears(age)) age--;                  return age + 1;             }              public int height             {                 get;                 set;             }              public list<people> listpeople { { return getpeople(); } }              public string name             {                 get;                 set;             }              public int weight             {                 get;                 set;             }              private list<people> getpeople()             {                  list<people> list = new list<people>();                 list.add(new people                 {                     name = "ranjit menon",                     dateofbirth = datetime.today,                     birthplace = "london",                     age = 25,                     height = 175,                     weight = 85                 });                   return list.orderby(x => x.name).tolist();             }          } 

when debug test , notice properties not contain value. property contains value listpeople property. listpeople property initialise other properties throws object cannot created error.let me know if doing test correctly. need test initialising model values.

code home controller

       private ipeople peopleservice;              public homecontroller(ipeople people)             {                 this.peopleservice = people;             }   public actionresult index()         {             return view(peopleservice);         } 

please find ipeople interface below

public interface ipeople     {         int age { get; set; }         string birthplace { get; set; }         datetime dateofbirth { get; set; }         int getage(datetime reference, datetime birthday);         int height { get; set; }         list<people> listpeople { get; }         string name { get; set; }         int weight { get; set; }     } 


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -