From e1100a0cf65e356a272aeb8e642deebc07d6fa2e Mon Sep 17 00:00:00 2001 From: Markus Rajahalme Date: Thu, 20 Jun 2024 08:19:24 +0300 Subject: [PATCH] Create a test to verify the bug --- ..._include_pagedlist_with_mapped_tenantid.cs | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/CoreTests/Bugs/Bug_3274_include_pagedlist_with_mapped_tenantid.cs diff --git a/src/CoreTests/Bugs/Bug_3274_include_pagedlist_with_mapped_tenantid.cs b/src/CoreTests/Bugs/Bug_3274_include_pagedlist_with_mapped_tenantid.cs new file mode 100644 index 0000000000..880940575b --- /dev/null +++ b/src/CoreTests/Bugs/Bug_3274_include_pagedlist_with_mapped_tenantid.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Marten.Pagination; +using Marten.Schema.Identity; +using Marten.Testing.Harness; +using Xunit; + +namespace CoreTests.Bugs +{ + public class Bug_3274_include_pagedlist_with_mapped_tenantid: BugIntegrationContext + { + [Fact] + public async Task multi_tenant_query_with_include_should_work() + { + StoreOptions(opts => + { + opts.Policies.AllDocumentsAreMultiTenanted(); + opts.Schema + .For() + .Metadata(a => a.TenantId.MapTo(x => x.TenantId)); + opts.Schema.For(); + }); + + var newUser = new User() + { + Id = CombGuidIdGeneration.NewGuid(), + Name = "Alex" + }; + var newDoc = new UserState(newUser.Id, "TestState"); + + var session = theStore.LightweightSession("tenant1"); + session.Store(newUser); + session.Store(newDoc); + await session.SaveChangesAsync(); + + var userDict = new Dictionary(); + + var document = await session + .Query() + .Include(x => x.Id, userDict) + .Where(a => a.Id == newUser.Id) + .ToPagedListAsync(1, 10); + + + Assert.Single(document); + Assert.Single(userDict); + + Assert.Equal(document.Single().Id, userDict.Single().Key); + } + + public record UserState(Guid Id, string State); + public class User + { + public Guid Id { get; set; } + public string Name { get; set; } + public string TenantId { get; set; } + } + } +}