Combining functions will crash the application without any error. Even surrounding with try-catch will not help.
Details
In an application, I have the ability to specify filters for data being processed. It is working fine when I have just one filter, but when there are multiple filters combined with ||
operator, the application (asp.net core 3.1) just stop debugging without any exceptions thrown.
Example test that will not pass, not fail, but just crash without any exception:
[Fact]
public void ShouldFilterWithFilterGroup()
{
// Arrange
var filters = new List<Func<object, bool>>();
filters.Add(x => true);
filters.Add(x => true);
Func<object, bool> filterFunction = null;
foreach (var item in filters)
{
if (filterFunction == null)
{
filterFunction = x => item(x);
}
else
{
filterFunction = x => filterFunction(x) || item(x);
}
}
// Act
var filterResult = filterFunction(null); // Test just stops here without throwing any exception
// Assert
Assert.True(filterResult);
}