简体   繁体   中英

MSTest Test Method to check for collection

I am trying to write a test method to check if the List is being obtained properly.I am very new to MSTest and Rhino Mocks.Till now I have written the below code.

   var mockRepository = new MockRepository();
   var menuRepository = mockRepository.DynamicMock<IMenuManager>();
   var expected = new List<Menu>();

  //Need to set expected value  

   var actual = menuRepository.GetMenus();
   Assert.AreEqual(expected, actual);

IMenuManager is as below

 public interface IMenuManager
 {
       List<Menu> GetMenus();
 }

Test method itself:

var myMenuList = new List<Menu>(); var menuManagerMock = MockRepository.GenerateMock<IMenuManager>(); 
menuManagerMock.Stub(c => c.GetMenus()).Return(myMenuList); 
actual = menuManagerMock.GetMenus(); 

How can I set the expected value in this scenario. Please suggest.GetMenus() reads an XML file and builds a collection.

Thanks

var myMenuList = new List<Menu>();
// setup the list from XML
var menuManagerMock = MockRepository.GenerateMock<IMenuManager>();
menuManagerMock.Stub(c => c.GetMenus()).Return(myMenuList);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM