I'm fairly new to TypeMock and have found it pretty easy to get going but have gotten stuck.
I'm trying to write tests for derived service objects that use lambda expressions. I want to verify the method is called with a specific lambda expression and returns the value.
I can't figure out how to test that a specific lambda expression is used:
item => item.Name == "MyBusinessUnit"
Any ideas?
Test:
[TestMethod]
[VerifyMocks]
public void Test()
{
BusinessUnit myBusinessUnit = new BusinessUnit{Name="MyBusiness"};
BusinessUnitService businessUnitService = new BusinessUnitService();
Isolate.WhenCalled(() => businessUnitService.GetObject(null)).WillReturn(myBusinessUnit);
businessUnitService.GetBusinessUnitByName("MyBusiness");
Isolate.Verify.WasCalledWithExactArguments(() => businessUnitService.GetObject(item => item.Name == "MyBusinessUnit"));
}
The method under test:
public BusinessUnit GetBusinessUnitByName(string businessUnitName)
{
return GetObject(item => item.Name == businessUnitName);
}