unit testing - Should the CustomEventArgs method implement another Interface? -


hi using test driven development , seem in area not familiar. please check , let me know changes should make in code make "unit testable" ?

code tested:

public void purchaseitemlist() {      //call methods checkavailablility      if(!productavailable)      {          purchaseitemeventargs.issuccessfull = false;      }      else      {            purchaseitemeventargs.issuccessfull = true;          // code update model.          purchaseitemeventargs.itemspurchased = getitemspurchased()      } } 

now issue face cannot mock purchaseitemeventargs class not implement interface. using moq testing. advise on code changes make unit testable helpfull.

thanks

since getitemspurchased() method of class, make protected virtual. define test class this:

class testablemyclass : myclass{   private items _items;    public testablemyclass(items items) : base() {     _items = items;   }    protected items getitemspurchased(){     return _items;   } } 

and then, in tests, replace new myclass new testablemyclass(myitems).

this way, actual getitemspurchased() won't called in tests, , can inject items want.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -