I am using the ProjectTo<T>
method to get data from the DB.
names = _mapper.ProjectTo<ItemNameDto>(query).ToList();
In the unit tests I would like to mock this method to return a specific collection.
Based on the second answer to this question - I figured out I need to pass all parameters to the setup.
When I pass null to the second parameter - the setup is ok, but when I pass null
to the third one - the setup does not return the collection I want.
What value should I pass to the Expression parameter in this particular case? I really wouldn't like to leave it with It.IsAny<>
because it seems too broad to me. I would like to write a setup which reflects exactly my use case.
_mapperMock
.Setup(c => c.ProjectTo(
It.Is<IQueryable<Item>>(x => x.HaveTheSameElements(filteredItems)),
It.IsAny<object>(),
It.IsAny<Expression<Func<ItemNameDto, object>>[]>()))
.Returns(filteredItemNameDtos.AsQueryable());
This is the method signature I would like to setup.
IQueryable<TDestination> ProjectTo<TDestination>(IQueryable source, object parameters = null, params Expression<Func<TDestination, object>>[] membersToExpand);