Possible SingleOrDefaultAsync issue?
See original GitHub issueHi Guys,
I bumped into a really strange issue when working on a project while using URF.core. I noticed that in my unit test a really simpel assert failed. But because there was a lot of custom code involved i first thought it was a mistake on my side so i skipped over it. Today I ran into the same issue again so I updated my fork of urf.core and added a simpel unit test:
[Fact]
public async Task Product_Should_Not_Be_Null_After_A_Contains_Query()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);
// Act
var products = await repository.Query().Where(p => p.ProductId == 1).SelectAsync();
// Assert
Assert.NotNull(products);
// Act
var product = await repository.Query().SingleOrDefaultAsync(s => s.ProductId == 2, new System.Threading.CancellationToken());
// Assert
Assert.NotNull(product);
}
To my suprise this unit test is failing as well! Am i making a mistake or doing something wierd?
You can clone my fork to see it failing: https://github.com/Domitnator/URF.Core
I believe there is something going wrong in the SingleOrDefaultAsync because if i would replace that line with FindAsync:
[Fact]
public async Task Product_Should_Not_Be_Null_After_A_Contains_Query()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);
// Act
var products = await repository.Query().Where(p => p.ProductId == 1).SelectAsync();
// Assert
Assert.NotNull(products);
// Act
var product = await repository.FindAsync(2);
// Assert
Assert.NotNull(product);
}
It works!
But it also works when i also request product with id 2 in the first query:
[Fact]
public async Task Product_Should_Not_Be_Null_After_A_Contains_Query()
{
// Arrange
var repository = new Repository<Product>(_fixture.Context);
// Act
var products = await repository.Query().Where(p => new List<int> { 1, 2 }.Contains(p.ProductId)).SelectAsync();
// Assert
Assert.NotNull(products);
// Act
var product = await repository.Query().SingleOrDefaultAsync(s => s.ProductId == 2, new System.Threading.CancellationToken());
// Assert
Assert.NotNull(product);
}
So i’m not quite sure if it has anything to do with the SingleOrDefaultAsync method.
Hopefully you can help me out.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
@Domitnator if you could be so kind to issue a PR on this, that would be great.
@Domitnator, yes I think a PR would be good.