From 9d4e55a0de4150b0fcb6a41ccf090136bd9aa7e1 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sat, 15 Jun 2024 19:08:56 +0200 Subject: [PATCH 01/22] Use Testcontainers.MsSql --- .../EntityFramework.DynamicLinq.Tests.csproj | 2 +- .../DefaultQueryableAnalyzerTests.cs | 200 ++++++++---------- .../EntitiesTests.DatabaseFixture.cs | 20 ++ .../EntitiesTests.GroupBy.cs | 2 +- .../EntitiesTests.In.cs | 4 +- .../EntitiesTests.Include.cs | 2 +- .../EntitiesTests.Page.cs | 83 ++++---- .../EntitiesTests.Select.cs | 4 +- .../EntitiesTests.SingleOrDefaultAsync.cs | 67 +++--- .../EntitiesTests.cs | 103 +++++---- 10 files changed, 235 insertions(+), 252 deletions(-) create mode 100644 test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs diff --git a/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj b/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj index 46c999ed..eff60236 100644 --- a/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj +++ b/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj @@ -40,13 +40,13 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs index 4673eb76..800074b4 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs @@ -4,125 +4,111 @@ using QueryInterceptor.Core; using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; +using MongoDB.Driver.Core.Misc; + #if EFCORE using Microsoft.EntityFrameworkCore; #else using System.Data.Entity; #endif -namespace System.Linq.Dynamic.Core.Tests -{ - public class DefaultQueryableAnalyzerTests : IDisposable - { - private readonly IQueryableAnalyzer _queryableAnalyzer; +namespace System.Linq.Dynamic.Core.Tests; - BlogContext _context; +public class DefaultQueryableAnalyzerTests : IClassFixture +{ + private readonly IQueryableAnalyzer _queryableAnalyzer; - // static readonly Random Rnd = new Random(1); + private readonly BlogContext _context; - public DefaultQueryableAnalyzerTests() - { + public DefaultQueryableAnalyzerTests(EntitiesTestsDatabaseFixture fixture) + { #if EFCORE - var builder = new DbContextOptionsBuilder(); - // builder.UseSqlite($"Filename=System.Linq.Dynamic.Core.{Guid.NewGuid()}.db"); - builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); + var builder = new DbContextOptionsBuilder(); + builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); - _context = new BlogContext(builder.Options); - _context.Database.EnsureCreated(); + _context = new BlogContext(builder.Options); + _context.Database.EnsureCreated(); #else - _context = new BlogContext($"data source=(LocalDB)\\MSSQLLocalDB;attachdbfilename=|DataDirectory|\\System.Linq.Dynamic.Core.{Guid.NewGuid()}.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"); - _context.Database.CreateIfNotExists(); + _context = new BlogContext(fixture.ConnectionString); #endif - _queryableAnalyzer = new DefaultQueryableAnalyzer(); - } + _queryableAnalyzer = new DefaultQueryableAnalyzer(); + } - public void Dispose() - { -#if EFCORE - _context.Database.EnsureDeleted(); -#else - _context.Database.Delete(); -#endif - _context.Dispose(); - _context = null; - } - - [Fact] - public void DefaultQueryableAnalyzer_SupportsLinqToObjects_ObjectQuery() - { - // Assign - var query = new[] { 1, 2 }.AsQueryable().Where(x => x > 0); - - // Act - bool result = _queryableAnalyzer.SupportsLinqToObjects(query); - - // Assert - Check.That(result).IsTrue(); - } - - [Fact] - public void DefaultQueryableAnalyzer_SupportsLinqToObjects_ObjectQuery_With_QueryInterceptor() - { - // Assign - var query = new[] { 1, 2 }.AsQueryable().Where(x => x > 0).InterceptWith(new PropertyVisitor()); - - // Act - bool result = _queryableAnalyzer.SupportsLinqToObjects(query); - - // Assert - Check.That(result).IsTrue(); - } - - [Fact] - public void DefaultQueryableAnalyzer_SupportsLinqToObjects_ObjectQuery_With_ExpandableQuery() - { - // Assign - var query = new[] { 1, 2 }.AsQueryable().Where(x => x > 0).AsExpandable(); - - // Act - bool result = _queryableAnalyzer.SupportsLinqToObjects(query); - - // Assert - Check.That(result).IsTrue(); - } - - [Fact] - public void DefaultQueryableAnalyzer_SupportsLinqToObjects_EntitiesQuery() - { - // Assign - var query = _context.Blogs.Where(b => b.BlogId > 0); - - // Act - bool result = _queryableAnalyzer.SupportsLinqToObjects(query); - - // Assert - Check.That(result).IsFalse(); - } - - [Fact] - public void DefaultQueryableAnalyzer_SupportsLinqToObjects_EntitiesQuery_With_QueryInterceptor() - { - // Assign - var query = _context.Blogs.Where(b => b.BlogId > 0).InterceptWith(new PropertyVisitor()); - - // Act - bool result = _queryableAnalyzer.SupportsLinqToObjects(query); - - // Assert - Check.That(result).IsFalse(); - } - - [Fact] - public void DefaultQueryableAnalyzer_SupportsLinqToObjects_EntitiesQuery_With_ExpandableQuery() - { - // Assign - var query = _context.Blogs.Where(b => b.BlogId > 0).AsExpandable(); - - // Act - bool result = _queryableAnalyzer.SupportsLinqToObjects(query); - - // Assert - Check.That(result).IsFalse(); - } + [Fact] + public void DefaultQueryableAnalyzer_SupportsLinqToObjects_ObjectQuery() + { + // Assign + var query = new[] { 1, 2 }.AsQueryable().Where(x => x > 0); + + // Act + bool result = _queryableAnalyzer.SupportsLinqToObjects(query); + + // Assert + Check.That(result).IsTrue(); + } + + [Fact] + public void DefaultQueryableAnalyzer_SupportsLinqToObjects_ObjectQuery_With_QueryInterceptor() + { + // Assign + var query = new[] { 1, 2 }.AsQueryable().Where(x => x > 0).InterceptWith(new PropertyVisitor()); + + // Act + bool result = _queryableAnalyzer.SupportsLinqToObjects(query); + + // Assert + Check.That(result).IsTrue(); + } + + [Fact] + public void DefaultQueryableAnalyzer_SupportsLinqToObjects_ObjectQuery_With_ExpandableQuery() + { + // Assign + var query = new[] { 1, 2 }.AsQueryable().Where(x => x > 0).AsExpandable(); + + // Act + bool result = _queryableAnalyzer.SupportsLinqToObjects(query); + + // Assert + Check.That(result).IsTrue(); + } + + [Fact] + public void DefaultQueryableAnalyzer_SupportsLinqToObjects_EntitiesQuery() + { + // Assign + var query = _context.Blogs.Where(b => b.BlogId > 0); + + // Act + bool result = _queryableAnalyzer.SupportsLinqToObjects(query); + + // Assert + Check.That(result).IsFalse(); + } + + [Fact] + public void DefaultQueryableAnalyzer_SupportsLinqToObjects_EntitiesQuery_With_QueryInterceptor() + { + // Assign + var query = _context.Blogs.Where(b => b.BlogId > 0).InterceptWith(new PropertyVisitor()); + + // Act + bool result = _queryableAnalyzer.SupportsLinqToObjects(query); + + // Assert + Check.That(result).IsFalse(); + } + + [Fact] + public void DefaultQueryableAnalyzer_SupportsLinqToObjects_EntitiesQuery_With_ExpandableQuery() + { + // Assign + var query = _context.Blogs.Where(b => b.BlogId > 0).AsExpandable(); + + // Act + bool result = _queryableAnalyzer.SupportsLinqToObjects(query); + + // Assert + Check.That(result).IsFalse(); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs new file mode 100644 index 00000000..409d4f66 --- /dev/null +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs @@ -0,0 +1,20 @@ +using System.Threading.Tasks; +using Xunit; + +namespace System.Linq.Dynamic.Core.Tests; + +/// +/// https://blog.jetbrains.com/dotnet/2023/10/24/how-to-use-testcontainers-with-dotnet-unit-tests/ +/// +public class EntitiesTestsDatabaseFixture : IAsyncLifetime +{ + private readonly Testcontainers.MsSql.MsSqlContainer _msSqlContainer = new Testcontainers.MsSql.MsSqlBuilder().Build(); + + public string ConnectionString => _msSqlContainer.GetConnectionString(); + + public string ContainerId => $"{_msSqlContainer.Id}"; + + public Task InitializeAsync() => _msSqlContainer.StartAsync(); + + public Task DisposeAsync() => _msSqlContainer.DisposeAsync().AsTask(); +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs index 15df4c60..2a6aa697 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs @@ -9,7 +9,7 @@ namespace System.Linq.Dynamic.Core.Tests { - public partial class EntitiesTests : IDisposable + public partial class EntitiesTests { [Fact] public void Entities_GroupBy_SingleKey() diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs index 99728a90..d3138b1a 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs @@ -8,7 +8,7 @@ namespace System.Linq.Dynamic.Core.Tests { - public partial class EntitiesTests : IDisposable + public partial class EntitiesTests { /// /// Test for https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/524 @@ -33,4 +33,4 @@ public void Entities_Where_In_And() Assert.Equal(expected, test); } } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs index 2e45981d..1449d227 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs @@ -9,7 +9,7 @@ namespace System.Linq.Dynamic.Core.Tests { - public partial class EntitiesTests : IDisposable + public partial class EntitiesTests { /// /// Test for https://github.com/StefH/System.Linq.Dynamic.Core/issues/28 diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs index 3a8ab962..d7ebcbbd 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs @@ -1,54 +1,51 @@ using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Page() { - [Fact] - public void Entities_Page() - { - //Arrange - const int total = 33; - const int page = 2; - const int pageSize = 10; - PopulateTestData(total, 0); + //Arrange + const int total = 25; + const int page = 2; + const int pageSize = 10; - //Act - var expected = _context.Blogs.OrderBy(b => b.BlogId).Page(page, pageSize).ToArray(); - IOrderedQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId"); - bool any = queryable.Any(); - var count = queryable.Count(); - var result = queryable.Page(page, pageSize).ToDynamicArray(); + //Act + var expected = _context.Blogs.OrderBy(b => b.BlogId).Page(page, pageSize).ToArray(); + IOrderedQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId"); + bool any = queryable.Any(); + var count = queryable.Count(); + var result = queryable.Page(page, pageSize).ToDynamicArray(); - //Assert - Assert.True(any); - Assert.Equal(total, count); - Assert.Equal(expected, result); - } + //Assert + Assert.True(any); + Assert.Equal(total, count); + Assert.Equal(expected, result); + } - [Fact] - public void Entities_PageResult() - { - //Arrange - const int total = 44; - const int page = 2; - const int pageSize = 10; - PopulateTestData(total, 0); + [Fact] + public void Entities_PageResult() + { + //Arrange + const int total = 25; + const int page = 2; + const int pageSize = 10; - //Act - var expectedResult = _context.Blogs.OrderBy(b => b.BlogId).PageResult(page, pageSize).Queryable.ToArray(); - IQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId"); - var count = queryable.Count(); - var result = queryable.PageResult(page, pageSize); + //Act + var expectedResult = _context.Blogs.OrderBy(b => b.BlogId).PageResult(page, pageSize).Queryable.ToArray(); + IQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId"); + var count = queryable.Count(); + var result = queryable.PageResult(page, pageSize); - //Assert - Assert.Equal(total, count); - Assert.Equal(page, result.CurrentPage); - Assert.Equal(pageSize, result.PageSize); - Assert.Equal(total, result.RowCount); - Assert.Equal(5, result.PageCount); - Assert.Equal(expectedResult, result.Queryable.ToDynamicArray()); - } + //Assert + Assert.Equal(total, count); + Assert.Equal(page, result.CurrentPage); + Assert.Equal(pageSize, result.PageSize); + Assert.Equal(total, result.RowCount); + Assert.Equal(5, result.PageCount); + Assert.Equal(expectedResult, result.Queryable.ToDynamicArray()); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs index 6ae1a84b..b1a4b825 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs @@ -12,12 +12,12 @@ namespace System.Linq.Dynamic.Core.Tests { - public partial class EntitiesTests : IDisposable + public partial class EntitiesTests { [Fact] public void Entities_Select_SingleColumn_NullCoalescing() { - //A rrange + // Arrange var blog1 = new Blog { BlogId = 1000, Name = "Blog1", Created = DateTime.Now, NullableInt = null }; var blog2 = new Blog { BlogId = 2000, Name = "Blog2", Created = DateTime.Now, NullableInt = 5 }; _context.Blogs.Add(blog1); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SingleOrDefaultAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SingleOrDefaultAsync.cs index 0ee84918..c3bb198a 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SingleOrDefaultAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SingleOrDefaultAsync.cs @@ -6,56 +6,39 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_SingleOrDefaultAsync() { - [Fact] - public async Task Entities_SingleOrDefaultAsync() - { - //Arrange - PopulateTestData(1, 0); - - var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); - var expected1 = await expectedQueryable1.SingleOrDefaultAsync(); - - var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999); - var expected2 = await expectedQueryable2.SingleOrDefaultAsync(); + // Arrange + var expectedQueryable1 = _context.Blogs.Where(b => b.Name == "SingleBlog"); + var expected1 = await expectedQueryable1.SingleOrDefaultAsync(); - //Act - IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); - var result1 = await queryable1.SingleOrDefaultAsync(); + // Act + IQueryable queryable1 = _context.Blogs.Where("Name == \"SingleBlog\""); + var result1 = await queryable1.SingleOrDefaultAsync(); - IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999"); - var result2 = await queryable2.SingleOrDefaultAsync(); - - //Assert - Assert.Equal(expected1, result1); - Assert.Null(expected2); - Assert.Null(result2); - } + // Assert + Assert.Equal(expected1, result1); + } - [Fact] - public async Task Entities_SingleOrDefaultAsync_Predicate() - { - //Arrange - PopulateTestData(1, 0); + [Fact] + public async Task Entities_SingleOrDefaultAsync_Predicate() + { + // Arrange #if EFCORE - var expected1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(_context.Blogs, b => b.BlogId > 0); - var expected2 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(_context.Blogs, b => b.BlogId > 9999); + var expected1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync(_context.Blogs, b => b.Name == "SingleBlog"); #else - var expected1 = await System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync(_context.Blogs, b => b.BlogId > 0); - var expected2 = await System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync(_context.Blogs, b => b.BlogId > 9999); + var expected1 = await System.Data.Entity.QueryableExtensions.SingleOrDefaultAsync(_context.Blogs, b => b.Name == "SingleBlog"); #endif - //Act - var result1 = await _context.Blogs.AsQueryable().SingleOrDefaultAsync("it.BlogId > 0"); - var result2 = await _context.Blogs.AsQueryable().SingleOrDefaultAsync("it.BlogId > 9999"); + // Act + var result1 = await _context.Blogs.AsQueryable().SingleOrDefaultAsync("it.Name == \"SingleBlog\""); - //Assert - Assert.Equal(expected1, result1); - Assert.Null(expected2); - Assert.Null(result2); - } + // Assert + Assert.Equal(expected1, result1); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index 225b40dd..0abea8b9 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -1,77 +1,74 @@ using System.Collections; using System.Linq.Dynamic.Core.Tests.Helpers.Entities; +using System.Threading.Tasks; +using Xunit; + #if EFCORE using Microsoft.EntityFrameworkCore; #else using System.Data.Entity; #endif -using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests : IClassFixture { - public partial class EntitiesTests : IDisposable - { - BlogContext _context; + private static readonly Random Rnd = new Random(1); - static readonly Random Rnd = new Random(1); + private readonly BlogContext _context; - public EntitiesTests() - { + public EntitiesTests(EntitiesTestsDatabaseFixture fixture) + { #if EFCORE - var builder = new DbContextOptionsBuilder(); - // builder.UseSqlite($"Filename=System.Linq.Dynamic.Core.{Guid.NewGuid()}.db"); - builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); - //builder.UseSqlServer($"Server=(localdb)\\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=.\\System.Linq.Dynamic.Core.{Guid.NewGuid()}.mdf;"); - - _context = new BlogContext(builder.Options); - //_context.Database.EnsureDeleted(); - _context.Database.EnsureCreated(); + var builder = new DbContextOptionsBuilder(); + builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); + + _context = new BlogContext(builder.Options); + + // _context.Database.EnsureCreated(); #else - //_context = new BlogContext(@"data source=.\EntityFramework.DynamicLinq.sqlite"); - //_context = new BlogContext($"Server=(localdb)\\MSSQLLocalDB;Integrated Security=true;AttachDbFileName=.\\System.Linq.Dynamic.Core.{Guid.NewGuid()}.mdf;"); - //_context = new BlogContext($"Filename=System.Linq.Dynamic.Core.{Guid.NewGuid()}.sqlitedb"); - _context = new BlogContext($"data source=(LocalDB)\\MSSQLLocalDB;attachdbfilename=|DataDirectory|\\System.Linq.Dynamic.Core.{Guid.NewGuid()}.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"); - //_context.Database.Delete(); - //_context.Database.CreateIfNotExists(); + _context = new BlogContext(fixture.ConnectionString); #endif - } + InternalPopulateTestData(); + } - // Use TestCleanup to run code after each test has run - public void Dispose() - { -#if EFCORE - _context.Database.EnsureDeleted(); -#else - _context.Database.Delete(); -#endif - _context.Dispose(); - _context = null; - } + private void PopulateTestData(int blogCount = 25, int postCount = 10) + { + // Dummy method to make the code compile + } - private void PopulateTestData(int blogCount = 25, int postCount = 10) + private void InternalPopulateTestData() + { + for (int i = 0; i < 25; i++) { - for (int i = 0; i < blogCount; i++) - { - var blog = new Blog { X = i.ToString(), Name = "Blog" + (i + 1), BlogId = 1000 + i, Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) }; + var blog = new Blog { X = i.ToString(), Name = "Blog" + (i + 1), BlogId = 1000 + i, Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) }; - _context.Blogs.Add(blog); + _context.Blogs.Add(blog); - for (int j = 0; j < postCount; j++) + for (int j = 0; j < 10; j++) + { + var post = new Post { - var post = new Post - { - Blog = blog, - Title = $"Blog {i + 1} - Post {j + 1}", - Content = "My Content", - PostDate = DateTime.Today.AddDays(-Rnd.Next(0, 100)).AddSeconds(Rnd.Next(0, 30000)), - NumberOfReads = Rnd.Next(0, 5000) - }; + Blog = blog, + Title = $"Blog {i + 1} - Post {j + 1}", + Content = "My Content", + PostDate = DateTime.Today.AddDays(-Rnd.Next(0, 100)).AddSeconds(Rnd.Next(0, 30000)), + NumberOfReads = Rnd.Next(0, 5000) + }; - _context.Posts.Add(post); - } + _context.Posts.Add(post); } - - _context.SaveChanges(); } + + var singleBlog = new Blog + { + X = Guid.NewGuid().ToString(), + Name = "SingleBlog", + BlogId = 12345678, + Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) + }; + _context.Blogs.Add(singleBlog); + + _context.SaveChanges(); } -} +} \ No newline at end of file From a493305949a0052661564d2f9610fec839958bcd Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 22:15:39 +0200 Subject: [PATCH 02/22] x --- .github/workflows/ci.yml | 26 +- .../DefaultQueryableAnalyzerTests.cs | 3 +- .../EntitiesTests.Count.cs | 33 +-- .../EntitiesTests.CountAsync.cs | 35 ++- .../EntitiesTests.DatabaseFixture.cs | 3 +- .../EntitiesTests.FirstOrDefault.cs | 28 +-- .../EntitiesTests.FirstOrDefaultAsync.cs | 68 ++---- .../EntitiesTests.FormattableString.cs | 216 +++++++--------- .../EntitiesTests.In.cs | 40 ++- .../EntitiesTests.LongCount.cs | 36 ++- .../EntitiesTests.LongCountAsync.cs | 37 ++- .../EntitiesTests.Page.cs | 18 +- .../EntitiesTests.Select.cs | 230 +++++++++--------- .../EntitiesTests.cs | 22 +- .../ExpressionTests.cs | 2 +- .../Helpers/Entities/Blog.cs | 31 ++- .../Helpers/Entities/Post.cs | 30 ++- .../ExpressionParserTests.MemberAccess.cs | 2 +- .../Parser/ExpressionParserTests.cs | 10 +- .../QueryableTests.Contains.cs | 2 +- .../QueryableTests.Select.cs | 2 +- .../System.Linq.Dynamic.Core.Tests.csproj | 33 +-- .../TestHelpers/ExpressionString.cs | 2 +- 23 files changed, 409 insertions(+), 500 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c00b9b2d..e961d982 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: [push] jobs: build: - runs-on: windows-2022 + runs-on: ubuntu env: IsRunningOnGitHubActions: 'true' @@ -12,12 +12,12 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-dotnet@v3 - with: - dotnet-version: | - 6.0.x - 7.0.x - 8.0.x + # - uses: actions/setup-dotnet@v3 + # with: + # dotnet-version: | + # 6.0.x + # 7.0.x + # 8.0.x - name: Build Projects run: | @@ -25,20 +25,16 @@ jobs: - name: Run Tests net8.0 run: | - dotnet build ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci --no-build + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci - name: Run Tests net7.0 run: | - dotnet build ./test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj -c Release -p:buildType=azure-pipelines-ci - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj -c Release -p:buildType=azure-pipelines-ci --no-build + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj -c Release -p:buildType=azure-pipelines-ci - name: Run Tests net6.0 run: | - dotnet build ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci --no-build + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci - name: Run Tests net452 run: | - dotnet build ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -f net452 -p:buildType=azure-pipelines-ci - dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -f net452 -p:buildType=azure-pipelines-ci --no-build + dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -f net452 -p:buildType=azure-pipelines-ci diff --git a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs index 800074b4..718a6cdf 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs @@ -4,7 +4,6 @@ using QueryInterceptor.Core; using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; -using MongoDB.Driver.Core.Misc; #if EFCORE using Microsoft.EntityFrameworkCore; @@ -24,7 +23,7 @@ public DefaultQueryableAnalyzerTests(EntitiesTestsDatabaseFixture fixture) { #if EFCORE var builder = new DbContextOptionsBuilder(); - builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); + builder.UseSqlServer(fixture.ConnectionString); _context = new BlogContext(builder.Options); _context.Database.EnsureCreated(); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs index f8a817ad..6f7b8dd2 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs @@ -1,28 +1,21 @@ using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Count_Predicate() { - [Fact] - public void Entities_Count_Predicate() - { - const string search = "a"; - - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); - - //Act - int expected = _context.Blogs.Count(b => b.Name.Contains(search)); - int result = _context.Blogs.Count("Name.Contains(@0)", search); + // Arrange + const string search = "a"; + + // Act + int expected = _context.Blogs.Count(b => b.Name.Contains(search)); + int result = _context.Blogs.Count("Name.Contains(@0)", search); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs index 1d055b5f..db6e8f0e 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.CountAsync.cs @@ -10,35 +10,28 @@ using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_CountAsync_Predicate_Args() { - [Fact] - public async Task Entities_CountAsync_Predicate_Args() - { - const string search = "a"; - - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); + // Arrange + const string search = "a"; - Expression> predicate = b => b.Name.Contains(search); + Expression> predicate = b => b.Name.Contains(search); #if EFCORE - var expected = await EntityFrameworkQueryableExtensions.CountAsync(_context.Blogs, predicate); + var expected = await EntityFrameworkQueryableExtensions.CountAsync(_context.Blogs, predicate); #else - var expected = await QueryableExtensions.CountAsync(_context.Blogs, predicate); + var expected = await QueryableExtensions.CountAsync(_context.Blogs, predicate); #endif - //Act - int result = await (_context.Blogs as IQueryable).CountAsync("Name.Contains(@0)", search); + //Act + int result = await (_context.Blogs as IQueryable).CountAsync("Name.Contains(@0)", search); - //Assert - Assert.Equal(expected, result); - } + //Assert + Assert.Equal(expected, result); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs index 409d4f66..d39fbcad 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using Testcontainers.MsSql; using Xunit; namespace System.Linq.Dynamic.Core.Tests; @@ -8,7 +9,7 @@ namespace System.Linq.Dynamic.Core.Tests; /// public class EntitiesTestsDatabaseFixture : IAsyncLifetime { - private readonly Testcontainers.MsSql.MsSqlContainer _msSqlContainer = new Testcontainers.MsSql.MsSqlBuilder().Build(); + private readonly MsSqlContainer _msSqlContainer = new MsSqlBuilder().Build(); public string ConnectionString => _msSqlContainer.GetConnectionString(); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefault.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefault.cs index 9724579b..ad4cd7e5 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefault.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefault.cs @@ -6,26 +6,18 @@ #endif using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_FirstOrDefault_Dynamic() { - [Fact] - public void Entities_FirstOrDefault_Dynamic() - { - //Arrange - PopulateTestData(); - - //remove all posts from first record (to allow Defaults case to validate) - _context.Posts.RemoveRange(_context.Blogs.OrderBy(x => x.BlogId).First().Posts); - _context.SaveChanges(); - - //Act - var firstExpected = _context.Blogs.OrderBy(x => x.Posts.OrderBy(y => y.PostDate).FirstOrDefault().PostDate).Select(x => x.BlogId); - var firstTest = _context.Blogs.OrderBy("Posts.OrderBy(PostDate).FirstOrDefault().PostDate").Select("BlogId"); + // Act + var firstExpected = _context.Blogs.OrderBy(x => x.Posts.OrderBy(y => y.PostDate).FirstOrDefault().PostDate).Select(x => x.BlogId); + var firstTest = _context.Blogs.OrderBy("Posts.OrderBy(PostDate).FirstOrDefault().PostDate").Select("BlogId"); - //Assert - Assert.Equal(firstExpected.ToArray(), firstTest.ToArray()); - } + // Assert + Assert.Equal(firstExpected.ToArray(), firstTest.ToArray()); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefaultAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefaultAsync.cs index 64e2d8b7..358445a0 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefaultAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstOrDefaultAsync.cs @@ -6,56 +6,42 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_FirstOrDefaultAsync() { - [Fact] - public async Task Entities_FirstOrDefaultAsync() - { - //Arrange - PopulateTestData(1, 0); - - var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); - var expected1 = await expectedQueryable1.FirstOrDefaultAsync(); - - var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999); - var expected2 = await expectedQueryable2.FirstOrDefaultAsync(); + // Arrange + var expectedQueryable1 = _context.Blogs.Where(b => b.Name == "SingleBlog"); + var expected1 = await expectedQueryable1.FirstOrDefaultAsync(); - //Act - IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); - var result1 = await queryable1.FirstOrDefaultAsync(); + // Act + var result1 = await _context.Blogs.Where("Name == \"SingleBlog\"").FirstOrDefaultAsync(); + var result2 = await _context.Blogs.Where("Name == \"NotFound\"").FirstOrDefaultAsync(); - IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999"); - var result2 = await queryable2.FirstOrDefaultAsync(); - - //Assert - Assert.Equal(expected1, result1); - Assert.Null(expected2); - Assert.Null(result2); - } + // Assert + Assert.Equal(expected1, result1); + Assert.Null(result2); + } - [Fact] - public async Task Entities_FirstOrDefaultAsync_Predicate() - { - //Arrange - PopulateTestData(1, 0); + [Fact] + public async Task Entities_FirstOrDefaultAsync_Predicate() + { + // Arrange #if EFCORE - var expected1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(_context.Blogs, b => b.BlogId > 0); - var expected2 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(_context.Blogs, b => b.BlogId > 9999); + var expected1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync(_context.Blogs, b => b.Name == "SingleBlog"); #else - var expected1 = await System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(_context.Blogs, b => b.BlogId > 0); - var expected2 = await System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(_context.Blogs, b => b.BlogId > 9999); + var expected1 = await System.Data.Entity.QueryableExtensions.FirstOrDefaultAsync(_context.Blogs, b => b.Name == "SingleBlog"); #endif - //Act - var result1 = await _context.Blogs.AsQueryable().FirstOrDefaultAsync("it.BlogId > 0"); - var result2 = await _context.Blogs.AsQueryable().FirstOrDefaultAsync("it.BlogId > 9999"); + // Act + var result1 = await _context.Blogs.AsQueryable().FirstOrDefaultAsync("Name == \"SingleBlog\""); + var result2 = await _context.Blogs.AsQueryable().FirstOrDefaultAsync("Name == \"NotFound\""); - //Assert - Assert.Equal(expected1, result1); - Assert.Null(expected2); - Assert.Null(result2); - } + // Assert + Assert.Equal(expected1, result1); + Assert.Null(result2); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs index 9488dae5..b18e560c 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs @@ -10,150 +10,120 @@ using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using System.Linq.Expressions; -namespace System.Linq.Dynamic.Core.Tests -{ +namespace System.Linq.Dynamic.Core.Tests; #if EFCORE || (NET46_OR_GREATER || NET5_0_OR_GREATER || NETCOREAPP2_1_OR_GREATER || NETSTANDARD1_3_OR_GREATER || UAP10_0) - public partial class EntitiesTests +public partial class EntitiesTests +{ + [Fact] + public void Entities_All_FS() { - [Fact] - public void Entities_All_FS() - { - //Arrange - PopulateTestData(1, 0); - int value = 2000; - var expected = _context.Blogs.All(b => b.BlogId > value); - - //Act - var actual = _context.Blogs.AllInterpolated($"BlogId > {value}"); - - //Assert - Assert.Equal(expected, actual); - } - - [Fact] - public async Task Entities_AllAsync_FS() - { - //Arrange - PopulateTestData(1, 0); - int value = 2000; - var expected = await _context.Blogs.AllAsync(b => b.BlogId > value); - - //Act - var actual = await _context.Blogs.AllInterpolatedAsync($"BlogId > {value}"); - - //Assert - Assert.Equal(expected, actual); - } - - [Fact] - public void Entities_Count_Predicate_FS() - { - const string search = "a"; - - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); - - //Act - int expected = _context.Blogs.Count(b => b.Name.Contains(search)); - int result = _context.Blogs.CountInterpolated($"Name.Contains({search})"); - - //Assert - Assert.Equal(expected, result); - } - - [Fact] - public async Task Entities_CountAsync_Predicate_Args_FS() - { - const string search = "a"; - - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); - - Expression> predicate = b => b.Name.Contains(search); + //Arrange + PopulateTestData(1, 0); + int value = 2000; + var expected = _context.Blogs.All(b => b.BlogId > value); -#if EFCORE - var expected = await EntityFrameworkQueryableExtensions.CountAsync(_context.Blogs, predicate); -#else - var expected = await QueryableExtensions.CountAsync(_context.Blogs, predicate); -#endif + //Act + var actual = _context.Blogs.AllInterpolated($"BlogId > {value}"); - //Act - int result = await (_context.Blogs as IQueryable).CountInterpolatedAsync($"Name.Contains({search})"); + //Assert + Assert.Equal(expected, actual); + } - //Assert - Assert.Equal(expected, result); - } + [Fact] + public async Task Entities_AllAsync_FS() + { + //Arrange + PopulateTestData(1, 0); + int value = 2000; + var expected = await _context.Blogs.AllAsync(b => b.BlogId > value); - [Fact] - public void Entities_LongCount_Predicate_FS() - { - const string search = "a"; + //Act + var actual = await _context.Blogs.AllInterpolatedAsync($"BlogId > {value}"); - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); + //Assert + Assert.Equal(expected, actual); + } - //Act - long expected = _context.Blogs.LongCount(b => b.Name.Contains(search)); - long result = _context.Blogs.LongCountInterpolated($"Name.Contains({search})"); + [Fact] + public void Entities_Count_Predicate_FS() + { + // Arrange + const string search = "a"; - //Assert - Assert.Equal(expected, result); - } + // Act + int expected = _context.Blogs.Count(b => b.Name.Contains(search)); + int result = _context.Blogs.CountInterpolated($"Name.Contains({search})"); - [Fact] - public async Task Entities_LongCountAsync_Predicate_Args_FS() - { - const string search = "a"; + // Assert + Assert.Equal(expected, result); + } - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); + [Fact] + public async Task Entities_CountAsync_Predicate_Args_FS() + { + // Arrange + const string search = "a"; - Expression> predicate = b => b.Name.Contains(search); + Expression> predicate = b => b.Name.Contains(search); #if EFCORE - var expected = await EntityFrameworkQueryableExtensions.LongCountAsync(_context.Blogs, predicate); + var expected = await EntityFrameworkQueryableExtensions.CountAsync(_context.Blogs, predicate); #else - var expected = await QueryableExtensions.LongCountAsync(_context.Blogs, predicate); + var expected = await QueryableExtensions.CountAsync(_context.Blogs, predicate); #endif - //Act - long result = (_context.Blogs as IQueryable).LongCountInterpolated($"Name.Contains({search})"); + // Act + int result = await (_context.Blogs as IQueryable).CountInterpolatedAsync($"Name.Contains({search})"); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); + } - [Fact(Skip = "not supported")] - public void Entities_TakeWhile_FS() - { - //Arrange - const int total = 33; - PopulateTestData(total, 0); + [Fact] + public void Entities_LongCount_Predicate_FS() + { + // Arrange + const string search = "a"; - //Act - int value = 5; - var expected = _context.Blogs.OrderBy(b => b.BlogId).TakeWhile(b => b.BlogId > value).ToArray(); - var result = _context.Blogs.OrderByInterpolated($"BlogId").TakeWhileInterpolated($"b.BlogId > {value}").ToDynamicArray(); + // Act + long expected = _context.Blogs.LongCount(b => b.Name.Contains(search)); + long result = _context.Blogs.LongCountInterpolated($"Name.Contains({search})"); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); } + + [Fact] + public async Task Entities_LongCountAsync_Predicate_Args_FS() + { + // Arrange + const string search = "a"; + + Expression> predicate = b => b.Name.Contains(search); + +#if EFCORE + var expected = await EntityFrameworkQueryableExtensions.LongCountAsync(_context.Blogs, predicate); +#else + var expected = await QueryableExtensions.LongCountAsync(_context.Blogs, predicate); #endif + + //Act + long result = (_context.Blogs as IQueryable).LongCountInterpolated($"Name.Contains({search})"); + + //Assert + Assert.Equal(expected, result); + } + + [Fact(Skip = "not supported")] + public void Entities_TakeWhile_FS() + { + // Act + int value = 5; + var expected = _context.Blogs.OrderBy(b => b.BlogId).TakeWhile(b => b.BlogId > value).ToArray(); + var result = _context.Blogs.OrderByInterpolated($"BlogId").TakeWhileInterpolated($"b.BlogId > {value}").ToDynamicArray(); + + // Assert + Assert.Equal(expected, result); + } } +#endif \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs index d3138b1a..5b81edd0 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs @@ -6,31 +6,27 @@ using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + /// + /// Test for https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/524 + /// +//#if EFCORE +// [Fact(Skip = "Fails on .NET Core App with EF Core ?")] +//#else +// [Fact] +//#endif + public void Entities_Where_In_And() { - /// - /// Test for https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/524 - /// -#if EFCORE - [Fact(Skip = "Fails on .NET Core App with EF Core ?")] -#else - [Fact] -#endif - public void Entities_Where_In_And() - { - // Arrange - PopulateTestData(); - - var expected = _context.Blogs.Include(b => b.Posts).Where(b => new[] { 1, 3, 5 }.Contains(b.BlogId) && new[] { "Blog3", "Blog4" }.Contains(b.Name)).ToArray(); + // Arrange + var expected = _context.Blogs.Include(b => b.Posts).Where(b => new[] { 1000, 1001, 1002 }.Contains(b.BlogId) && new[] { "Blog1", "Blog2" }.Contains(b.Name)).ToArray(); - // Act - var test = _context.Blogs.Include(b => b.Posts).Where(@"BlogId in (1, 3, 5) and Name in (""Blog3"", ""Blog4"")").ToArray(); + // Act + var test = _context.Blogs.Include(b => b.Posts).Where(@"BlogId in (1000, 1001, 1002) and Name in (""Blog1"", ""Blog2"")").ToArray(); - // Assert - Assert.NotEmpty(test); - Assert.Equal(expected, test); - } + // Assert + Assert.Equal(expected, test); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCount.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCount.cs index 834db30a..2eeaa4a0 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCount.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCount.cs @@ -1,28 +1,20 @@ -using System.Linq.Dynamic.Core.Tests.Helpers.Entities; -using Xunit; +using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_LongCount_Predicate() { - [Fact] - public void Entities_LongCount_Predicate() - { - const string search = "a"; - - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); + // Arrange + const string search = "a"; - //Act - long expected = _context.Blogs.LongCount(b => b.Name.Contains(search)); - long result = _context.Blogs.LongCount("Name.Contains(@0)", search); + // Act + long expected = _context.Blogs.LongCount(b => b.Name.Contains(search)); + long result = _context.Blogs.LongCount("Name.Contains(@0)", search); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCountAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCountAsync.cs index 197b7d63..8f6ddc8d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCountAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.LongCountAsync.cs @@ -10,35 +10,28 @@ using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_LongCountAsync_Predicate_Args() { - [Fact] - public async Task Entities_LongCountAsync_Predicate_Args() - { - const string search = "a"; - - //Arrange - var blog1 = new Blog { Name = "blog a", BlogId = 1000, Created = DateTime.Now }; - var blog2 = new Blog { Name = "blog b", BlogId = 3000, Created = DateTime.Now }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); + // Arrange + const string search = "a"; - Expression> predicate = b => b.Name.Contains(search); + Expression> predicate = b => b.Name.Contains(search); #if EFCORE - var expected = await EntityFrameworkQueryableExtensions.LongCountAsync(_context.Blogs, predicate); + var expected = await EntityFrameworkQueryableExtensions.LongCountAsync(_context.Blogs, predicate); #else - var expected = await QueryableExtensions.LongCountAsync(_context.Blogs, predicate); + var expected = await QueryableExtensions.LongCountAsync(_context.Blogs, predicate); #endif - //Act - long result = (_context.Blogs as IQueryable).LongCount("Name.Contains(@0)", search); + //Act + long result = (_context.Blogs as IQueryable).LongCount("Name.Contains(@0)", search); - //Assert - Assert.Equal(expected, result); - } + //Assert + Assert.Equal(expected, result); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs index d7ebcbbd..6abdb6d6 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Page.cs @@ -8,19 +8,19 @@ public partial class EntitiesTests [Fact] public void Entities_Page() { - //Arrange - const int total = 25; + // Arrange const int page = 2; const int pageSize = 10; + int total = _context.Blogs.Count(); - //Act + // Act var expected = _context.Blogs.OrderBy(b => b.BlogId).Page(page, pageSize).ToArray(); IOrderedQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId"); bool any = queryable.Any(); var count = queryable.Count(); var result = queryable.Page(page, pageSize).ToDynamicArray(); - //Assert + // Assert Assert.True(any); Assert.Equal(total, count); Assert.Equal(expected, result); @@ -29,23 +29,23 @@ public void Entities_Page() [Fact] public void Entities_PageResult() { - //Arrange - const int total = 25; + // Arrange const int page = 2; const int pageSize = 10; + int total = _context.Blogs.Count(); - //Act + // Act var expectedResult = _context.Blogs.OrderBy(b => b.BlogId).PageResult(page, pageSize).Queryable.ToArray(); IQueryable queryable = _context.Blogs.Select("it").OrderBy("BlogId"); var count = queryable.Count(); var result = queryable.PageResult(page, pageSize); - //Assert + // Assert Assert.Equal(total, count); Assert.Equal(page, result.CurrentPage); Assert.Equal(pageSize, result.PageSize); Assert.Equal(total, result.RowCount); - Assert.Equal(5, result.PageCount); + Assert.Equal(3, result.PageCount); Assert.Equal(expectedResult, result.Queryable.ToDynamicArray()); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs index b1a4b825..d44c3d9d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs @@ -10,157 +10,149 @@ #endif using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Select_SingleColumn_NullCoalescing() { - [Fact] - public void Entities_Select_SingleColumn_NullCoalescing() - { - // Arrange - var blog1 = new Blog { BlogId = 1000, Name = "Blog1", Created = DateTime.Now, NullableInt = null }; - var blog2 = new Blog { BlogId = 2000, Name = "Blog2", Created = DateTime.Now, NullableInt = 5 }; - _context.Blogs.Add(blog1); - _context.Blogs.Add(blog2); - _context.SaveChanges(); - - var expected1 = _context.Blogs.Select(x => (int?)(x.NullableInt ?? 10)).ToArray(); - var expected2 = _context.Blogs.Select(x => (int?)(x.NullableInt ?? 9 + x.BlogId)).ToArray(); - - // Act - var test1 = _context.Blogs.Select("NullableInt ?? 10").ToArray(); - var test2 = _context.Blogs.Select("NullableInt ?? 9 + BlogId").ToArray(); - - // Assert - Assert.Equal(expected1, test1); - Assert.Equal(expected2, test2); - } + var expected1 = _context.Blogs.Select(x => (int?)(x.NullableInt ?? 10)).ToArray(); + var expected2 = _context.Blogs.Select(x => (int?)(x.NullableInt ?? 9 + x.BlogId)).ToArray(); - [Fact] - public void Entities_Select_SingleColumn() - { - //Arrange - PopulateTestData(5, 0); + // Act + var test1 = _context.Blogs.Select("NullableInt ?? 10").ToArray(); + var test2 = _context.Blogs.Select("NullableInt ?? 9 + BlogId").ToArray(); - var expected = _context.Blogs.Select(x => x.BlogId).ToArray(); + // Assert + Assert.Equal(expected1, test1); + Assert.Equal(expected2, test2); + } - //Act - var test = _context.Blogs.Select("BlogId").ToArray(); + [Fact] + public void Entities_Select_SingleColumn() + { + //Arrange + PopulateTestData(5, 0); - //Assert - Assert.Equal(expected, test); - } + var expected = _context.Blogs.Select(x => x.BlogId).ToArray(); - [Fact] - public void Entities_Select_EmptyObject() - { - ParsingConfig config = ParsingConfig.Default; - config.EvaluateGroupByAtDatabase = true; + //Act + var test = _context.Blogs.Select("BlogId").ToArray(); - // Arrange - PopulateTestData(5, 0); + //Assert + Assert.Equal(expected, test); + } - var expected = _context.Blogs.Select(x => new { }).ToList(); + [Fact] + public void Entities_Select_EmptyObject() + { + ParsingConfig config = ParsingConfig.Default; + config.EvaluateGroupByAtDatabase = true; - // Act - var test = _context.Blogs.GroupBy(config, "BlogId", "new()").Select("new()").ToList(); + // Arrange + PopulateTestData(5, 0); - // Assert - Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(test)); - } + var expected = _context.Blogs.Select(x => new { }).ToList(); - [Fact] - public void Entities_Select_BrokenObject() - { - ParsingConfig config = ParsingConfig.Default; - config.DisableMemberAccessToIndexAccessorFallback = false; + // Act + var test = _context.Blogs.GroupBy(config, "BlogId", "new()").Select("new()").ToList(); - // Silently creates something that will later fail on materialization - var test = _context.Blogs.Select(config, "new(~.BlogId)"); - test = test.Select(config, "new(nonexistentproperty as howcanthiswork)"); + // Assert + Assert.Equal(JsonConvert.SerializeObject(expected), JsonConvert.SerializeObject(test)); + } - // Will fail when creating the expression - config.DisableMemberAccessToIndexAccessorFallback = true; - Assert.ThrowsAny(() => - { - test = test.Select(config, "new(nonexistentproperty as howcanthiswork)"); - }); - } + [Fact] + public void Entities_Select_BrokenObject() + { + ParsingConfig config = ParsingConfig.Default; + config.DisableMemberAccessToIndexAccessorFallback = false; + + // Silently creates something that will later fail on materialization + var test = _context.Blogs.Select(config, "new(~.BlogId)"); + test = test.Select(config, "new(nonexistentproperty as howcanthiswork)"); - [Fact] - public void Entities_Select_MultipleColumn() + // Will fail when creating the expression + config.DisableMemberAccessToIndexAccessorFallback = true; + Assert.ThrowsAny(() => { - //Arrange - PopulateTestData(5, 0); + test = test.Select(config, "new(nonexistentproperty as howcanthiswork)"); + }); + } - var expected = _context.Blogs.Select(x => new { X = "x", x.BlogId, x.Name }).ToArray(); + [Fact] + public void Entities_Select_MultipleColumn() + { + //Arrange + PopulateTestData(5, 0); - //Act - var test = _context.Blogs.Select("new (\"x\" as X, BlogId, Name)").ToDynamicArray(); + var expected = _context.Blogs.Select(x => new { X = "x", x.BlogId, x.Name }).ToArray(); - //Assert - Assert.Equal( - expected, - test.Select(x => new { X = "x", BlogId = (int)x.BlogId, Name = (string)x.Name }).ToArray() //convert to same anomymous type used by expected so they can be found equal - ); - } + //Act + var test = _context.Blogs.Select("new (\"x\" as X, BlogId, Name)").ToDynamicArray(); - [Fact] - public void Entities_Select_BlogPosts() - { - //Arrange - PopulateTestData(5, 5); + //Assert + Assert.Equal( + expected, + test.Select(x => new { X = "x", BlogId = (int)x.BlogId, Name = (string)x.Name }).ToArray() //convert to same anomymous type used by expected so they can be found equal + ); + } - var expected = _context.Blogs.Where(x => x.BlogId == 1).SelectMany(x => x.Posts).Select(x => x.PostId).ToArray(); + [Fact] + public void Entities_Select_BlogPosts() + { + //Arrange + PopulateTestData(5, 5); - //Act - var test = _context.Blogs.Where(x => x.BlogId == 1).SelectMany("Posts").Select("PostId").ToArray(); + var expected = _context.Blogs.Where(x => x.BlogId == 1).SelectMany(x => x.Posts).Select(x => x.PostId).ToArray(); - //Assert - Assert.Equal(expected, test); - } + //Act + var test = _context.Blogs.Where(x => x.BlogId == 1).SelectMany("Posts").Select("PostId").ToArray(); - // fixed : EF issue !!! https://github.com/aspnet/EntityFramework/issues/4968 - [Fact] - public void Entities_Select_BlogAndPosts() - { - //Arrange - PopulateTestData(5, 5); + //Assert + Assert.Equal(expected, test); + } + + // fixed : EF issue !!! https://github.com/aspnet/EntityFramework/issues/4968 + [Fact] + public void Entities_Select_BlogAndPosts() + { + //Arrange + PopulateTestData(5, 5); - var expected = _context.Blogs.Select(x => new { x.BlogId, x.Name, x.Posts }).ToArray(); + var expected = _context.Blogs.Select(x => new { x.BlogId, x.Name, x.Posts }).ToArray(); - //Act - var test = _context.Blogs.Select("new (BlogId, Name, Posts)").ToDynamicArray(); + //Act + var test = _context.Blogs.Select("new (BlogId, Name, Posts)").ToDynamicArray(); - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; - var testRow = test[i]; + //Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; + var testRow = test[i]; - Assert.Equal(expectedRow.BlogId, testRow.BlogId); - Assert.Equal(expectedRow.Name, testRow.Name); + Assert.Equal(expectedRow.BlogId, testRow.BlogId); + Assert.Equal(expectedRow.Name, testRow.Name); - Assert.True(expectedRow.Posts != null); - Assert.Equal(expectedRow.Posts.ToList(), testRow.Posts); - } + Assert.True(expectedRow.Posts != null); + Assert.Equal(expectedRow.Posts.ToList(), testRow.Posts); } + } - [Fact(Skip = "593 - this does not work")] - public void Entities_Select_DynamicClass_And_Call_Any() - { - // Arrange - PopulateTestData(5, 0); + [Fact(Skip = "593 - this does not work")] + public void Entities_Select_DynamicClass_And_Call_Any() + { + // Arrange + PopulateTestData(5, 0); - // Act - var result = _context.Blogs - .Select("new (BlogId, Name)") - .Cast() - .Any("Name == \"Blog2\""); + // Act + var result = _context.Blogs + .Select("new (BlogId, Name)") + .Cast() + .Any("Name == \"Blog2\""); - // Assert - Assert.Equal(true, result); - } + // Assert + Assert.Equal(true, result); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index 0abea8b9..2c256e17 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -1,6 +1,4 @@ -using System.Collections; -using System.Linq.Dynamic.Core.Tests.Helpers.Entities; -using System.Threading.Tasks; +using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; #if EFCORE @@ -21,11 +19,10 @@ public EntitiesTests(EntitiesTestsDatabaseFixture fixture) { #if EFCORE var builder = new DbContextOptionsBuilder(); - builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); - + builder.UseSqlServer(fixture.ConnectionString); + _context = new BlogContext(builder.Options); - - // _context.Database.EnsureCreated(); + _context.Database.EnsureCreated(); #else _context = new BlogContext(fixture.ConnectionString); #endif @@ -39,6 +36,11 @@ private void PopulateTestData(int blogCount = 25, int postCount = 10) private void InternalPopulateTestData() { + if (_context.Blogs.Any()) + { + return; + } + for (int i = 0; i < 25; i++) { var blog = new Blog { X = i.ToString(), Name = "Blog" + (i + 1), BlogId = 1000 + i, Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) }; @@ -49,6 +51,7 @@ private void InternalPopulateTestData() { var post = new Post { + PostId = 10000 + i * 10 + j, Blog = blog, Title = $"Blog {i + 1} - Post {j + 1}", Content = "My Content", @@ -69,6 +72,11 @@ private void InternalPopulateTestData() }; _context.Blogs.Add(singleBlog); + _context.Blogs.Add(new Blog { BlogId = 2000, Name = "blog a", Created = DateTime.Now }); + _context.Blogs.Add(new Blog { BlogId = 2001, Name = "blog b", Created = DateTime.Now }); + _context.Blogs.Add(new Blog { BlogId = 3000, Name = "Blog1", Created = DateTime.Now, NullableInt = null }); + _context.Blogs.Add(new Blog { BlogId = 3001, Name = "Blog2", Created = DateTime.Now, NullableInt = 5 }); + _context.SaveChanges(); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs b/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs index d3d89467..42b5a743 100644 --- a/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/ExpressionTests.cs @@ -1544,7 +1544,7 @@ public void ExpressionTests_NullCoalescing() [InlineData("np(nullablenumber)", "Select(Param_0 => IIF(((Param_0 != null) AndAlso (Param_0.nullablenumber != null)), Param_0.nullablenumber, null))")] [InlineData("np(_enumnullable)", "Select(Param_0 => IIF(((Param_0 != null) AndAlso (Param_0._enumnullable != null)), Param_0._enumnullable, null))")] -#if NET452 +#if NET48 [InlineData("np(dt)", "Select(Param_0 => IIF((Param_0 != null), Convert(Param_0.dt), null))")] [InlineData("np(_enum)", "Select(Param_0 => IIF((Param_0 != null), Convert(Param_0._enum), null))")] [InlineData("np(g)", "Select(Param_0 => IIF((Param_0 != null), Convert(Param_0.g), null))")] diff --git a/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Blog.cs b/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Blog.cs index 1deffd3d..e9ad2dd1 100644 --- a/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Blog.cs +++ b/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Blog.cs @@ -1,19 +1,26 @@ using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; -namespace System.Linq.Dynamic.Core.Tests.Helpers.Entities +namespace System.Linq.Dynamic.Core.Tests.Helpers.Entities; + +public class Blog { - public class Blog - { - public int BlogId { get; set; } - public string? X { get; set; } - public string Name { get; set; } - public int? NullableInt { get; set; } - public virtual ICollection Posts { get; set; } + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int BlogId { get; set; } + + public string? X { get; set; } + + public string Name { get; set; } + + public int? NullableInt { get; set; } + + public virtual ICollection Posts { get; set; } -#if NET4 || NET452 - public DateTime Created { get; set; } +#if NET461 || NET48 + public DateTime Created { get; set; } #else - public DateTimeOffset Created { get; set; } + public DateTimeOffset Created { get; set; } #endif - } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Post.cs b/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Post.cs index df1da2cd..1406b4e9 100644 --- a/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Post.cs +++ b/test/System.Linq.Dynamic.Core.Tests/Helpers/Entities/Post.cs @@ -1,17 +1,23 @@ - -namespace System.Linq.Dynamic.Core.Tests.Helpers.Entities +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace System.Linq.Dynamic.Core.Tests.Helpers.Entities; + +public class Post { - public class Post - { - public int PostId { get; set; } - public string Title { get; set; } - public string Content { get; set; } + [Key] + [DatabaseGenerated(DatabaseGeneratedOption.None)] + public int PostId { get; set; } + + public string Title { get; set; } + + public string Content { get; set; } + + public int BlogId { get; set; } - public int BlogId { get; set; } - public virtual Blog Blog { get; set; } + public virtual Blog Blog { get; set; } - public int NumberOfReads { get; set; } + public int NumberOfReads { get; set; } - public DateTime PostDate { get; set; } - } + public DateTime PostDate { get; set; } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.MemberAccess.cs b/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.MemberAccess.cs index 8f266e69..9d60381b 100644 --- a/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.MemberAccess.cs +++ b/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.MemberAccess.cs @@ -15,7 +15,7 @@ public void ParseMemberAccess_DictionaryIndex_On_Dynamic() var expression = products.Where("Properties.Name == @0", "First Product").Expression; // Assert -#if NET452 || NET461 +#if NET461 || NET48 expression.ToString().Should().Be("System.Linq.Dynamic.Core.Tests.Parser.ProductDynamic[].Where(Param_0 => (GetMember Name(Param_0.Properties) == Convert(\"First Product\")))"); #else expression.ToString().Should().Be("System.Linq.Dynamic.Core.Tests.Parser.ProductDynamic[].Where(Param_0 => ([Dynamic] == Convert(\"First Product\", Object)))"); diff --git a/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.cs index bcc3c975..196e5578 100644 --- a/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/Parser/ExpressionParserTests.cs @@ -48,7 +48,7 @@ public void Parse_BitwiseOperatorOr_On_2EnumFlags() { // Arrange var expression = "@0 | @1"; -#if NET452 +#if NET48 var expected = "Convert((Convert(A) | Convert(B)))"; #else var expected = "Convert((Convert(A, Int32) | Convert(B, Int32)), ExampleFlags)"; @@ -78,7 +78,7 @@ public void Parse_BitwiseOperatorAnd_On_2EnumFlags() { // Arrange var expression = "@0 & @1"; -#if NET452 +#if NET48 var expected = "Convert((Convert(A) & Convert(B)))"; #else var expected = "Convert((Convert(A, Int32) & Convert(B, Int32)), ExampleFlags)"; @@ -108,7 +108,7 @@ public void Parse_BitwiseOperatorOr_On_3EnumFlags() { // Arrange var expression = "@0 | @1 | @2"; -#if NET452 +#if NET48 var expected = "Convert(((Convert(A) | Convert(B)) | Convert(C)))"; #else var expected = "Convert(((Convert(A, Int32) | Convert(B, Int32)) | Convert(C, Int32)), ExampleFlags)"; @@ -138,7 +138,7 @@ public void Parse_BitwiseOperatorAnd_On_3EnumFlags() { // Arrange var expression = "@0 & @1 & @2"; -#if NET452 +#if NET48 var expected = "Convert(((Convert(A) & Convert(B)) & Convert(C)))"; #else var expected = "Convert(((Convert(A, Int32) & Convert(B, Int32)) & Convert(C, Int32)), ExampleFlags)"; @@ -316,7 +316,7 @@ public void Parse_CastStringIntShouldReturnConstantExpression(string expression, } [Theory] -#if NET452 +#if NET48 [InlineData("int?(5)", typeof(int?), "Convert(5)")] [InlineData("int?(null)", typeof(int?), "Convert(null)")] [InlineData("string(null)", typeof(string), "Convert(null)")] diff --git a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs index afe4abba..8c688e22 100644 --- a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs +++ b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs @@ -23,7 +23,7 @@ public void Contains_Dynamic_ListWithStrings() Assert.Equal(realQuery.ToArray(), testQuery.Cast().ToArray()); } -#if NET452 || NET5_0 || NET6_0_OR_GREATER +#if NET48 || NET5_0 || NET6_0_OR_GREATER [Fact] [Trait("Issue", "130")] public void Contains_Dynamic_ListWithDynamicObjects() diff --git a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs index bcaeb676..6df5959c 100644 --- a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs @@ -429,7 +429,7 @@ public void Select_Dynamic_RenameParameterExpression_Is_True() Check.That(result).Equals("System.Int32[].Select(it => (it * it))"); } -#if NET452 || NET5_0 || NET6_0 || NET7_0 || NET8_0 +#if NET461 || NET5_0 || NET6_0 || NET7_0 || NET8_0 [Fact(Skip = "Fails sometimes in GitHub CI build")] #else [Fact] diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index 453da40b..6a1ad381 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -1,19 +1,16 @@  Stef Heyenrath - net452;netcoreapp3.1 + net48;netcoreapp3.1 System.Linq.Dynamic.Core.Tests full True enable ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk {912FBF24-3CAE-4A50-B5EA-E525B9FAEC80} + $(DefineConstants);EFCORE;EFCORE_3X - - @@ -40,33 +37,21 @@ - + + + + - - - - - - + + + - - - - - - - - - - - $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1 - \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs b/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs index 960ac8ea..995f02b1 100644 --- a/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs +++ b/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs @@ -4,7 +4,7 @@ public static class ExpressionString { public static string NullableConversion(string convertedExpr) { -#if NET452 || NET461 +#if NET461 || NET48 return $"Convert({convertedExpr})"; #else return $"Convert({convertedExpr}, Nullable`1)"; From 794d55a76b3e0da1146a17a414408948a0d7a711 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 22:42:45 +0200 Subject: [PATCH 03/22] . --- .github/workflows/ci.yml | 22 +++++++++---------- .../EntityFramework.DynamicLinq.Tests.csproj | 2 -- ...System.Linq.Dynamic.Core.Tests.Net5.csproj | 1 + ...System.Linq.Dynamic.Core.Tests.Net6.csproj | 1 + ...System.Linq.Dynamic.Core.Tests.Net7.csproj | 1 + ...System.Linq.Dynamic.Core.Tests.Net8.csproj | 1 + .../EntitiesTests.In.cs | 6 +---- .../System.Linq.Dynamic.Core.Tests.csproj | 13 ++++++----- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e961d982..9d2ff490 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,29 +12,29 @@ jobs: steps: - uses: actions/checkout@v2 - # - uses: actions/setup-dotnet@v3 - # with: - # dotnet-version: | - # 6.0.x - # 7.0.x - # 8.0.x + - uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 7.0.x + 8.0.x - name: Build Projects run: | dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci - - name: Run Tests net8.0 + - name: Run Tests EFCore net8.0 run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci - - name: Run Tests net7.0 + - name: Run Tests EFCore net7.0 run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj -c Release -p:buildType=azure-pipelines-ci - - name: Run Tests net6.0 + - name: Run Tests EFCore net6.0 run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci - - name: Run Tests net452 + - name: Run Tests EF net461 run: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -f net452 -p:buildType=azure-pipelines-ci + dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci diff --git a/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj b/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj index eff60236..48a6c721 100644 --- a/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj +++ b/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj @@ -52,9 +52,7 @@ - - diff --git a/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj b/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj index 36e8bac4..85adbca7 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj @@ -35,6 +35,7 @@ + diff --git a/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj b/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj index 2bbc533b..926ecaa8 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj @@ -38,6 +38,7 @@ + diff --git a/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj b/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj index 1661a129..8c15b8f2 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj @@ -39,6 +39,7 @@ + diff --git a/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj b/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj index f1c3db35..64b23118 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj @@ -39,6 +39,7 @@ + diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs index 5b81edd0..76a52796 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.In.cs @@ -13,11 +13,7 @@ public partial class EntitiesTests /// /// Test for https://github.com/zzzprojects/System.Linq.Dynamic.Core/pull/524 /// -//#if EFCORE -// [Fact(Skip = "Fails on .NET Core App with EF Core ?")] -//#else -// [Fact] -//#endif + [Fact] public void Entities_Where_In_And() { // Arrange diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index 6a1ad381..4cc4f803 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -1,7 +1,7 @@  Stef Heyenrath - net48;netcoreapp3.1 + netcoreapp3.1 System.Linq.Dynamic.Core.Tests full True @@ -38,19 +38,20 @@ - - - + - + + From e022de243db89423d7130f135244fd638639c029 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 22:44:19 +0200 Subject: [PATCH 04/22] windows-2022 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d2ff490..49631a24 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: [push] jobs: build: - runs-on: ubuntu + runs-on: windows-2022 env: IsRunningOnGitHubActions: 'true' From 55e866876faf5f6a384f304c2ebdfc6b080c7b5c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 22:55:16 +0200 Subject: [PATCH 05/22] ubuntu --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49631a24..9d2ff490 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,7 @@ on: [push] jobs: build: - runs-on: windows-2022 + runs-on: ubuntu env: IsRunningOnGitHubActions: 'true' From f96b02c2d6082944cd96e4f2e641619a7082cf02 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 23:09:04 +0200 Subject: [PATCH 06/22] inmem --- .github/workflows/ci.yml | 33 ++++++++++++++++--- .../DefaultQueryableAnalyzerTests.cs | 11 +++++-- .../EntitiesTests.DatabaseFixture.cs | 29 ++++++++++++++-- .../EntitiesTests.cs | 11 +++++-- .../System.Linq.Dynamic.Core.Tests.csproj | 1 + 5 files changed, 75 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d2ff490..50f57698 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,32 @@ name: Build with Tests on: [push] jobs: - build: + build_and_test_Windows: + runs-on: windows-latest + + env: + IsRunningOnGitHubActions: 'true' + UseInMemory: 'true' + + steps: + - uses: actions/checkout@v2 + + # - uses: actions/setup-dotnet@v3 + # with: + # dotnet-version: | + # 6.0.x + # 7.0.x + # 8.0.x + + - name: Build + run: | + dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci + + - name: Run Tests EFCore net8.0 + run: | + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci + + build_and_test_Linux: runs-on: ubuntu env: @@ -14,12 +39,12 @@ jobs: - uses: actions/setup-dotnet@v3 with: - dotnet-version: | + dotnet-version: | 6.0.x 7.0.x 8.0.x - - name: Build Projects + - name: Build run: | dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci @@ -37,4 +62,4 @@ jobs: - name: Run Tests EF net461 run: | - dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci + dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs index 718a6cdf..db630f81 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs @@ -23,13 +23,20 @@ public DefaultQueryableAnalyzerTests(EntitiesTestsDatabaseFixture fixture) { #if EFCORE var builder = new DbContextOptionsBuilder(); - builder.UseSqlServer(fixture.ConnectionString); + if (fixture.UseInMemory) + { + builder.UseInMemoryDatabase(Guid.NewGuid().ToString()); + } + else + { + builder.UseSqlServer(fixture.ConnectionString); + } _context = new BlogContext(builder.Options); - _context.Database.EnsureCreated(); #else _context = new BlogContext(fixture.ConnectionString); #endif + _queryableAnalyzer = new DefaultQueryableAnalyzer(); } diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs index d39fbcad..429ecdea 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.DatabaseFixture.cs @@ -15,7 +15,32 @@ public class EntitiesTestsDatabaseFixture : IAsyncLifetime public string ContainerId => $"{_msSqlContainer.Id}"; - public Task InitializeAsync() => _msSqlContainer.StartAsync(); + public bool UseInMemory + { + get + { + var useInMemory = Environment.GetEnvironmentVariable("UseInMemory"); + return bool.TryParse(useInMemory, out var value) && value; + } + } - public Task DisposeAsync() => _msSqlContainer.DisposeAsync().AsTask(); + public async Task InitializeAsync() + { + if (UseInMemory) + { + return; + } + + await _msSqlContainer.StartAsync(); + } + + public async Task DisposeAsync() + { + if (UseInMemory) + { + return; + } + + await _msSqlContainer.DisposeAsync(); + } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index 2c256e17..d1b487de 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -19,8 +19,15 @@ public EntitiesTests(EntitiesTestsDatabaseFixture fixture) { #if EFCORE var builder = new DbContextOptionsBuilder(); - builder.UseSqlServer(fixture.ConnectionString); - + if (fixture.UseInMemory) + { + builder.UseInMemoryDatabase(Guid.NewGuid().ToString()); + } + else + { + builder.UseSqlServer(fixture.ConnectionString); + } + _context = new BlogContext(builder.Options); _context.Database.EnsureCreated(); #else diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index 4cc4f803..432130dc 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -50,6 +50,7 @@ + From f92d33a71d5cc8d167c1f4e0246f10cef0281872 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 23:13:22 +0200 Subject: [PATCH 07/22] $"System.Linq.Dynamic.Core.{Guid.NewGuid()}" --- .../DefaultQueryableAnalyzerTests.cs | 2 +- test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs index db630f81..6f575e99 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DefaultQueryableAnalyzerTests.cs @@ -25,7 +25,7 @@ public DefaultQueryableAnalyzerTests(EntitiesTestsDatabaseFixture fixture) var builder = new DbContextOptionsBuilder(); if (fixture.UseInMemory) { - builder.UseInMemoryDatabase(Guid.NewGuid().ToString()); + builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); } else { diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index d1b487de..c6960df7 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -21,7 +21,7 @@ public EntitiesTests(EntitiesTestsDatabaseFixture fixture) var builder = new DbContextOptionsBuilder(); if (fixture.UseInMemory) { - builder.UseInMemoryDatabase(Guid.NewGuid().ToString()); + builder.UseInMemoryDatabase($"System.Linq.Dynamic.Core.{Guid.NewGuid()}"); } else { From 72c45bcdf23cfa0738784a38d26d1fdc0510d6fd Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Sun, 16 Jun 2024 23:27:58 +0200 Subject: [PATCH 08/22] fix --- .../EntitiesTests.Cast.cs | 32 +++++++------------ .../EntitiesTests.cs | 18 +++++++---- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs index 7eaa490c..008752c5 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs @@ -8,13 +8,15 @@ public partial class EntitiesTests // https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/577 #if NET6_0_OR_GREATER [Fact] - public void Cast_To_FromStringToInt() + public void Entities_Cast_To_FromStringToInt() { - // Arrange - PopulateTestData(2, 0); - // Act - var result = _context.Blogs.AsQueryable().Select("X").Select("Cast(\"int\")").ToDynamicArray(); + var result = _context.Blogs + .Where(b => b.BlogId >= 1000 && b.BlogId <= 1001) + .AsQueryable() + .Select("X") + .Select("Cast(\"int\")") + .ToDynamicArray(); // Assert Assert.Equal(new[] { 0, 1 }, result); @@ -23,11 +25,8 @@ public void Cast_To_FromStringToInt() // https://github.com/StefH/System.Linq.Dynamic.Core/issues/44 [Fact] - public void Cast_To_nullableint() + public void Entities_Cast_To_nullableint() { - // Arrange - PopulateTestData(1, 0); - // Act var expectedResult = _context.Blogs.Select(b => (int?)b.BlogId).Count(); var result = _context.Blogs.AsQueryable().Select("int?(BlogId)").Count(); @@ -37,11 +36,8 @@ public void Cast_To_nullableint() } [Fact] - public void Cast_To_nullableint_Automatic() + public void Entities_Cast_To_nullableint_Automatic() { - // Arrange - PopulateTestData(5, 0); - // Act var expectedResult = _context.Blogs.Select(b => b.BlogId == 2 ? (int?)b.BlogId : null).ToList(); var result = _context.Blogs.AsQueryable().Select("BlogId == 2 ? BlogId : null").ToDynamicList(); @@ -51,11 +47,8 @@ public void Cast_To_nullableint_Automatic() } [Fact] - public void Cast_To_nullablelong() + public void Entities_Cast_To_nullablelong() { - // Arrange - PopulateTestData(1, 0); - // Act var expectedResult = _context.Blogs.Select(b => (long?)b.BlogId).Count(); var result = _context.Blogs.AsQueryable().Select("long?(BlogId)").Count(); @@ -66,11 +59,8 @@ public void Cast_To_nullablelong() // https://github.com/StefH/System.Linq.Dynamic.Core/issues/44 [Fact] - public void Cast_To_newnullableint() + public void Entities_Cast_To_newnullableint() { - // Arrange - PopulateTestData(1, 0); - // Act var expectedResult = _context.Blogs.Select(x => new { i = (int?)x.BlogId }).Count(); var result = _context.Blogs.AsQueryable().Select("new (int?(BlogId) as i)").Count(); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index c6960df7..4c92d389 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -50,7 +50,13 @@ private void InternalPopulateTestData() for (int i = 0; i < 25; i++) { - var blog = new Blog { X = i.ToString(), Name = "Blog" + (i + 1), BlogId = 1000 + i, Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) }; + var blog = new Blog + { + X = i.ToString(), + Name = "Blog" + (i + 1), + BlogId = 1000 + i, + Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) + }; _context.Blogs.Add(blog); @@ -72,17 +78,17 @@ private void InternalPopulateTestData() var singleBlog = new Blog { - X = Guid.NewGuid().ToString(), + X = "42", Name = "SingleBlog", BlogId = 12345678, Created = DateTime.Now.AddDays(-Rnd.Next(0, 100)) }; _context.Blogs.Add(singleBlog); - _context.Blogs.Add(new Blog { BlogId = 2000, Name = "blog a", Created = DateTime.Now }); - _context.Blogs.Add(new Blog { BlogId = 2001, Name = "blog b", Created = DateTime.Now }); - _context.Blogs.Add(new Blog { BlogId = 3000, Name = "Blog1", Created = DateTime.Now, NullableInt = null }); - _context.Blogs.Add(new Blog { BlogId = 3001, Name = "Blog2", Created = DateTime.Now, NullableInt = 5 }); + _context.Blogs.Add(new Blog { BlogId = 2000, X = "0", Name = "blog a", Created = DateTime.Now }); + _context.Blogs.Add(new Blog { BlogId = 2001, X = "0", Name = "blog b", Created = DateTime.Now }); + _context.Blogs.Add(new Blog { BlogId = 3000, X = "0", Name = "Blog1", Created = DateTime.Now, NullableInt = null }); + _context.Blogs.Add(new Blog { BlogId = 3001, X = "0", Name = "Blog2", Created = DateTime.Now, NullableInt = 5 }); _context.SaveChanges(); } From e8bfc3f45f5ddc659c96e5ab2fcebfa2eeede151 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 07:08:13 +0200 Subject: [PATCH 09/22] ubuntu-latest --- .github/workflows/ci.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 50f57698..a44473e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,14 +11,7 @@ jobs: UseInMemory: 'true' steps: - - uses: actions/checkout@v2 - - # - uses: actions/setup-dotnet@v3 - # with: - # dotnet-version: | - # 6.0.x - # 7.0.x - # 8.0.x + - uses: actions/checkout@v4 - name: Build run: | @@ -29,13 +22,13 @@ jobs: dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci build_and_test_Linux: - runs-on: ubuntu + runs-on: ubuntu-latest env: IsRunningOnGitHubActions: 'true' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v3 with: From 23f7d452356ad58302f2d209913448f8bc906f5c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 07:16:47 +0200 Subject: [PATCH 10/22] fix linux --- .../Parser/StringParserTests.cs | 191 +++++++++--------- .../QueryableTests.Contains.cs | 10 +- 2 files changed, 102 insertions(+), 99 deletions(-) diff --git a/test/System.Linq.Dynamic.Core.Tests/Parser/StringParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/Parser/StringParserTests.cs index cc8f782d..b39a2349 100644 --- a/test/System.Linq.Dynamic.Core.Tests/Parser/StringParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/Parser/StringParserTests.cs @@ -3,103 +3,102 @@ using FluentAssertions; using Xunit; -namespace System.Linq.Dynamic.Core.Tests.Parser +namespace System.Linq.Dynamic.Core.Tests.Parser; + +public class StringParserTests { - public class StringParserTests + [Theory] + [InlineData("'s")] + [InlineData("\"s")] + public void StringParser_With_UnexpectedUnclosedString_ThrowsException(string input) + { + // Act + var exception = Assert.Throws(() => StringParser.ParseString(input)); + + // Assert + Assert.Equal($"Unexpected end of string with unclosed string at position 2 near '{input}'.", exception.Message); + } + + [Theory] + [InlineData("")] + [InlineData(null)] + [InlineData("x")] + public void StringParser_With_InvalidStringLength_ThrowsException(string input) + { + // Act + Action action = () => StringParser.ParseString(input); + + // Assert + action.Should().Throw().WithMessage($"String '{input}' should have at least 2 characters."); + } + + [Theory] + [InlineData("xx")] + [InlineData(" ")] + public void StringParser_With_InvalidStringQuoteCharacter_ThrowsException(string input) + { + // Act + Action action = () => StringParser.ParseString(input); + + // Assert + action.Should().Throw().WithMessage("An escaped string should start with a double (\") or a single (') quote."); + } + + [Fact] + public void StringParser_With_UnexpectedUnrecognizedEscapeSequence_ThrowsException() { - [Theory] - [InlineData("'s")] - [InlineData("\"s")] - public void StringParser_With_UnexpectedUnclosedString_ThrowsException(string input) - { - // Act - var exception = Assert.Throws(() => StringParser.ParseString(input)); - - // Assert - Assert.Equal($"Unexpected end of string with unclosed string at position 2 near '{input}'.", exception.Message); - } - - [Theory] - [InlineData("")] - [InlineData(null)] - [InlineData("x")] - public void StringParser_With_InvalidStringLength_ThrowsException(string input) - { - // Act - Action action = () => StringParser.ParseString(input); - - // Assert - action.Should().Throw().WithMessage($"String '{input}' should have at least 2 characters."); - } - - [Theory] - [InlineData("xx")] - [InlineData(" ")] - public void StringParser_With_InvalidStringQuoteCharacter_ThrowsException(string input) - { - // Act - Action action = () => StringParser.ParseString(input); - - // Assert - action.Should().Throw().WithMessage("An escaped string should start with a double (\") or a single (') quote."); - } - - [Fact] - public void StringParser_With_UnexpectedUnrecognizedEscapeSequence_ThrowsException() - { - // Arrange - var input = new string(new[] { '"', '\\', 'u', '?', '"' }); - - // Act - Action action = () => StringParser.ParseString(input); - - // Assert - var parseException = action.Should().Throw(); - - parseException.Which.InnerException!.Message.Should().Contain("hexadecimal digits"); - - parseException.Which.StackTrace.Should().Contain("at System.Linq.Dynamic.Core.Parser.StringParser.ParseString(String s, Int32 pos) in ").And.Contain("System.Linq.Dynamic.Core\\Parser\\StringParser.cs:line "); - } - - [Theory] - [InlineData("''", "")] - [InlineData("'s'", "s")] - [InlineData("'\\\\'", "\\")] - [InlineData("'\\n'", "\n")] - public void StringParser_Parse_SingleQuotedString(string input, string expectedResult) - { - // Act - var result = StringParser.ParseString(input); - - // Assert - result.Should().Be(expectedResult); - } - - [Theory] - [InlineData("\"\"", "")] - [InlineData("\"\\\\\"", "\\")] - [InlineData("\"\\n\"", "\n")] - [InlineData("\"\\\\n\"", "\\n")] - [InlineData("\"\\\\new\"", "\\new")] - [InlineData("\"[]\"", "[]")] - [InlineData("\"()\"", "()")] - [InlineData("\"(\\\"\\\")\"", "(\"\")")] - [InlineData("\"/\"", "/")] - [InlineData("\"a\"", "a")] - [InlineData("\"This \\\"is\\\" a test.\"", "This \"is\" a test.")] - [InlineData(@"""This \""is\"" b test.""", @"This ""is"" b test.")] - [InlineData("\"ab\\\"cd\"", "ab\"cd")] - [InlineData("\"\\\"\"", "\"")] - [InlineData("\"\\\"\\\"\"", "\"\"")] - [InlineData("\"AB YZ 19 \uD800\udc05 \u00e4\"", "AB YZ 19 \uD800\udc05 \u00e4")] - [InlineData("\"\\\\\\\\192.168.1.1\\\\audio\\\\new\"", "\\\\192.168.1.1\\audio\\new")] - public void StringParser_Parse_DoubleQuotedString(string input, string expectedResult) - { - // Act - var result = StringParser.ParseString(input); - - // Assert - result.Should().Be(expectedResult); - } + // Arrange + var input = new string(new[] { '"', '\\', 'u', '?', '"' }); + + // Act + Action action = () => StringParser.ParseString(input); + + // Assert + var parseException = action.Should().Throw(); + + parseException.Which.InnerException!.Message.Should().Contain("hexadecimal digits"); + + parseException.Which.StackTrace.Should().Contain("at System.Linq.Dynamic.Core.Parser.StringParser.ParseString(String s, Int32 pos) in ").And.Contain("StringParser.cs:line "); + } + + [Theory] + [InlineData("''", "")] + [InlineData("'s'", "s")] + [InlineData("'\\\\'", "\\")] + [InlineData("'\\n'", "\n")] + public void StringParser_Parse_SingleQuotedString(string input, string expectedResult) + { + // Act + var result = StringParser.ParseString(input); + + // Assert + result.Should().Be(expectedResult); + } + + [Theory] + [InlineData("\"\"", "")] + [InlineData("\"\\\\\"", "\\")] + [InlineData("\"\\n\"", "\n")] + [InlineData("\"\\\\n\"", "\\n")] + [InlineData("\"\\\\new\"", "\\new")] + [InlineData("\"[]\"", "[]")] + [InlineData("\"()\"", "()")] + [InlineData("\"(\\\"\\\")\"", "(\"\")")] + [InlineData("\"/\"", "/")] + [InlineData("\"a\"", "a")] + [InlineData("\"This \\\"is\\\" a test.\"", "This \"is\" a test.")] + [InlineData(@"""This \""is\"" b test.""", @"This ""is"" b test.")] + [InlineData("\"ab\\\"cd\"", "ab\"cd")] + [InlineData("\"\\\"\"", "\"")] + [InlineData("\"\\\"\\\"\"", "\"\"")] + [InlineData("\"AB YZ 19 \uD800\udc05 \u00e4\"", "AB YZ 19 \uD800\udc05 \u00e4")] + [InlineData("\"\\\\\\\\192.168.1.1\\\\audio\\\\new\"", "\\\\192.168.1.1\\audio\\new")] + public void StringParser_Parse_DoubleQuotedString(string input, string expectedResult) + { + // Act + var result = StringParser.ParseString(input); + + // Assert + result.Should().Be(expectedResult); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs index 8c688e22..16855fad 100644 --- a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs +++ b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs @@ -32,7 +32,11 @@ public void Contains_Dynamic_ListWithDynamicObjects() var baseQuery = User.GenerateSampleModels(100).AsQueryable(); var list = new List { new { UserName = "User1" } }; - var keyType = DynamicClassFactory.CreateType(new[] { new DynamicProperty("UserName", typeof(string)) }); + var keyType = DynamicClassFactory.CreateType(new[] + { + new DynamicProperty($"Test{Guid.NewGuid().ToString().Replace("-", "")}Test", typeof(string)), + new DynamicProperty("UserName", typeof(string)) + }); var keyVals = (IList)CreateGenericInstance(typeof(List<>), new[] { keyType }); var keyVal = Activator.CreateInstance(keyType); @@ -47,9 +51,9 @@ public void Contains_Dynamic_ListWithDynamicObjects() Assert.Equal(realQuery.ToArray(), testQuery.Cast().ToArray()); } - private object CreateGenericInstance(Type type, Type[] types, params dynamic[] ctorParams) + private static object CreateGenericInstance(Type type, Type[] typeArguments, params dynamic[] ctorParams) { - Type genType = type.MakeGenericType(types); + var genType = type.MakeGenericType(typeArguments); var constructor = genType.GetConstructors().First(); return constructor.Invoke(ctorParams); From 569169ca1f5702adb4985bfc41de2f4573e0eda8 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 07:17:31 +0200 Subject: [PATCH 11/22] Run Tests EF net461 --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a44473e9..49428caf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,10 @@ jobs: run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci + - name: Run Tests EF net461 + run: | + dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci + build_and_test_Linux: runs-on: ubuntu-latest From 95b5265a5e30fff0f634333178954938c861f793 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 08:07:29 +0200 Subject: [PATCH 12/22] contains --- .../EntitiesTests.All.cs | 27 +- .../EntitiesTests.AllAsync.cs | 27 +- .../EntitiesTests.Any.cs | 81 +++--- .../EntitiesTests.AnyAsync.cs | 71 +++--- .../EntitiesTests.Average.cs | 48 ++-- .../EntitiesTests.AverageAsync.cs | 49 ++-- .../EntitiesTests.Distinct.cs | 26 +- .../EntitiesTests.FirstAsync.cs | 55 ++-- .../EntitiesTests.FormattableString.cs | 2 - .../EntitiesTests.GroupBy.cs | 238 +++++++++--------- .../EntitiesTests.Include.cs | 31 ++- .../EntitiesTests.Select.cs | 17 +- .../EntitiesTests.Sum.cs | 93 ++++--- .../EntitiesTests.SumAsync.cs | 93 ++++--- .../EntitiesTests.TakeWhile.cs | 28 +-- .../EntitiesTests.cs | 5 - .../QueryableTests.Contains.cs | 70 ++---- 17 files changed, 413 insertions(+), 548 deletions(-) diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs index 4c4bc66f..900652b4 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs @@ -8,23 +8,20 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_All() { - [Fact] - public void Entities_All() - { - //Arrange - PopulateTestData(1, 0); - - var expected = _context.Blogs.All(b => b.BlogId > 2000); + // Arrange + var expected = _context.Blogs.All(b => b.BlogId > 2000); - //Act - var actual = _context.Blogs.All("BlogId > 2000"); + // Act + var actual = _context.Blogs.All("BlogId > 2000"); - //Assert - Assert.Equal(expected, actual); - } + // Assert + Assert.Equal(expected, actual); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AllAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AllAsync.cs index 7ec5d647..8c3ee4d9 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AllAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AllAsync.cs @@ -8,23 +8,20 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_AllAsync() { - [Fact] - public async Task Entities_AllAsync() - { - //Arrange - PopulateTestData(1, 0); - - var expected = await _context.Blogs.AllAsync(b => b.BlogId > 2000); + // Arrange + var expected = await _context.Blogs.AllAsync(b => b.BlogId > 2000); - //Act - var actual = await _context.Blogs.AllAsync("BlogId > 2000"); + // Act + var actual = await _context.Blogs.AllAsync("BlogId > 2000"); - //Assert - Assert.Equal(expected, actual); - } + // Assert + Assert.Equal(expected, actual); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Any.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Any.cs index c1896b87..cc811994 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Any.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Any.cs @@ -1,49 +1,44 @@ using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Any() + { + // Arrange + var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); + bool expectedAny1 = expectedQueryable1.Any(); + + var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999); + bool expectedAny2 = expectedQueryable2.Any(); + + // Act + IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); + bool any1 = queryable1.Any(); + + IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999"); + bool any2 = queryable2.Any(); + + // Assert + Assert.Equal(expectedAny1, any1); + Assert.Equal(expectedAny2, any2); + } + + [Fact] + public void Entities_Any_Predicate() { - [Fact] - public void Entities_Any() - { - //Arrange - PopulateTestData(1, 0); - - var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); - bool expectedAny1 = expectedQueryable1.Any(); - - var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999); - bool expectedAny2 = expectedQueryable2.Any(); - - //Act - IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); - bool any1 = queryable1.Any(); - - IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999"); - bool any2 = queryable2.Any(); - - //Assert - Assert.Equal(expectedAny1, any1); - Assert.Equal(expectedAny2, any2); - } - - [Fact] - public void Entities_Any_Predicate() - { - //Arrange - PopulateTestData(1, 0); - - bool expectedAny1 = _context.Blogs.Any(b => b.BlogId > 0); - bool expectedAny2 = _context.Blogs.Any(b => b.BlogId > 9999); - - //Act - bool any1 = _context.Blogs.AsQueryable().Any("it.BlogId > 0"); - bool any2 = _context.Blogs.AsQueryable().Any("it.BlogId > 9999"); - - //Assert - Assert.Equal(expectedAny1, any1); - Assert.Equal(expectedAny2, any2); - } + // Arrange + bool expectedAny1 = _context.Blogs.Any(b => b.BlogId > 0); + bool expectedAny2 = _context.Blogs.Any(b => b.BlogId > 9999); + + // Act + bool any1 = _context.Blogs.AsQueryable().Any("it.BlogId > 0"); + bool any2 = _context.Blogs.AsQueryable().Any("it.BlogId > 9999"); + + // ssert + Assert.Equal(expectedAny1, any1); + Assert.Equal(expectedAny2, any2); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AnyAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AnyAsync.cs index d98f3d6c..68887a0c 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AnyAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AnyAsync.cs @@ -8,55 +8,50 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_AnyAsync() { - [Fact] - public async Task Entities_AnyAsync() - { - //Arrange - PopulateTestData(1, 0); - - var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); - bool expectedAny1 = await expectedQueryable1.AnyAsync(); - - var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999); - bool expectedAny2 = await expectedQueryable2.AnyAsync(); + // Arrange + var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); + bool expectedAny1 = await expectedQueryable1.AnyAsync(); - //Act - IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); - bool any1 = await queryable1.AnyAsync(); + var expectedQueryable2 = _context.Blogs.Where(b => b.BlogId > 9999); + bool expectedAny2 = await expectedQueryable2.AnyAsync(); - IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999"); - bool any2 = await queryable2.AnyAsync(); + // Act + IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); + bool any1 = await queryable1.AnyAsync(); - //Assert - Assert.Equal(expectedAny1, any1); - Assert.Equal(expectedAny2, any2); - } + IQueryable queryable2 = _context.Blogs.Where("BlogId > 9999"); + bool any2 = await queryable2.AnyAsync(); - [Fact] - public async Task Entities_AnyAsync_Predicate() - { - //Arrange - PopulateTestData(1, 0); + // Assert + Assert.Equal(expectedAny1, any1); + Assert.Equal(expectedAny2, any2); + } + [Fact] + public async Task Entities_AnyAsync_Predicate() + { + // Arrange #if EFCORE - bool expectedAny1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 0); - bool expectedAny2 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 9999); + bool expectedAny1 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 0); + bool expectedAny2 = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 9999); #else - bool expectedAny1 = await System.Data.Entity.QueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 0); - bool expectedAny2 = await System.Data.Entity.QueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 9999); + bool expectedAny1 = await System.Data.Entity.QueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 0); + bool expectedAny2 = await System.Data.Entity.QueryableExtensions.AnyAsync(_context.Blogs, b => b.BlogId > 9999); #endif - //Act - bool any1 = await _context.Blogs.AsQueryable().AnyAsync("it.BlogId > 0"); - bool any2 = await _context.Blogs.AsQueryable().AnyAsync("it.BlogId > 9999"); + // Act + bool any1 = await _context.Blogs.AsQueryable().AnyAsync("it.BlogId > 0"); + bool any2 = await _context.Blogs.AsQueryable().AnyAsync("it.BlogId > 9999"); - //Assert - Assert.Equal(expectedAny1, any1); - Assert.Equal(expectedAny2, any2); - } + // Assert + Assert.Equal(expectedAny1, any1); + Assert.Equal(expectedAny2, any2); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Average.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Average.cs index 815b7b26..ef4bda70 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Average.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Average.cs @@ -7,37 +7,29 @@ #endif using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Average() { - [Fact] - public void Entities_Average() - { - // Arrange - PopulateTestData(2, 0); - - // Act - double expected = _context.Blogs.Select(b => b.BlogId).Average(); - double actual = _context.Blogs.Select("BlogId").Average(); - - // Assert - Assert.Equal(expected, actual); - } + // Act + double expected = _context.Blogs.Select(b => b.BlogId).Average(); + double actual = _context.Blogs.Select("BlogId").Average(); - [Fact] - public void Entities_Average_Selector() - { - // Arrange - PopulateTestData(2, 0); - - double expected = _context.Blogs.Average(b => b.BlogId); + // Assert + Assert.Equal(expected, actual); + } - // Act - double actual = _context.Blogs.Average("BlogId"); + [Fact] + public void Entities_Average_Selector() + { + // Act + double expected = _context.Blogs.Average(b => b.BlogId); + double actual = _context.Blogs.Average("BlogId"); - // Assert - Assert.Equal(expected, actual); - } + // Assert + Assert.Equal(expected, actual); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AverageAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AverageAsync.cs index 0f496cda..ae6f0d12 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AverageAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.AverageAsync.cs @@ -8,38 +8,33 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_AverageAsync() { - [Fact] - public void Entities_AverageAsync() - { - // Arrange - PopulateTestData(2, 0); - - double expected = _context.Blogs.Select(b => b.BlogId).AverageAsync().GetAwaiter().GetResult(); - - // Act - double actual = _context.Blogs.Select("BlogId").AverageAsync().GetAwaiter().GetResult(); + // Arrange + double expected = _context.Blogs.Select(b => b.BlogId).AverageAsync().GetAwaiter().GetResult(); - // Assert - Assert.Equal(expected, actual); - } + // Act + double actual = _context.Blogs.Select("BlogId").AverageAsync().GetAwaiter().GetResult(); - [Fact] - public async Task Entities_AverageAsync_Selector() - { - // Arrange - PopulateTestData(2, 0); + // Assert + Assert.Equal(expected, actual); + } - double expected = await _context.Blogs.AverageAsync(b => b.BlogId); + [Fact] + public async Task Entities_AverageAsync_Selector() + { + // Arrange + double expected = await _context.Blogs.AverageAsync(b => b.BlogId); - // Act - double actual = await _context.Blogs.AverageAsync("BlogId"); + // Act + double actual = await _context.Blogs.AverageAsync("BlogId"); - // Assert - Assert.Equal(expected, actual); - } + // Assert + Assert.Equal(expected, actual); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Distinct.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Distinct.cs index 4573e78b..1db86176 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Distinct.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Distinct.cs @@ -1,23 +1,17 @@ using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Distinct() { - [Fact] - public void Entities_Distinct() - { - //Arrange - PopulateTestData(10, 5); - - var expectedQueryable1 = _context.Blogs.Select(b => b.Posts.Distinct()); - - //Act - var expected = _context.Blogs.Select(b => b.Posts.Distinct()).ToArray(); - var result = _context.Blogs.Select("Posts.Distinct()").ToDynamicArray(); + // Act + var expected = _context.Blogs.Select(b => b.Posts.Distinct()).ToArray(); + var result = _context.Blogs.Select("Posts.Distinct()").ToDynamicArray(); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstAsync.cs index b9ebe304..93d76d2b 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FirstAsync.cs @@ -6,44 +6,39 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_FirstAsync() { - [Fact] - public async Task Entities_FirstAsync() - { - //Arrange - PopulateTestData(1, 0); - - var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); - - var expected = await expectedQueryable1.FirstAsync(); + // rrange + var expectedQueryable1 = _context.Blogs.Where(b => b.BlogId > 0); - //Act - IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); - var result = await queryable1.FirstAsync(); + var expected = await expectedQueryable1.FirstAsync(); - //Assert - Assert.Equal(expected, result); - } + // Act + IQueryable queryable1 = _context.Blogs.Where("BlogId > 0"); + var result = await queryable1.FirstAsync(); - [Fact] - public async Task Entities_FirstAsync_Predicate() - { - //Arrange - PopulateTestData(1, 0); + // Assert + Assert.Equal(expected, result); + } + [Fact] + public async Task Entities_FirstAsync_Predicate() + { + // Arrange #if EFCORE - var expected = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstAsync(_context.Blogs, b => b.BlogId > 0); + var expected = await Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstAsync(_context.Blogs, b => b.BlogId > 0); #else - var expected = await System.Data.Entity.QueryableExtensions.FirstAsync(_context.Blogs, b => b.BlogId > 0); + var expected = await System.Data.Entity.QueryableExtensions.FirstAsync(_context.Blogs, b => b.BlogId > 0); #endif - //Act - var result = await (_context.Blogs.AsQueryable() as IQueryable).FirstAsync("it.BlogId > 0"); + // Act + var result = await (_context.Blogs.AsQueryable() as IQueryable).FirstAsync("it.BlogId > 0"); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs index b18e560c..2f5494de 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.FormattableString.cs @@ -18,7 +18,6 @@ public partial class EntitiesTests public void Entities_All_FS() { //Arrange - PopulateTestData(1, 0); int value = 2000; var expected = _context.Blogs.All(b => b.BlogId > value); @@ -33,7 +32,6 @@ public void Entities_All_FS() public async Task Entities_AllAsync_FS() { //Arrange - PopulateTestData(1, 0); int value = 2000; var expected = await _context.Blogs.AllAsync(b => b.BlogId > value); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs index 2a6aa697..8018f9cf 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.GroupBy.cs @@ -7,170 +7,158 @@ #endif using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_GroupBy_SingleKey() { - [Fact] - public void Entities_GroupBy_SingleKey() - { - // "memory leak" warning exception starting from EF Core 3.x + // "memory leak" warning exception starting from EF Core 3.x #if !EFCORE_3X - //Arrange - PopulateTestData(5, 5); - - var expected = _context.Posts.GroupBy(x => x.BlogId).ToArray(); + // Arrange + var expected = _context.Posts.GroupBy(x => x.BlogId).ToArray(); - //Act - var test = _context.Posts.GroupBy("BlogId").ToDynamicArray(); + // Act + var test = _context.Posts.GroupBy("BlogId").ToDynamicArray(); - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; + // Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; - //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first - var testRow = (IGrouping)test[i]; + //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first + var testRow = (IGrouping)test[i]; - Assert.Equal(expectedRow.Key, testRow.Key); - Assert.Equal(expectedRow.ToArray(), testRow.ToArray()); - } -#endif + Assert.Equal(expectedRow.Key, testRow.Key); + Assert.Equal(expectedRow.ToArray(), testRow.ToArray()); } +#endif + } - [Fact] - public void Entities_GroupBy_MultiKey() - { - // "memory leak" warning exception starting from EF Core 3.x + [Fact] + public void Entities_GroupBy_MultiKey() + { + // "memory leak" warning exception starting from EF Core 3.x #if !EFCORE_3X - //Arrange - PopulateTestData(5, 15); + // Arrange + var expected = _context.Posts.GroupBy(x => new { x.BlogId, x.PostDate }).OrderBy(x => x.Key.PostDate).ToArray(); - var expected = _context.Posts.GroupBy(x => new { x.BlogId, x.PostDate }).OrderBy(x => x.Key.PostDate).ToArray(); + // Act + var test = _context.Posts.GroupBy("new (BlogId, PostDate)").OrderBy("Key.PostDate").ToDynamicArray(); - //Act - var test = _context.Posts.GroupBy("new (BlogId, PostDate)").OrderBy("Key.PostDate").ToDynamicArray(); - - - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; + // Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; - //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first - var testRow = (IGrouping)test[i]; + //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first + var testRow = (IGrouping)test[i]; - Assert.Equal(expectedRow.Key.BlogId, ((dynamic)testRow.Key).BlogId); - Assert.Equal(expectedRow.Key.PostDate, ((dynamic)testRow.Key).PostDate); - Assert.Equal(expectedRow.ToArray(), testRow.ToArray()); - } -#endif + Assert.Equal(expectedRow.Key.BlogId, ((dynamic)testRow.Key).BlogId); + Assert.Equal(expectedRow.Key.PostDate, ((dynamic)testRow.Key).PostDate); + Assert.Equal(expectedRow.ToArray(), testRow.ToArray()); } +#endif + } - [Fact] - public void Entities_GroupBy_SingleKey_SingleResult() - { - // "memory leak" warning exception starting from EF Core 3.x + [Fact] + public void Entities_GroupBy_SingleKey_SingleResult() + { + // "memory leak" warning exception starting from EF Core 3.x #if !EFCORE_3X - //Arrange - PopulateTestData(5, 5); + // Arrange - var expected = _context.Posts.GroupBy(x => x.PostDate, x => x.Title).ToArray(); + var expected = _context.Posts.GroupBy(x => x.PostDate, x => x.Title).ToArray(); - //Act - var test = _context.Posts.GroupBy("PostDate", "Title").ToDynamicArray(); + // Act + var test = _context.Posts.GroupBy("PostDate", "Title").ToDynamicArray(); - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; + // Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; - //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first - var testRow = (IGrouping)test[i]; + //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first + var testRow = (IGrouping)test[i]; - Assert.Equal(expectedRow.Key, testRow.Key); - Assert.Equal(expectedRow.ToArray(), testRow.ToArray()); - } -#endif + Assert.Equal(expectedRow.Key, testRow.Key); + Assert.Equal(expectedRow.ToArray(), testRow.ToArray()); } +#endif + } - [Fact] - public void Entities_GroupBy_SingleKey_MultiResult() - { - // "memory leak" warning exception starting from EF Core 3.x + [Fact] + public void Entities_GroupBy_SingleKey_MultiResult() + { + // "memory leak" warning exception starting from EF Core 3.x #if !EFCORE_3X - //Arrange - PopulateTestData(5, 5); + // Arrange - var expected = _context.Posts.GroupBy(x => x.PostDate, x => new { x.Title, x.Content }).ToArray(); + var expected = _context.Posts.GroupBy(x => x.PostDate, x => new { x.Title, x.Content }).ToArray(); - //Act - var test = _context.Posts.GroupBy("PostDate", "new (Title, Content)").ToDynamicArray(); + // Act + var test = _context.Posts.GroupBy("PostDate", "new (Title, Content)").ToDynamicArray(); - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; + // Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; - //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first - var testRow = (IGrouping)test[i]; + //For some reason, the DynamicBinder doesn't allow us to access values of the Group object, so we have to cast first + var testRow = (IGrouping)test[i]; - Assert.Equal(expectedRow.Key, testRow.Key); - Assert.Equal( - expectedRow.ToArray(), - testRow.Cast().Select(x => new { Title = (string)x.Title, Content = (string)x.Content }).ToArray()); - } -#endif + Assert.Equal(expectedRow.Key, testRow.Key); + Assert.Equal( + expectedRow.ToArray(), + testRow.Cast().Select(x => new { Title = (string)x.Title, Content = (string)x.Content }).ToArray()); } +#endif + } - [Fact] - public void Entities_GroupBy_SingleKey_Count() - { - //Arrange - PopulateTestData(5, 5); - - var expected = _context.Posts.GroupBy(x => x.PostDate).Select(x => new { x.Key, Count = x.Count() }).ToArray(); + [Fact] + public void Entities_GroupBy_SingleKey_Count() + { + // Arrange + var expected = _context.Posts.GroupBy(x => x.PostDate).Select(x => new { x.Key, Count = x.Count() }).ToArray(); - //Act - var test = _context.Posts.GroupBy("PostDate").Select("new(Key, Count() AS Count)").ToDynamicArray(); + // Act + var test = _context.Posts.GroupBy("PostDate").Select("new(Key, Count() AS Count)").ToDynamicArray(); - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; - var testRow = test[i]; + // Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; + var testRow = test[i]; - Assert.Equal(expectedRow.Key, testRow.Key); - Assert.Equal(expectedRow.Count, testRow.Count); - } + Assert.Equal(expectedRow.Key, testRow.Key); + Assert.Equal(expectedRow.Count, testRow.Count); } + } - [Fact] - public void Entities_GroupBy_SingleKey_Sum() - { - //Arrange - PopulateTestData(5, 5); - - var expected = _context.Posts.GroupBy(x => x.PostDate).Select(x => new { x.Key, Reads = x.Sum(y => y.NumberOfReads) }).ToArray(); + [Fact] + public void Entities_GroupBy_SingleKey_Sum() + { + // Arrange + var expected = _context.Posts.GroupBy(x => x.PostDate).Select(x => new { x.Key, Reads = x.Sum(y => y.NumberOfReads) }).ToArray(); - //Act - var test = _context.Posts.GroupBy("PostDate").Select("new(Key, Sum(NumberOfReads) AS Reads)").ToDynamicArray(); + // Act + var test = _context.Posts.GroupBy("PostDate").Select("new(Key, Sum(NumberOfReads) AS Reads)").ToDynamicArray(); - //Assert - Assert.Equal(expected.Length, test.Length); - for (int i = 0; i < expected.Length; i++) - { - var expectedRow = expected[i]; - var testRow = test[i]; + // Assert + Assert.Equal(expected.Length, test.Length); + for (int i = 0; i < expected.Length; i++) + { + var expectedRow = expected[i]; + var testRow = test[i]; - Assert.Equal(expectedRow.Key, testRow.Key); - Assert.Equal(expectedRow.Reads, testRow.Reads); - } + Assert.Equal(expectedRow.Key, testRow.Key); + Assert.Equal(expectedRow.Reads, testRow.Reads); } } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs index 1449d227..3599c631 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Include.cs @@ -7,26 +7,23 @@ #endif using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + /// + /// Test for https://github.com/StefH/System.Linq.Dynamic.Core/issues/28 + /// + [Fact] + public void Entities_Where_Include() { - /// - /// Test for https://github.com/StefH/System.Linq.Dynamic.Core/issues/28 - /// - [Fact] - public void Entities_Where_Include() - { - // Arrange - PopulateTestData(5, 2); - - var expected = _context.Blogs.Include(b => b.Posts).Where(b => b.BlogId > 2000).ToArray(); + // Arrange + var expected = _context.Blogs.Include(b => b.Posts).Where(b => b.BlogId > 2000).ToArray(); - // Act - var test = _context.Blogs.Include(b => b.Posts).Where("BlogId > 2000").ToArray(); + // Act + var test = _context.Blogs.Include(b => b.Posts).Where("BlogId > 2000").ToArray(); - // Assert - Assert.Equal(expected, test); - } + // Assert + Assert.Equal(expected, test); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs index d44c3d9d..ccba384e 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs @@ -33,8 +33,6 @@ public void Entities_Select_SingleColumn_NullCoalescing() public void Entities_Select_SingleColumn() { //Arrange - PopulateTestData(5, 0); - var expected = _context.Blogs.Select(x => x.BlogId).ToArray(); //Act @@ -47,12 +45,10 @@ public void Entities_Select_SingleColumn() [Fact] public void Entities_Select_EmptyObject() { + // Arrange ParsingConfig config = ParsingConfig.Default; config.EvaluateGroupByAtDatabase = true; - - // Arrange - PopulateTestData(5, 0); - + var expected = _context.Blogs.Select(x => new { }).ToList(); // Act @@ -84,8 +80,6 @@ public void Entities_Select_BrokenObject() public void Entities_Select_MultipleColumn() { //Arrange - PopulateTestData(5, 0); - var expected = _context.Blogs.Select(x => new { X = "x", x.BlogId, x.Name }).ToArray(); //Act @@ -102,8 +96,6 @@ public void Entities_Select_MultipleColumn() public void Entities_Select_BlogPosts() { //Arrange - PopulateTestData(5, 5); - var expected = _context.Blogs.Where(x => x.BlogId == 1).SelectMany(x => x.Posts).Select(x => x.PostId).ToArray(); //Act @@ -118,8 +110,6 @@ public void Entities_Select_BlogPosts() public void Entities_Select_BlogAndPosts() { //Arrange - PopulateTestData(5, 5); - var expected = _context.Blogs.Select(x => new { x.BlogId, x.Name, x.Posts }).ToArray(); //Act @@ -143,9 +133,6 @@ public void Entities_Select_BlogAndPosts() [Fact(Skip = "593 - this does not work")] public void Entities_Select_DynamicClass_And_Call_Any() { - // Arrange - PopulateTestData(5, 0); - // Act var result = _context.Blogs .Select("new (BlogId, Name)") diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Sum.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Sum.cs index 3cbb3714..988cc632 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Sum.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Sum.cs @@ -7,68 +7,59 @@ #endif using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public void Entities_Sum_Integer() { - [Fact] - public void Entities_Sum_Integer() - { - // Arrange - PopulateTestData(2, 0); - - var expected = _context.Blogs.Select(b => b.BlogId).Sum(); - - // Act - var actual = _context.Blogs.Select("BlogId").Sum(); + // Arrange + var expected = _context.Blogs.Select(b => b.BlogId).Sum(); - // Assert - Assert.Equal(expected, actual); - } + // Act + var actual = _context.Blogs.Select("BlogId").Sum(); - [Fact] - public void Entities_Sum_Double() - { - // Arrange - PopulateTestData(2, 0); - - var expected = _context.Blogs.Select(b => b.BlogId * 1.0d).Sum(); - - // Act - var actual = _context.Blogs.Select("BlogId * 1.0").Sum(); + // Assert + Assert.Equal(expected, actual); + } - // Assert - Assert.Equal(expected, actual); - } + [Fact] + public void Entities_Sum_Double() + { + // Arrange + var expected = _context.Blogs.Select(b => b.BlogId * 1.0d).Sum(); - [Fact] - public void Entities_Sum_Integer_Selector() - { - // Arrange - PopulateTestData(2, 0); + // Act + var actual = _context.Blogs.Select("BlogId * 1.0").Sum(); - var expected = _context.Blogs.Sum(b => b.BlogId); + // Assert + Assert.Equal(expected, actual); + } - // Act - var actual = _context.Blogs.Sum("BlogId"); + [Fact] + public void Entities_Sum_Integer_Selector() + { + // Arrange + var expected = _context.Blogs.Sum(b => b.BlogId); - // Assert - Assert.Equal(expected, actual); - } + // Act + var actual = _context.Blogs.Sum("BlogId"); - [Fact] - public void Entities_Sum_Double_Selector() - { - // Arrange - PopulateTestData(2, 0); + // Assert + Assert.Equal(expected, actual); + } - var expected = _context.Blogs.Sum(b => b.BlogId * 1.0d); + [Fact] + public void Entities_Sum_Double_Selector() + { + // Arrange + var expected = _context.Blogs.Sum(b => b.BlogId * 1.0d); - // Act - var actual = _context.Blogs.Sum("BlogId * 1.0d"); + // Act + var actual = _context.Blogs.Sum("BlogId * 1.0d"); - // Assert - Assert.Equal(expected, actual); - } + // Assert + Assert.Equal(expected, actual); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SumAsync.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SumAsync.cs index 8c4daaf4..44ec861d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SumAsync.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.SumAsync.cs @@ -8,68 +8,59 @@ using System.Threading.Tasks; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + [Fact] + public async Task Entities_SumAsync_Integer() { - [Fact] - public async Task Entities_SumAsync_Integer() - { - // Arrange - PopulateTestData(2, 0); - - var expected = await _context.Blogs.Select(b => b.BlogId).SumAsync(); - - // Act - var actual = await _context.Blogs.Select("BlogId").SumAsync(); + // Arrange + var expected = await _context.Blogs.Select(b => b.BlogId).SumAsync(); - // Assert - Assert.Equal(expected, actual); - } + // Act + var actual = await _context.Blogs.Select("BlogId").SumAsync(); - [Fact] - public async Task Entities_SumAsync_Double() - { - // Arrange - PopulateTestData(2, 0); - - var expected = await _context.Blogs.Select(b => b.BlogId * 1.0d).SumAsync(); - - // Act - var actual = await _context.Blogs.Select("BlogId").SumAsync(); + // Assert + Assert.Equal(expected, actual); + } - // Assert - Assert.Equal(expected, actual); - } + [Fact] + public async Task Entities_SumAsync_Double() + { + // Arrange + var expected = await _context.Blogs.Select(b => b.BlogId * 1.0d).SumAsync(); - [Fact] - public async Task Entities_SumAsync_Integer_Selector() - { - // Arrange - PopulateTestData(2, 0); + // Act + var actual = await _context.Blogs.Select("BlogId").SumAsync(); - var expected = await _context.Blogs.SumAsync(b => b.BlogId); + // Assert + Assert.Equal(expected, actual); + } - // Act - var actual = await _context.Blogs.SumAsync("BlogId"); + [Fact] + public async Task Entities_SumAsync_Integer_Selector() + { + // Arrange + var expected = await _context.Blogs.SumAsync(b => b.BlogId); - // Assert - Assert.Equal(expected, actual); - } + // Act + var actual = await _context.Blogs.SumAsync("BlogId"); - [Fact] - public async Task Entities_SumAsync_Double_Selector() - { - // Arrange - PopulateTestData(2, 0); + // Assert + Assert.Equal(expected, actual); + } - var expected = await _context.Blogs.SumAsync(b => b.BlogId * 1.0d); + [Fact] + public async Task Entities_SumAsync_Double_Selector() + { + // Arrange + var expected = await _context.Blogs.SumAsync(b => b.BlogId * 1.0d); - // Act - var actual = await _context.Blogs.SumAsync("BlogId * 1.0d"); + // Act + var actual = await _context.Blogs.SumAsync("BlogId * 1.0d"); - // Assert - Assert.Equal(expected, actual); - } + // Assert + Assert.Equal(expected, actual); } -} +} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.TakeWhile.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.TakeWhile.cs index cc7973e6..77ce308c 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.TakeWhile.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.TakeWhile.cs @@ -1,24 +1,22 @@ using System.Linq.Dynamic.Core.Tests.Helpers.Entities; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class EntitiesTests { - public partial class EntitiesTests + // Not supported : https://msdn.microsoft.com/en-in/library/bb738474%28en-us%29.aspx + [Fact(Skip = "not supported")] + public void Entities_TakeWhile() { - // Not supported : https://msdn.microsoft.com/en-in/library/bb738474%28en-us%29.aspx - [Fact(Skip = "not supported")] - public void Entities_TakeWhile() - { - //Arrange - const int total = 33; - PopulateTestData(total, 0); + // Arrange + const int total = 33; - //Act - var expected = _context.Blogs.OrderBy(b => b.BlogId).TakeWhile(b => b.BlogId > 5).ToArray(); - var result = _context.Blogs.OrderBy("BlogId").TakeWhile("b.BlogId > 5").ToDynamicArray(); + // Act + var expected = _context.Blogs.OrderBy(b => b.BlogId).TakeWhile(b => b.BlogId > 5).ToArray(); + var result = _context.Blogs.OrderBy("BlogId").TakeWhile("b.BlogId > 5").ToDynamicArray(); - //Assert - Assert.Equal(expected, result); - } + // Assert + Assert.Equal(expected, result); } } \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs index 4c92d389..f29fde4e 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.cs @@ -36,11 +36,6 @@ public EntitiesTests(EntitiesTestsDatabaseFixture fixture) InternalPopulateTestData(); } - private void PopulateTestData(int blogCount = 25, int postCount = 10) - { - // Dummy method to make the code compile - } - private void InternalPopulateTestData() { if (_context.Blogs.Any()) diff --git a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs index 16855fad..32b75f85 100644 --- a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs +++ b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Contains.cs @@ -1,63 +1,23 @@ -using System.Collections; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq.Dynamic.Core.Tests.Helpers.Models; -using System.Reflection; using Xunit; -namespace System.Linq.Dynamic.Core.Tests +namespace System.Linq.Dynamic.Core.Tests; + +public partial class QueryableTests { - public partial class QueryableTests + [Fact] + public void Contains_Dynamic_ListWithStrings() { - [Fact] - public void Contains_Dynamic_ListWithStrings() - { - // Arrange - var baseQuery = User.GenerateSampleModels(100).AsQueryable(); - var list = new List { "User1", "User5", "User10" }; - - // Act - var realQuery = baseQuery.Where(x => list.Contains(x.UserName)).Select(x => x.Id); - var testQuery = baseQuery.Where("@0.Contains(UserName)", list).Select("Id"); - - // Assert - Assert.Equal(realQuery.ToArray(), testQuery.Cast().ToArray()); - } - -#if NET48 || NET5_0 || NET6_0_OR_GREATER - [Fact] - [Trait("Issue", "130")] - public void Contains_Dynamic_ListWithDynamicObjects() - { - // Arrange - var baseQuery = User.GenerateSampleModels(100).AsQueryable(); - var list = new List { new { UserName = "User1" } }; - - var keyType = DynamicClassFactory.CreateType(new[] - { - new DynamicProperty($"Test{Guid.NewGuid().ToString().Replace("-", "")}Test", typeof(string)), - new DynamicProperty("UserName", typeof(string)) - }); - var keyVals = (IList)CreateGenericInstance(typeof(List<>), new[] { keyType }); - - var keyVal = Activator.CreateInstance(keyType); - keyType.GetProperty("UserName").SetValue(keyVal, "User1"); - keyVals.Add(keyVal); - - // Act - var realQuery = baseQuery.Where(x => list.Contains(new { UserName = x.UserName })).Select(x => x.Id); - var testQuery = baseQuery.Where("@0.Contains(new(it.UserName as UserName))", keyVals).Select("Id"); - - // Assert - Assert.Equal(realQuery.ToArray(), testQuery.Cast().ToArray()); - } + // Arrange + var baseQuery = User.GenerateSampleModels(100).AsQueryable(); + var list = new List { "User1", "User5", "User10" }; - private static object CreateGenericInstance(Type type, Type[] typeArguments, params dynamic[] ctorParams) - { - var genType = type.MakeGenericType(typeArguments); + // Act + var realQuery = baseQuery.Where(x => list.Contains(x.UserName)).Select(x => x.Id); + var testQuery = baseQuery.Where("@0.Contains(UserName)", list).Select("Id"); - var constructor = genType.GetConstructors().First(); - return constructor.Invoke(ctorParams); - } -#endif + // Assert + Assert.Equal(realQuery.ToArray(), testQuery.Cast().ToArray()); } -} +} \ No newline at end of file From 9eaa5b7ad70de43b49f0cd919667632b86fd8da3 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 08:11:46 +0200 Subject: [PATCH 13/22] Linux - no461 --- .github/workflows/ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49428caf..e31bce33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,8 +55,4 @@ jobs: - name: Run Tests EFCore net6.0 run: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci - - - name: Run Tests EF net461 - run: | - dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci \ No newline at end of file + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci \ No newline at end of file From 660a79c9f6e607f9b4036fddb07a1d84628608df Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 08:17:38 +0200 Subject: [PATCH 14/22] net8.0 / UseInMemory: 'true' --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e31bce33..765b6572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,13 @@ jobs: env: IsRunningOnGitHubActions: 'true' - UseInMemory: 'true' steps: - uses: actions/checkout@v4 - name: Build + env: + UseInMemory: 'true' run: | dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci From 234d55afb449ac0f002d9807ae4afab85db024a1 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 08:25:38 +0200 Subject: [PATCH 15/22] UseInMemory: 'true' --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 765b6572..5018e7dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,12 +13,12 @@ jobs: - uses: actions/checkout@v4 - name: Build - env: - UseInMemory: 'true' run: | dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci - name: Run Tests EFCore net8.0 + env: + UseInMemory: 'true' run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci @@ -35,7 +35,7 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: actions/setup-dotnet@v3 + - uses: actions/setup-dotnet@v4 with: dotnet-version: | 6.0.x From e97678b478a27dd000ae04120041d307d67d401a Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 08:35:55 +0200 Subject: [PATCH 16/22] remove net461 --- .github/workflows/ci.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5018e7dd..16712013 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,10 +4,12 @@ on: [push] jobs: build_and_test_Windows: + name: Build and run Tests on Windows runs-on: windows-latest env: IsRunningOnGitHubActions: 'true' + UseInMemory: 'true' steps: - uses: actions/checkout@v4 @@ -17,16 +19,11 @@ jobs: dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci - name: Run Tests EFCore net8.0 - env: - UseInMemory: 'true' run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci - - name: Run Tests EF net461 - run: | - dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci - build_and_test_Linux: + name: Build and run Tests on Linux runs-on: ubuntu-latest env: @@ -56,4 +53,8 @@ jobs: - name: Run Tests EFCore net6.0 run: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci \ No newline at end of file + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci + + # - name: Run Tests EF net461 + # run: | + # dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci \ No newline at end of file From 46d5186f40f7e9257aa6fcea4310f00a4c95183e Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 09:15:02 +0200 Subject: [PATCH 17/22] EF --- .github/workflows/ci.yml | 10 ++++----- .../EntityFramework.DynamicLinq.Tests.csproj | 21 ++++++++++++++----- ...System.Linq.Dynamic.Core.Tests.Net5.csproj | 2 +- ...System.Linq.Dynamic.Core.Tests.Net6.csproj | 2 +- ...System.Linq.Dynamic.Core.Tests.Net7.csproj | 2 +- ...System.Linq.Dynamic.Core.Tests.Net8.csproj | 2 +- .../DynamicExpressionParserTests.cs | 18 +++++++--------- .../EntitiesTests.Cast.cs | 2 +- .../QueryableTests.Select.cs | 2 +- .../System.Linq.Dynamic.Core.Tests.csproj | 2 +- .../TestHelpers/ExpressionString.cs | 2 +- 11 files changed, 36 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16712013..43f72027 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,10 @@ jobs: run: | dotnet build ./src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.csproj -c Release -p:buildType=azure-pipelines-ci + - name: Run Tests EF net8.0 + run: | + dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net8.0 -p:buildType=azure-pipelines-ci + - name: Run Tests EFCore net8.0 run: | dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci @@ -53,8 +57,4 @@ jobs: - name: Run Tests EFCore net6.0 run: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci - - # - name: Run Tests EF net461 - # run: | - # dotnet test ./test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj -c Release -f net461 -p:buildType=azure-pipelines-ci \ No newline at end of file + dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj -c Release -p:buildType=azure-pipelines-ci \ No newline at end of file diff --git a/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj b/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj index 48a6c721..132074f7 100644 --- a/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj +++ b/test/EntityFramework.DynamicLinq.Tests/EntityFramework.DynamicLinq.Tests.csproj @@ -2,7 +2,7 @@ Stef Heyenrath - net461 + net461;net8.0 10 EF;NET461 EntityFramework.DynamicLinq.Tests @@ -42,19 +42,30 @@ - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + + + + + + + $(DefineConstants);AspNetCoreIdentity + + \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj b/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj index 85adbca7..750d3c6a 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net5/System.Linq.Dynamic.Core.Tests.Net5.csproj @@ -8,7 +8,7 @@ True ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk false - $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1 + $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1;AspNetCoreIdentity diff --git a/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj b/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj index 926ecaa8..f1213b12 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net6/System.Linq.Dynamic.Core.Tests.Net6.csproj @@ -7,7 +7,7 @@ True ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk false - $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1 + $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1;AspNetCoreIdentity diff --git a/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj b/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj index 8c15b8f2..f4d5376c 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net7/System.Linq.Dynamic.Core.Tests.Net7.csproj @@ -8,7 +8,7 @@ ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk false enable - $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1 + $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1;AspNetCoreIdentity diff --git a/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj b/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj index 64b23118..a77e17e2 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj @@ -8,7 +8,7 @@ ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk false enable - $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1 + $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1;AspNetCoreIdentity diff --git a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs index 64536139..4c4a9ee0 100644 --- a/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs +++ b/test/System.Linq.Dynamic.Core.Tests/DynamicExpressionParserTests.cs @@ -394,8 +394,8 @@ public void DynamicExpressionParser_ParseLambda_UseParameterizedNamesInDynamicQu var queriedPropType = queriedProp.PropertyType; var queriedPropUnderlyingType = Nullable.GetUnderlyingType(queriedPropType); - Check.That(expressionAsString).IsEqualTo($"Param_0 => (Param_0.{propName} == {ExpressionString.NullableConversion($"value(System.Linq.Dynamic.Core.Parser.WrappedValue`1[{queriedPropUnderlyingType}]).Value")})"); - dynamic constantExpression = (ConstantExpression)((MemberExpression)((UnaryExpression)((BinaryExpression)expression.Body).Right).Operand).Expression; + expressionAsString.Should().StartWith($"Param_0 => (Param_0.{propName}").And.Contain($"System.Linq.Dynamic.Core.Parser.WrappedValue`1[{queriedPropUnderlyingType}])"); + dynamic constantExpression = (ConstantExpression)((MemberExpression)((UnaryExpression)((BinaryExpression)expression.Body).Right).Operand).Expression!; object wrapperObj = constantExpression.Value; var propertyInfo = wrapperObj.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public)!; @@ -439,8 +439,6 @@ public void DynamicExpressionParser_ParseLambda_WithStructWithEquality(string qu [InlineData("BooleanVariable1 || BooleanVariable4", true)] public void DynamicExpressionParser_ParseLambda_WithStruct_UsingOperators(string query, bool expectedResult) { - var x = new BooleanVariable(true) && new BooleanVariable(false); - // Assign var model = new { @@ -493,8 +491,7 @@ public void DynamicExpressionParser_ParseLambda_Complex_1() }; // Act - var query = - "Users.GroupBy(x => new { x.Profile.Age }).OrderBy(gg => gg.Key.Age).Select(j => new (j.Key.Age, j.Sum(k => k.Income) As TotalIncome))"; + var query = "Users.GroupBy(x => new { x.Profile.Age }).OrderBy(gg => gg.Key.Age).Select(j => new (j.Key.Age, j.Sum(k => k.Income) As TotalIncome))"; var expression = DynamicExpressionParser.ParseLambda(null, query, externals); var del = expression.Compile(); var result = del.DynamicInvoke() as IEnumerable; @@ -518,8 +515,7 @@ public void DynamicExpressionParser_ParseLambda_Complex_2() var qry = testList.AsQueryable(); // Act - var query = - "GroupBy(x => new { x.Profile.Age }, it).OrderBy(gg => gg.Key.Age).Select(j => new (j.Key.Age, j.Sum(k => k.Income) As TotalIncome))"; + var query = "GroupBy(x => new { x.Profile.Age }, it).OrderBy(gg => gg.Key.Age).Select(j => new (j.Key.Age, j.Sum(k => k.Income) As TotalIncome))"; var expression = DynamicExpressionParser.ParseLambda(qry.GetType(), null, query); var del = expression.Compile(); var result = del.DynamicInvoke(qry) as IEnumerable; @@ -1781,7 +1777,7 @@ public void DynamicExpressionParser_ParseLambda_NullPropagation_InstanceMethod_0 var lambdaExpression = DynamicExpressionParser.ParseLambda(config, typeof(Foo), null, expression, new Foo()); // Assert -#if NETCOREAPP3_1 +#if NETCOREAPP3_1_OR_GREATER || NET6_0_OR_GREATER lambdaExpression.ToString().Should().Be("Param_0 => IIF((((Param_0 != null) AndAlso (Param_0.FooValue != null)) AndAlso (Param_0.FooValue.Zero() != null)), Convert(Param_0.FooValue.Zero().Length, Nullable`1), null)"); #else lambdaExpression.ToString().Should().Be("Param_0 => IIF((((Param_0 != null) AndAlso (Param_0.FooValue != null)) AndAlso (Param_0.FooValue.Zero() != null)), Convert(Param_0.FooValue.Zero().Length), null)"); @@ -1804,7 +1800,7 @@ public void DynamicExpressionParser_ParseLambda_NullPropagation_InstanceMethod_1 var lambdaExpression = DynamicExpressionParser.ParseLambda(config, typeof(Foo), null, expression, new Foo()); // Assert -#if NETCOREAPP3_1 +#if NETCOREAPP3_1_OR_GREATER || NET6_0_OR_GREATER lambdaExpression.ToString().Should().Be("Param_0 => IIF((((Param_0 != null) AndAlso (Param_0.FooValue != null)) AndAlso (Param_0.FooValue.One(1) != null)), Convert(Param_0.FooValue.One(1).Length, Nullable`1), null)"); #else lambdaExpression.ToString().Should().Be("Param_0 => IIF((((Param_0 != null) AndAlso (Param_0.FooValue != null)) AndAlso (Param_0.FooValue.One(1) != null)), Convert(Param_0.FooValue.One(1).Length), null)"); @@ -1827,7 +1823,7 @@ public void DynamicExpressionParser_ParseLambda_NullPropagation_InstanceMethod_2 var lambdaExpression = DynamicExpressionParser.ParseLambda(config, typeof(Foo), null, expression, new Foo()); // Assert -#if NETCOREAPP3_1 +#if NETCOREAPP3_1_OR_GREATER || NET6_0_OR_GREATER lambdaExpression.ToString().Should().Be("Param_0 => IIF((((Param_0 != null) AndAlso (Param_0.FooValue != null)) AndAlso (Param_0.FooValue.Two(1, 42) != null)), Convert(Param_0.FooValue.Two(1, 42).Length, Nullable`1), null)"); #else lambdaExpression.ToString().Should().Be("Param_0 => IIF((((Param_0 != null) AndAlso (Param_0.FooValue != null)) AndAlso (Param_0.FooValue.Two(1, 42) != null)), Convert(Param_0.FooValue.Two(1, 42).Length), null)"); diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs index 008752c5..7663ca2d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs @@ -6,7 +6,7 @@ namespace System.Linq.Dynamic.Core.Tests; public partial class EntitiesTests { // https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/577 -#if NET6_0_OR_GREATER +#if EF_CORE [Fact] public void Entities_Cast_To_FromStringToInt() { diff --git a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs index 6df5959c..8c04538a 100644 --- a/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/QueryableTests.Select.cs @@ -9,7 +9,7 @@ using Xunit; using NFluent; using Newtonsoft.Json.Linq; -#if EFCORE +#if AspNetCoreIdentity using Microsoft.AspNetCore.Identity; #else using Microsoft.AspNet.Identity.EntityFramework; diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index 432130dc..c0527b85 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -8,7 +8,7 @@ enable ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk {912FBF24-3CAE-4A50-B5EA-E525B9FAEC80} - $(DefineConstants);EFCORE;EFCORE_3X + $(DefineConstants);EFCORE;EFCORE_3X;AspNetCoreIdentity diff --git a/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs b/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs index 995f02b1..a55e7ff0 100644 --- a/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs +++ b/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs @@ -4,7 +4,7 @@ public static class ExpressionString { public static string NullableConversion(string convertedExpr) { -#if NET461 || NET48 +#if NET461 return $"Convert({convertedExpr})"; #else return $"Convert({convertedExpr}, Nullable`1)"; From 39628a83f68ff5ce451bf1451cd8596bab9790d5 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 09:26:50 +0200 Subject: [PATCH 18/22] -- --- .../Properties/debugSettings.json | 3 - .../SqlFunctionsTests.cs | 136 ------------------ 2 files changed, 139 deletions(-) delete mode 100644 test/System.Linq.Dynamic.Core.Tests/Properties/debugSettings.json delete mode 100644 test/System.Linq.Dynamic.Core.Tests/SqlFunctionsTests.cs diff --git a/test/System.Linq.Dynamic.Core.Tests/Properties/debugSettings.json b/test/System.Linq.Dynamic.Core.Tests/Properties/debugSettings.json deleted file mode 100644 index a44fad34..00000000 --- a/test/System.Linq.Dynamic.Core.Tests/Properties/debugSettings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Profiles": [] -} \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/SqlFunctionsTests.cs b/test/System.Linq.Dynamic.Core.Tests/SqlFunctionsTests.cs deleted file mode 100644 index 7e9acd4e..00000000 --- a/test/System.Linq.Dynamic.Core.Tests/SqlFunctionsTests.cs +++ /dev/null @@ -1,136 +0,0 @@ -#if DNX452 -using System.Collections; -using System.Linq.Dynamic.Core.Tests.Helpers.Entities; -using Microsoft.Data.Entity; -using Xunit; - -namespace System.Linq.Dynamic.Core.Tests -{ - /// - /// http://erikej.blogspot.nl/2014/06/entity-framework-6-and-sql-server.html - /// - public class SqlFunctionsTests : IDisposable - { - static readonly Random Rnd = new Random(5); - - BlogContext _context; - - public SqlFunctionsTests() - { - var builder = new DbContextOptionsBuilder(); - builder.UseSqlite($"Filename=SqlFunctionsTests_{Guid.NewGuid()}.db"); - //builder.UseSqlServer($"Data Source=(LocalDb)\\MSSQLLocalDB;Initial Catalog=unittestdb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|SqlFunctionsTests_{Guid.NewGuid()}.mdf"); - - _context = new BlogContext(builder.Options); - _context.Database.EnsureDeleted(); - _context.Database.EnsureCreated(); - //_context.EnableLogging(); - } - - // Use TestCleanup to run code after each test has run - public void Dispose() - { - _context.Database.EnsureDeleted(); - _context.Dispose(); - _context = null; - } - - void PopulateTestData(int blogCount = 25, int postCount = 10) - { - for (int i = 0; i < blogCount; i++) - { - var blog = new Blog { Name = "Blog" + (i + 1), Created = DateTime.Today.AddDays(-Rnd.Next(0, 100)) }; - - _context.Blogs.Add(blog); - - for (int j = 0; j < postCount; j++) - { - var post = new Post - { - Blog = blog, - Title = $"Blog {i + 1} - Post {j + 1}", - Content = "My Content", - PostDate = DateTime.Today.AddDays(-Rnd.Next(0, 100)).AddSeconds(Rnd.Next(0, 30000)), - NumberOfReads = Rnd.Next(0, 5000) - }; - - _context.Posts.Add(post); - } - } - - _context.SaveChanges(); - } - - [Fact] - public void SqlFunctions_Math_PI() - { - //Arrange - PopulateTestData(1, 0); - - var expected = _context.Blogs.Select(x => new { x.Name, p = x.BlogId + Math.PI }).First(); - - //Act - var test = _context.Blogs.Select("new (Name, BlogId + Math.PI as p)").ToDynamicArray().First(); - - //Assert - Assert.Equal(expected.Name, test.Name); - Assert.Equal(expected.p, test.p, 10); - } - - //[Fact] - public void SqlFunctions_DateAdd() - { - //Arrange - PopulateTestData(1, 0); - - var expected = _context.Blogs.Select(x => new { x.Name, c = x.Created.AddDays(1) }).First(); - - try - { - //System.Data.Objects.EntityFunctions.AddDays(DateTime.Now, 1); - System.Data.Entity.Core.Objects.EntityFunctions.AddDays(DateTime.Now, 1); - - //System.Data.Objects.SqlClient.SqlFunctions.DateAdd("day", 1, DateTime.Now); - System.Data.Entity.DbFunctions.AddDays(DateTime.Now, 1); - System.Data.Entity.SqlServer.SqlFunctions.DateAdd("day", 1, DateTime.Now); - } - catch - { - } - - //Act - //var test = _context.Blogs.Select("new (Name, DbFunctions.AddDays(Created, 1) as c)").ToDynamicArray().First(); - //var test2 = _context.Blogs.Select("new (Name, SqlFunctions.DateAdd(\"day\", 1, Created) as c)").ToDynamicArray().First(); - var test = _context.Blogs.Select("new (Name, EntityFunctions.AddDays(Created, 1) as c)").ToDynamicArray().First(); - - //Assert - Assert.Equal(expected.Name, test.Name); - Assert.Equal(expected.c, test.c); - } - - //[Fact] - public void SqlFunctions_StringConvert() - { - //Arrange - PopulateTestData(1, 0); - - const string search = "1"; - var expected = _context.Blogs.Where(b => System.Data.Entity.SqlServer.SqlFunctions.StringConvert((double)b.BlogId).Contains(search)).ToList(); - - try - { - System.Data.Entity.SqlServer.SqlFunctions.StringConvert(1d); - } - catch - { - } - - //Act - var result = _context.Blogs.Where("System.Data.Entity.SqlServer.SqlFunctions.StringConvert((double) BlogId).Contains(@0)", search).ToDynamicList(); - - //Assert - Assert.Equal(expected, result); - } - } -} -#endif \ No newline at end of file From 8f5d3034ef7eeb06d76584ab4798c31cef4db014 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 09:38:36 +0200 Subject: [PATCH 19/22] test projects --- .github/workflows/ci.yml | 4 +- System.Linq.Dynamic.Core.sln | 38 ++++++------- ...nq.Dynamic.Core.Tests.NetCoreApp31.csproj} | 55 +++++++++--------- .../System.Linq.Dynamic.Core.Tests.csproj | 57 +++++++------------ 4 files changed, 72 insertions(+), 82 deletions(-) rename test/{System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj => System.Linq.Dynamic.Core.Tests.NetCoreApp31/System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj} (58%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43f72027..5f56b1c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Run Tests EFCore net8.0 run: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci + dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -p:buildType=azure-pipelines-ci build_and_test_Linux: name: Build and run Tests on Linux @@ -49,7 +49,7 @@ jobs: - name: Run Tests EFCore net8.0 run: | - dotnet test ./test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj -c Release -p:buildType=azure-pipelines-ci + dotnet test ./test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj -c Release -p:buildType=azure-pipelines-ci - name: Run Tests EFCore net7.0 run: | diff --git a/System.Linq.Dynamic.Core.sln b/System.Linq.Dynamic.Core.sln index e9aacb69..50f7cb4b 100644 --- a/System.Linq.Dynamic.Core.sln +++ b/System.Linq.Dynamic.Core.sln @@ -124,8 +124,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Te EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8", "src\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8\Microsoft.EntityFrameworkCore.DynamicLinq.EFCore8.csproj", "{9000129D-322D-4FE6-9C47-75464577C374}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Tests.Net8", "test\System.Linq.Dynamic.Core.Tests.Net8\System.Linq.Dynamic.Core.Tests.Net8.csproj", "{ABB1BF71-8927-49BB-99F3-70BCB2CD161E}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RadzenDataGrid.BlazorApp", "src-blazor\RadzenDataGrid.BlazorApp\RadzenDataGrid.BlazorApp.csproj", "{51074A4C-15C2-4E72-81F2-2FC53903553B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleApp_net6.0_EF6_Sqlite", "src-console\ConsoleAppEF6_Sqlite\ConsoleApp_net6.0_EF6_Sqlite.csproj", "{CA03FD55-9DAB-4827-9A35-A96D3804B311}" @@ -145,6 +143,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Host", "src-console\De EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo.Plugin", "src-console\Demo.Plugin\Demo.Plugin.csproj", "{B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Linq.Dynamic.Core.Tests.NetCoreApp31", "test\System.Linq.Dynamic.Core.Tests.NetCoreApp31\System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj", "{7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -769,22 +769,6 @@ Global {9000129D-322D-4FE6-9C47-75464577C374}.Release|x64.Build.0 = Release|Any CPU {9000129D-322D-4FE6-9C47-75464577C374}.Release|x86.ActiveCfg = Release|Any CPU {9000129D-322D-4FE6-9C47-75464577C374}.Release|x86.Build.0 = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|ARM.ActiveCfg = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|ARM.Build.0 = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|x64.ActiveCfg = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|x64.Build.0 = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|x86.ActiveCfg = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Debug|x86.Build.0 = Debug|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|Any CPU.Build.0 = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|ARM.ActiveCfg = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|ARM.Build.0 = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|x64.ActiveCfg = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|x64.Build.0 = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|x86.ActiveCfg = Release|Any CPU - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E}.Release|x86.Build.0 = Release|Any CPU {51074A4C-15C2-4E72-81F2-2FC53903553B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {51074A4C-15C2-4E72-81F2-2FC53903553B}.Debug|Any CPU.Build.0 = Debug|Any CPU {51074A4C-15C2-4E72-81F2-2FC53903553B}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -897,6 +881,22 @@ Global {B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x64.Build.0 = Release|Any CPU {B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x86.ActiveCfg = Release|Any CPU {B01B327C-FC68-49B6-BDE3-A13D0C66DF5C}.Release|x86.Build.0 = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|ARM.ActiveCfg = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|ARM.Build.0 = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|x64.ActiveCfg = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|x64.Build.0 = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|x86.ActiveCfg = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Debug|x86.Build.0 = Debug|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|Any CPU.Build.0 = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|ARM.ActiveCfg = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|ARM.Build.0 = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x64.ActiveCfg = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x64.Build.0 = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x86.ActiveCfg = Release|Any CPU + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -940,7 +940,6 @@ Global {FB2F4C99-EC34-4D29-87E2-944B25D90EF7} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F} {CC63ECEB-18C1-462B-BAFC-7F146A7C2740} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38} {9000129D-322D-4FE6-9C47-75464577C374} = {DBD7D9B6-FCC7-4650-91AF-E6457573A68F} - {ABB1BF71-8927-49BB-99F3-70BCB2CD161E} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38} {51074A4C-15C2-4E72-81F2-2FC53903553B} = {122BC4FA-7563-4E35-9D17-077F16F1629F} {CA03FD55-9DAB-4827-9A35-A96D3804B311} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62} {E36D1A08-F3ED-48C7-9DBF-8F625974A6C4} = {BCA2A024-9032-4E56-A6C4-17A15D921728} @@ -948,6 +947,7 @@ Global {68C7FF71-54F6-4D68-B419-65D1B10206D4} = {BCA2A024-9032-4E56-A6C4-17A15D921728} {D8368319-F370-4071-9411-A3DADB234330} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62} {B01B327C-FC68-49B6-BDE3-A13D0C66DF5C} = {7971CAEB-B9F2-416B-966D-2D697C4C1E62} + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616} = {8463ED7E-69FB-49AE-85CF-0791AFD98E38} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {94C56722-194E-4B8B-BC23-B3F754E89A20} diff --git a/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj b/test/System.Linq.Dynamic.Core.Tests.NetCoreApp31/System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj similarity index 58% rename from test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj rename to test/System.Linq.Dynamic.Core.Tests.NetCoreApp31/System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj index a77e17e2..ad978803 100644 --- a/test/System.Linq.Dynamic.Core.Tests.Net8/System.Linq.Dynamic.Core.Tests.Net8.csproj +++ b/test/System.Linq.Dynamic.Core.Tests.NetCoreApp31/System.Linq.Dynamic.Core.Tests.NetCoreApp31.csproj @@ -1,47 +1,49 @@ - - + - net8.0 + Stef Heyenrath + netcoreapp3.1 System.Linq.Dynamic.Core.Tests full True - ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk - false enable - $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1;AspNetCoreIdentity + ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk + {7AFC2836-0F6E-4B0D-8BB3-13317A3B6616} + $(DefineConstants);EFCORE;EFCORE_3X;AspNetCoreIdentity - + + all - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers - - - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + all + runtime; build; native; contentfiles; analyzers - - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers + - - - - - - - - - + - - + + + + + + @@ -49,4 +51,5 @@ - + + \ No newline at end of file diff --git a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj index c0527b85..0275848d 100644 --- a/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj +++ b/test/System.Linq.Dynamic.Core.Tests/System.Linq.Dynamic.Core.Tests.csproj @@ -1,59 +1,46 @@  - Stef Heyenrath - netcoreapp3.1 + net8.0 System.Linq.Dynamic.Core.Tests full True - enable ../../src/System.Linq.Dynamic.Core/System.Linq.Dynamic.Core.snk - {912FBF24-3CAE-4A50-B5EA-E525B9FAEC80} - $(DefineConstants);EFCORE;EFCORE_3X;AspNetCoreIdentity + false + enable + $(DefineConstants);NETCOREAPP;EFCORE;EFCORE_3X;NETCOREAPP3_1;AspNetCoreIdentity - - + all - runtime; build; native; contentfiles; analyzers + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - runtime; build; native; contentfiles; analyzers - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - runtime; build; native; contentfiles; analyzers - - - - - + + - + + + + + + + - - - - - - + \ No newline at end of file From 0c4f99b328708472eef88ce40a2e1e7d6e2a120c Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 13:25:16 +0200 Subject: [PATCH 20/22] --- --- .../DynamicExpressionArgument.cs | 35 ------------------- .../Extensions/ExpandObjectExtensions.cs | 25 ------------- .../Extensions/LinqExtensions.cs | 6 ---- 3 files changed, 66 deletions(-) delete mode 100644 src/System.Linq.Dynamic.Core/DynamicExpressionArgument.cs delete mode 100644 src/System.Linq.Dynamic.Core/Extensions/ExpandObjectExtensions.cs diff --git a/src/System.Linq.Dynamic.Core/DynamicExpressionArgument.cs b/src/System.Linq.Dynamic.Core/DynamicExpressionArgument.cs deleted file mode 100644 index c51fca39..00000000 --- a/src/System.Linq.Dynamic.Core/DynamicExpressionArgument.cs +++ /dev/null @@ -1,35 +0,0 @@ -//using System.Linq.Expressions; - -//namespace System.Linq.Dynamic.Core -//{ -// /// -// /// DynamicExpressionArgument -// /// -// public class DynamicExpressionArgument -// { -// /// -// /// If set to true then also create a constructor for all the parameters. Note that this doesn't work for Linq-to-Database entities. -// /// -// public bool CreateParameterCtor { get; set; } - -// /// -// /// Parameters -// /// -// public ParameterExpression[] Parameters { get; set; } - -// /// -// /// ResultType -// /// -// public Type ResultType { get; set; } - -// /// -// /// Expression -// /// -// public string Expression { get; set; } - -// /// -// /// Values -// /// -// public object[] Values { get; set; } -// } -//} \ No newline at end of file diff --git a/src/System.Linq.Dynamic.Core/Extensions/ExpandObjectExtensions.cs b/src/System.Linq.Dynamic.Core/Extensions/ExpandObjectExtensions.cs deleted file mode 100644 index 5b2ea6a7..00000000 --- a/src/System.Linq.Dynamic.Core/Extensions/ExpandObjectExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -//#if !(NET35 || UAP10_0) -//using System.Dynamic; -//using System.Reflection; -//using JetBrains.Annotations; - -//namespace System.Linq.Dynamic.Core.Extensions -//{ -// public static class ExpandObjectExtensions -// { -// public static DynamicClass ToDynamicClass([NotNull] this object obj, bool createParameterCtor = true) -// { -// var propertyInfo = obj.GetType().GetProperties(); -// var dynamicProperties = propertyInfo.Select(p => new DynamicProperty(p.Name, p.PropertyType)).ToList(); - -// Type type = DynamicClassFactory.CreateType(dynamicProperties, createParameterCtor); -// var dynamicClass = (DynamicClass) Activator.CreateInstance(type); - -// foreach (var kvp in obj) -// dynamicClass.SetDynamicPropertyValue(kvp.Key, kvp.Value); - -// return dynamicClass; -// } -// } -//} -//#endif \ No newline at end of file diff --git a/src/System.Linq.Dynamic.Core/Extensions/LinqExtensions.cs b/src/System.Linq.Dynamic.Core/Extensions/LinqExtensions.cs index c68ffee3..dc563fa8 100644 --- a/src/System.Linq.Dynamic.Core/Extensions/LinqExtensions.cs +++ b/src/System.Linq.Dynamic.Core/Extensions/LinqExtensions.cs @@ -7,12 +7,6 @@ namespace System.Linq.Dynamic.Core.Extensions; [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] internal static class LinqExtensions { - // Ex: collection.TakeLast(5); - public static IEnumerable TakeLast(this IList source, int n) - { - return source.Skip(Math.Max(0, source.Count() - n)); - } - public static IEnumerable WhereNotNull(this IEnumerable sequence) { Check.NotNull(sequence); From 8e31b5bac3be4472f370bcfe5a5d999170437558 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Mon, 17 Jun 2024 20:24:09 +0200 Subject: [PATCH 21/22] - --- .../TestHelpers/ExpressionString.cs | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs diff --git a/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs b/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs deleted file mode 100644 index a55e7ff0..00000000 --- a/test/System.Linq.Dynamic.Core.Tests/TestHelpers/ExpressionString.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace System.Linq.Dynamic.Core.Tests.TestHelpers -{ - public static class ExpressionString - { - public static string NullableConversion(string convertedExpr) - { -#if NET461 - return $"Convert({convertedExpr})"; -#else - return $"Convert({convertedExpr}, Nullable`1)"; -#endif - } - } -} \ No newline at end of file From a32ae63fa881f82bacdf7d4abd9abde84c381f26 Mon Sep 17 00:00:00 2001 From: Stef Heyenrath Date: Tue, 18 Jun 2024 13:48:07 +0200 Subject: [PATCH 22/22] x --- .../EntitiesTests.All.cs | 1 - .../EntitiesTests.Cast.cs | 2 +- .../EntitiesTests.Count.cs | 3 +-- .../EntitiesTests.Select.cs | 10 +++++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs index 900652b4..f0e21235 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.All.cs @@ -5,7 +5,6 @@ using System.Data.Entity; using EntityFramework.DynamicLinq; #endif -using System.Threading.Tasks; using Xunit; namespace System.Linq.Dynamic.Core.Tests; diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs index 7663ca2d..97292197 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Cast.cs @@ -6,7 +6,7 @@ namespace System.Linq.Dynamic.Core.Tests; public partial class EntitiesTests { // https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/577 -#if EF_CORE +#if EFCORE [Fact] public void Entities_Cast_To_FromStringToInt() { diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs index 6f7b8dd2..3c4be938 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Count.cs @@ -1,5 +1,4 @@ -using System.Linq.Dynamic.Core.Tests.Helpers.Entities; -using Xunit; +using Xunit; namespace System.Linq.Dynamic.Core.Tests; diff --git a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs index ccba384e..df4cf56e 100644 --- a/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs +++ b/test/System.Linq.Dynamic.Core.Tests/EntitiesTests.Select.cs @@ -1,7 +1,5 @@ using System.Collections; using System.Linq.Dynamic.Core.Exceptions; -using System.Linq.Dynamic.Core.Tests.Helpers.Entities; -using FluentAssertions; using Newtonsoft.Json; #if EFCORE using Microsoft.EntityFrameworkCore; @@ -88,7 +86,7 @@ public void Entities_Select_MultipleColumn() //Assert Assert.Equal( expected, - test.Select(x => new { X = "x", BlogId = (int)x.BlogId, Name = (string)x.Name }).ToArray() //convert to same anomymous type used by expected so they can be found equal + test.Select(x => new { X = "x", BlogId = (int)x.BlogId, Name = (string)x.Name }).ToArray() // Convert to same anonymous type used by expected, so they can be found equal. ); } @@ -130,13 +128,15 @@ public void Entities_Select_BlogAndPosts() } } - [Fact(Skip = "593 - this does not work")] + /// + /// #593 + /// + [Fact] public void Entities_Select_DynamicClass_And_Call_Any() { // Act var result = _context.Blogs .Select("new (BlogId, Name)") - .Cast() .Any("Name == \"Blog2\""); // Assert