Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include PagedList with mapped TenantId #3275

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<User>()
.Metadata(a => a.TenantId.MapTo(x => x.TenantId));
opts.Schema.For<UserState>();
});

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<Guid, UserState>();

var document = await session
.Query<User>()
.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; }
}
}
}
Loading