I am new to writing unit test cases using Fake It Easy. I could not able to figure it out that, How can we validate that method is called by some specific parameters?
Please see the example below
Main Class
//Model
public class Request
{
public string Param { get; set; }
}
//Repository
public class MyRepository : IMyReporitory
{
public string Get(Expression<Func<Request, bool>> query) { }
}
//Service
public class MyService
{
private readonly IMyReporitory _myReposotory;
public MyService(IMyReporitory myReposotory)
{
_myReposotory = myReposotory;
}
public string Search(string searchText)
{
return _myReposotory.Get(x => x.Param == searchText);
}
}
Test Class
[TestClass]
public class DashboardServiceTest
{
MyService service;
IMyRepository _fakeMyRepository;
public void Initialize()
{
_fakeMyRepository= A.Fake<IMyRepository>();
service = new MyService(_fakeMyRepository);
}
[TestMethod]
public void GetFilteredRfqs_FilterBy_RfqId()
{
var result = service.Search("abc");
A.CallTo(() => _fakeMyRepository.Get(A<Expression<Func<Request, bool>>>._)).MustHaveHappened();
}
}
In this example how can I check that _myReposotory.Get() method is called with "abc" parameter?