Endless loop when using Automapper on faked IQueryable<T>
See original GitHub issueUnsure, whether this is an issue with FakeItEasy or Automapper (or even Castle Proxy).
Assuming an IQueryable<Entity>
that is mapped using Automapper into an IQueryable<EntityDto>
by means of their expression mapping extension. When the original queryable is mocked using FakeItEasy, the enumeration of the mapped queryable never returns. It hogs a CPU at 100%, so I am assuming some kind of endless loop.
public class FakeItEasyTest
{
private readonly Mapper _mapper;
private readonly IQueryable<Entity> _queryable;
public FakeItEasyTest()
{
_mapper = new Mapper(new MapperConfiguration(cfg => cfg.CreateMap<Entity, EntityDto>()));
_queryable = A.Fake<IQueryable<Entity>>();
}
[Fact]
public void CanEnumerateQueryable()
{
Assert.Empty(_queryable.ToArray());
}
[Fact]
public void CanEnumerateDataSourceQueryable()
{
IQueryable<EntityDto> mappedQueryable = _queryable.UseAsDataSource(_mapper.ConfigurationProvider).For<EntityDto>();
// never returns!
Assert.Empty(mappedQueryable.ToArray());
}
[Fact]
public void CanEnumerateProjectedQueryable()
{
// never returns!
IQueryable<EntityDto> mappedQueryable = _queryable.ProjectTo<EntityDto>(_mapper.ConfigurationProvider);
Assert.Empty(mappedQueryable.ToArray());
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
c# - AutoMapper throwing StackOverflowException when ...
The problem is an infinite loop when calling mapper on lists. Your mappings are right. You can try to empty lists before convert...
Read more >IQueryable Extensions Exception · Issue #790
The problem is commented out properties will cause an infinite loop when trying to Project. Project makes a select statement, and DON'T use...
Read more >The reasons behind why I don't use AutoMapper.
I've encountered cases when AutoMapper transforms simple thing like mapping values from object to other into a really complex problem, which ...
Read more >4 Common Mistakes with the Repository Pattern
Repositories that return IQueryable. One of the reasons we use the repository pattern is to encapsulate fat queries. These queries make it hard ......
Read more >IQueryable no supported?
Hello, Isn't possible to map an IQueriable with AutoMapper? Articles = Mapper.Map<IQueryable<Article>, IQueryable<ArticleItemViewModel>>(articleRepository.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Works like a charm, @blairconrad . Thanks, I updated the repro-repo that passes all tests now, even when there is an arbitrary interface faked that has a method returning IQueryable.
I made an attempt with a dummy factory before, but obviously I was missing something. Well, it got pretty late yesterday…
Thanks!
@marcwittke, I’m sure you’ll get your configuration working, but if you’re interested, I stole some minutes to implement a DummyFactory that you might enjoy. It seemed to do the trick for me.