Skip to content
Closed
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions src/CoreTests/Partitioning/partitioning_configuration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Linq;
using System.Threading.Tasks;
using Marten;
using Marten.Schema;
using Marten.Schema.Indexing.Unique;
using Marten.Storage;
Expand Down Expand Up @@ -264,4 +265,52 @@ public async Task unique_index_on_partitioned_table_can_be_applied_to_database()
// that don't include all partition columns
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();
}

[Fact]
public async Task cannot_query_within_child_collections_across_partition_tenants()
{
StoreOptions(opts =>
{
opts.Schema.For<Target>()
.MultiTenantedWithPartitioning(x =>
{
x.ByHash(Enumerable.Range(0, 2).Select(i => $"h{i:000}").ToArray());
});
});
var targetBlue1 = Target.Random();
targetBlue1.NestedObject = new([Target.Random()]);
targetBlue1.NestedObject.Targets[0].String = "not a green list";
await using (var blue = theStore.LightweightSession("Blue"))
{
blue.Store(targetBlue1);
await blue.SaveChangesAsync();
}

var targetRed1 = Target.Random();
targetRed1.NestedObject = new([Target.Random()]);
targetRed1.NestedObject.Targets[0].String = "not a green list";
await using(var blue = theStore.LightweightSession("Blue"))
{
blue.Store(targetRed1);
await blue.SaveChangesAsync();
}

await using (var red = theStore.QuerySession("Red"))
{
(await red.Query<Target>()
.Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list"))
.ToListAsync())
.ShouldHaveSingleItem()
.Id.ShouldBe(targetRed1.Id);
}

await using (var blue = theStore.QuerySession("Blue"))
{
(await blue.Query<Target>()
.Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list"))
.ToListAsync())
.ShouldHaveSingleItem()
.Id.ShouldBe(targetBlue1.Id);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using JasperFx;
using Marten;
using Marten.Linq;
using Marten.Schema;
using Marten.Storage;
using Marten.Testing;
Expand All @@ -29,6 +32,10 @@ public class conjoined_multi_tenancy_with_partitioning: OneOffConfigurationsCont
public conjoined_multi_tenancy_with_partitioning()
{

targetBlue1.NestedObject = new([Target.Random()]);
targetBlue1.NestedObject.Targets[0].String = "not a green list";
targetRed1.NestedObject = new([Target.Random()]);
targetRed1.NestedObject.Targets[0].String = "not a green list";
StoreOptions(opts =>
{
opts.Policies.AllDocumentsAreMultiTenantedWithPartitioning(x =>
Expand Down Expand Up @@ -84,6 +91,28 @@ public async Task cannot_load_by_id_across_tenants()
}
}

[Fact]
public async Task cannot_query_within_child_collections_across_tenants()
{
await using (var red = theStore.QuerySession("Red"))
{
(await red.Query<Target>()
.Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list"))
.ToListAsync())
.ShouldHaveSingleItem()
.Id.ShouldBe(targetRed1.Id);
}

await using (var blue = theStore.QuerySession("Blue"))
{
(await blue.Query<Target>()
.Where(x => x.NestedObject.Targets.Any(i => i.String != null && i.String == "not a green list"))
.ToListAsync())
.ShouldHaveSingleItem()
.Id.ShouldBe(targetBlue1.Id);
}
}

[Fact]
public async Task cannot_load_json_by_id_across_tenants_async()
{
Expand Down