(bugfix): fix possible null ref exception
This commit is contained in:
parent
f463862b7c
commit
fd799615f7
@ -10,7 +10,7 @@ public class ExpressionExtensionsTests {
|
||||
public void CombineWith_ShouldCombineTwoPredicates() {
|
||||
// Arrange
|
||||
Expression<Func<TestEntity, bool>> firstPredicate = x => x.Age > 18;
|
||||
Expression<Func<TestEntity, bool>> secondPredicate = x => x.Name.StartsWith("A");
|
||||
Expression<Func<TestEntity, bool>> secondPredicate = x => (x.Name ?? "").StartsWith("A");
|
||||
|
||||
// Act
|
||||
var combinedPredicate = firstPredicate.CombineWith(secondPredicate);
|
||||
@ -25,7 +25,7 @@ public class ExpressionExtensionsTests {
|
||||
private class TestEntity {
|
||||
public Guid Id { get; set; }
|
||||
public int Age { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,17 +4,6 @@ using MaksIT.Core.Webapi.Models;
|
||||
namespace MaksIT.Core.Tests.Webapi.Models;
|
||||
|
||||
public class PagedRequestTests {
|
||||
[Fact]
|
||||
public void BuildFilterExpression_ShouldReturnNull_WhenFilterIsEmpty() {
|
||||
// Arrange
|
||||
var request = new PagedRequest();
|
||||
|
||||
// Act
|
||||
var result = request.BuildFilterExpression<TestEntity>(null);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildFilterExpression_ShouldHandleEqualsOperator() {
|
||||
@ -131,6 +120,6 @@ public class PagedRequestTests {
|
||||
|
||||
// Helper class for testing purposes
|
||||
public class TestEntity {
|
||||
public string Name { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Age { get; set; }
|
||||
}
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
<!-- NuGet package metadata -->
|
||||
<PackageId>MaksIT.Core</PackageId>
|
||||
<Version>1.1.3</Version>
|
||||
<Version>1.1.4</Version>
|
||||
<Authors>Maksym Sadovnychyy</Authors>
|
||||
<Company>MAKS-IT</Company>
|
||||
<Product>MaksIT.Core</Product>
|
||||
|
||||
@ -91,16 +91,18 @@ namespace MaksIT.Core.Webapi.Models {
|
||||
expression = Expression.Not(expression);
|
||||
}
|
||||
|
||||
// Combine the current expression with the previous one using the correct operator
|
||||
if (combinedExpression == null) {
|
||||
combinedExpression = expression;
|
||||
}
|
||||
else if (i - 1 < operators.Count) // Ensure we don't exceed the operators list size
|
||||
{
|
||||
var operatorType = operators[i - 1];
|
||||
combinedExpression = operatorType == "&&"
|
||||
? Expression.AndAlso(combinedExpression, expression)
|
||||
: Expression.OrElse(combinedExpression, expression);
|
||||
// Only combine expressions if the new expression is not null
|
||||
if (expression != null) {
|
||||
if (combinedExpression == null) {
|
||||
combinedExpression = expression;
|
||||
}
|
||||
else if (i - 1 < operators.Count) // Ensure we don't exceed the operators list size
|
||||
{
|
||||
var operatorType = operators[i - 1];
|
||||
combinedExpression = operatorType == "&&"
|
||||
? Expression.AndAlso(combinedExpression, expression)
|
||||
: Expression.OrElse(combinedExpression, expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user