| 
5 | 5 | using System.Linq.Dynamic.Core.Tests.Helpers.Entities;  | 
6 | 6 | using System.Linq.Dynamic.Core.Tests.Helpers.Models;  | 
7 | 7 | using System.Linq.Expressions;  | 
 | 8 | +using System.Text;  | 
 | 9 | +using Docker.DotNet.Models;  | 
8 | 10 | using FluentAssertions;  | 
9 | 11 | using Xunit;  | 
10 | 12 | 
 
  | 
@@ -326,6 +328,56 @@ public void Where_Dynamic_DateTimeConstructor_Issue662()  | 
326 | 328 |         result2.Should().HaveCount(1);  | 
327 | 329 |     }  | 
328 | 330 | 
 
  | 
 | 331 | +    // #937  | 
 | 332 | +    [Theory]  | 
 | 333 | +    [InlineData("NameCalculated == \"FooFoo\"", 1)]  | 
 | 334 | +    [InlineData("\"FooFoo\" == NameCalculated", 1)]  | 
 | 335 | +    [InlineData("NameCalculated == \"x\"", 0)]  | 
 | 336 | +    [InlineData("NameCalculated != \"x\"", 2)]  | 
 | 337 | +    [InlineData("NameCalculated <> \"x\"", 2)]  | 
 | 338 | +    [InlineData("\"x\" == NameCalculated", 0)]  | 
 | 339 | +    [InlineData("\"x\" != NameCalculated", 2)]  | 
 | 340 | +    [InlineData("\"x\" <> NameCalculated", 2)]  | 
 | 341 | +    public void Where_Dynamic_CompareObjectToString_ConvertObjectToSupportComparisonIsTrue(string expression, int expectedCount)  | 
 | 342 | +    {  | 
 | 343 | +        // Arrange  | 
 | 344 | +        var config = new ParsingConfig  | 
 | 345 | +        {  | 
 | 346 | +            ConvertObjectToSupportComparison = true  | 
 | 347 | +        };  | 
 | 348 | +        var queryable = new[]  | 
 | 349 | +        {  | 
 | 350 | +            new PersonWithObject { Name = "Foo", DateOfBirth = DateTime.UtcNow.AddYears(-31) },  | 
 | 351 | +            new PersonWithObject { Name = "Bar", DateOfBirth = DateTime.UtcNow.AddYears(-1) }  | 
 | 352 | +        }.AsQueryable();  | 
 | 353 | + | 
 | 354 | +        // Act  | 
 | 355 | +        queryable.Where(config, expression).ToList().Should().HaveCount(expectedCount);  | 
 | 356 | +    }  | 
 | 357 | + | 
 | 358 | +    // #937  | 
 | 359 | +    [Theory]  | 
 | 360 | +    [InlineData("NameCalculated == \"FooFoo\"", 0)] // This is the expected behavior when ConvertObjectToSupportComparison is false because "Foo" is a string and NameCalculated is an object which is a calculated string.  | 
 | 361 | +    [InlineData("\"FooFoo\" == NameCalculated", 0)] // Also expected.  | 
 | 362 | +    [InlineData("NameCalculated == \"x\"", 0)]  | 
 | 363 | +    [InlineData("NameCalculated != \"x\"", 2)]  | 
 | 364 | +    [InlineData("NameCalculated <> \"x\"", 2)]  | 
 | 365 | +    [InlineData("\"x\" == NameCalculated", 0)]  | 
 | 366 | +    [InlineData("\"x\" != NameCalculated", 2)]  | 
 | 367 | +    [InlineData("\"x\" <> NameCalculated", 2)]  | 
 | 368 | +    public void Where_Dynamic_CompareObjectToString_ConvertObjectToSupportComparisonIsFalse(string expression, int expectedCount)  | 
 | 369 | +    {  | 
 | 370 | +        // Arrange  | 
 | 371 | +        var queryable = new[]  | 
 | 372 | +        {  | 
 | 373 | +            new PersonWithObject { Name = "Foo", DateOfBirth = DateTime.UtcNow.AddYears(-31) },  | 
 | 374 | +            new PersonWithObject { Name = "Bar", DateOfBirth = DateTime.UtcNow.AddYears(-1) }  | 
 | 375 | +        }.AsQueryable();  | 
 | 376 | + | 
 | 377 | +        // Act  | 
 | 378 | +        queryable.Where(expression).ToList().Should().HaveCount(expectedCount);  | 
 | 379 | +    }  | 
 | 380 | + | 
329 | 381 |     // #451  | 
330 | 382 |     [Theory]  | 
331 | 383 |     [InlineData("Age == 99", 0)]  | 
@@ -448,7 +500,11 @@ private class PersonWithObject  | 
448 | 500 |     {  | 
449 | 501 |         // Deliberately typing these as `object` to illustrate the issue  | 
450 | 502 |         public object? Name { get; set; }  | 
 | 503 | + | 
 | 504 | +        public object? NameCalculated => Name + Encoding.ASCII.GetString(Convert.FromBase64String("Rm9v")); // "...Foo";  | 
 | 505 | + | 
451 | 506 |         public object Age => Convert.ToInt32(Math.Floor((DateTime.Today.Month - DateOfBirth.Month + 12 * DateTime.Today.Year - 12 * DateOfBirth.Year) / 12d));  | 
 | 507 | + | 
452 | 508 |         public DateTime DateOfBirth { get; set; }  | 
453 | 509 |     }  | 
454 | 510 | 
 
  | 
 | 
0 commit comments