-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for parsing Guid and string in the same condition #200
Changes from 14 commits
eca21da
4b7d15a
cd4b420
c7d29f4
e6ddce6
9a5e5e3
02bda33
e77c116
d7d432b
2c840f8
8590347
e13c9d1
6213fd1
4d6a4d5
43765a3
10bb5bd
a9c93f2
cc90915
ea0f3bd
1290d20
53c73ac
d143a0b
dc9e24d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ namespace System.Linq.Dynamic.Core.Tests | |
{ | ||
public class DynamicExpressionParserTests | ||
{ | ||
|
||
|
||
private class MyClass | ||
{ | ||
public int Foo() | ||
|
@@ -452,5 +454,39 @@ public void ParseLambda_With_InnerStringLiteral() | |
object result = del.DynamicInvoke(String.Empty); | ||
Check.That(result).IsEqualTo(originalTrueValue); | ||
} | ||
|
||
[Fact] | ||
public void ParseLambda_With_If_Guid_Null() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better text like: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! |
||
{ | ||
var objContext = new User(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. user There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! |
||
var guidEmpty = Guid.Empty; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity, I mostly / always use real definitions for simple types. So use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! |
||
var someId = Guid.NewGuid(); | ||
var expressionText = $"iif(@0.{nameof(objContext.Id)} == null, @0.{nameof(objContext.Id)} == Guid.Parse(\"{someId}\"), {nameof(objContext.Id)}={nameof(objContext.Id)})"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For readability I would just type the expressionText string as simple as possible, so just: $"iif(@0.Id == null, @0.Id == Guid.Parse(\"{someId}\"), Id=Id)"; And actually I wonder if this is ok? $"iif(@0.Id == null, @0.Id == Guid.Parse(\"{someId}\"), Id)"; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it would not. This expression should have boolean result. So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's correct expression: |
||
|
||
var lambda = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(typeof(User), null, expressionText, objContext); | ||
var boolLambda = lambda as Expression<Func<User, bool>>; | ||
Check.That(boolLambda).IsNotEqualTo(null); | ||
|
||
var del = lambda.Compile(); | ||
object result = del.DynamicInvoke(objContext); | ||
Check.That(result).IsEqualTo(true); | ||
} | ||
|
||
[Fact] | ||
public void ParseLambda_With_If_Null_Guid() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as defined on other method also apply here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was done! |
||
{ | ||
var objContext = new User(); | ||
var guidEmpty = Guid.Empty; | ||
var someId = Guid.NewGuid(); | ||
var expressionText = $"iif(null == @0.{nameof(objContext.Id)}, @0.{nameof(objContext.Id)} == Guid.Parse(\"{someId}\"), {nameof(objContext.Id)}={nameof(objContext.Id)})"; | ||
|
||
var lambda = System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(typeof(User), null, expressionText, objContext); | ||
var boolLambda = lambda as Expression<Func<User, bool>>; | ||
Check.That(boolLambda).IsNotEqualTo(null); | ||
|
||
var del = lambda.Compile(); | ||
object result = del.DynamicInvoke(objContext); | ||
Check.That(result).IsEqualTo(true); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think that removing this code would actually break unit-tests? Or do you say that this logic was wrong from the beginning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion logic was wrong from the start.
It's like the issue #19
I've added unit test
ParseLambda_With_Guid_Equals_String
for demonstrate thatGuid
plusString
works without these lines (at least in condition part).