Skip to content

Commit

Permalink
Adjust tests to the lack of a discriminator predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Jul 4, 2024
1 parent 7182f36 commit 2e69af4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ public override Expression Translate(Expression expression)
(property, parameter) => (property, parameter))
.ToDictionary(tuple => tuple.property, tuple => tuple.parameter);

// TODO: Reimplement ReadItem properly: #34157
_readItemInfo = new ReadItemInfo(entityType, propertyParameterList, clrType);
}
}
Expand Down Expand Up @@ -830,7 +831,7 @@ protected override ShapedQueryExpression TranslateCast(ShapedQueryExpression sou
return null;
}

if (select is { Predicate: null, Orderings: [] })
if (select is { Orderings: [], Predicate: null, ReadItemInfo: null })
{
_queryCompilationContext.Logger.FirstWithoutOrderByAndFilterWarning();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public sealed class SelectExpression : Expression, IPrintableExpression
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
// TODO: Reimplement ReadItem properly: #34157
public ReadItemInfo? ReadItemInfo { get; init; }

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ await context.AddAsync(
{
var customerFromStore = await context.Set<CustomerWithResourceId>()
.WithPartitionKey(pk1, 3.15m)
.FirstAsync();
.SingleAsync();

Assert.Equal("42", customerFromStore.id);
Assert.Equal("Theon Greyjoy", customerFromStore.Name);
Expand Down Expand Up @@ -1135,7 +1135,7 @@ public async Task Can_read_with_find_with_resource_id()
{
var customerFromStore = context.Set<CustomerWithResourceId>()
.WithPartitionKey(pk1, 3.15m)
.First();
.Single();

Assert.Equal("42", customerFromStore.id);
Assert.Equal("Theon Greyjoy", customerFromStore.Name);
Expand Down Expand Up @@ -1219,7 +1219,7 @@ await context.AddAsync(
{
var customerFromStore = await context.Set<Customer>()
.WithPartitionKey(pk1, "One", true)
.FirstAsync();
.SingleAsync();

Assert.Equal(42, customerFromStore.Id);
Assert.Equal("Theon Greyjoy", customerFromStore.Name);
Expand Down Expand Up @@ -1288,7 +1288,7 @@ public async Task Can_read_with_find_with_partition_key_and_value_generator()
{
var customerFromStore = context.Set<Customer>()
.WithPartitionKey(pk1, "One", true)
.First();
.Single();

Assert.Equal(42, customerFromStore.Id);
Assert.Equal("Theon Greyjoy", customerFromStore.Name);
Expand Down Expand Up @@ -1357,7 +1357,7 @@ OFFSET 0 LIMIT 1
{
var customerFromStore = context.Set<Customer>()
.WithPartitionKey(pk1, "One", true)
.First();
.Single();

Assert.Equal(42, customerFromStore.Id);
Assert.Equal("Theon Greyjoy", customerFromStore.Name);
Expand Down
16 changes: 6 additions & 10 deletions test/EFCore.Cosmos.FunctionalTests/HierarchicalPartitionKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public virtual async Task Can_add_update_delete_end_to_end_with_partition_key()
"""
SELECT c
FROM root c
WHERE (c["Discriminator"] = "Customer")
ORDER BY c["PartitionKey1"]
OFFSET 0 LIMIT 1
""";
Expand All @@ -39,7 +38,6 @@ OFFSET 0 LIMIT 1
SELECT c
FROM root c
WHERE (c["Discriminator"] = "Customer")
ORDER BY c["PartitionKey1"]
OFFSET @__p_0 LIMIT 1
""";
Expand All @@ -61,14 +59,13 @@ public virtual async Task Can_add_update_delete_end_to_end_with_with_partition_k
"""
SELECT c
FROM root c
WHERE (c["Discriminator"] = "Customer")
OFFSET 0 LIMIT 1
OFFSET 0 LIMIT 2
""";

await PartitionKeyTestAsync(
ctx => ctx.Customers.WithPartitionKey("A", 1.1, true).FirstAsync(),
ctx => ctx.Customers.WithPartitionKey("A", 1.1, true).SingleAsync(),
readSql,
ctx => ctx.Customers.WithPartitionKey("B", 2.1, false).FirstAsync(),
ctx => ctx.Customers.WithPartitionKey("B", 2.1, false).SingleAsync(),
readSql,
ctx => ctx.Customers.WithPartitionKey("B", 2.1, false).LastAsync(),
ctx => ctx.Customers.WithPartitionKey("B", 2.1, false).ToListAsync(),
Expand All @@ -82,8 +79,7 @@ public async Task Can_query_with_implicit_partition_key_filter()
"""
SELECT c
FROM root c
WHERE (c["Discriminator"] = "Customer")
OFFSET 0 LIMIT 1
OFFSET 0 LIMIT 2
""";

await PartitionKeyTestAsync(
Expand All @@ -93,15 +89,15 @@ await PartitionKeyTestAsync(
&& b.PartitionKey1 == "A"
&& b.PartitionKey2 == 1.1
&& b.PartitionKey3)
.FirstAsync(),
.SingleAsync(),
readSql,
ctx => ctx.Customers
.Where(
b => (b.Id == 42 || b.Name == "John Snow")
&& b.PartitionKey1 == "B"
&& b.PartitionKey2 == 2.1
&& !b.PartitionKey3)
.FirstAsync(),
.SingleAsync(),
readSql,
ctx => ctx.Customers.WithPartitionKey("B", 2.1, false).LastAsync(),
ctx => ctx.Customers
Expand Down
8 changes: 3 additions & 5 deletions test/EFCore.Cosmos.FunctionalTests/PartitionKeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public virtual async Task Can_add_update_delete_end_to_end_with_partition_key()
"""
SELECT c
FROM root c
WHERE (c["Discriminator"] = "Customer")
ORDER BY c["PartitionKey"]
OFFSET 0 LIMIT 1
""";
Expand All @@ -50,12 +49,11 @@ public virtual async Task Can_add_update_delete_end_to_end_with_with_partition_k
"""
SELECT c
FROM root c
WHERE (c["Discriminator"] = "Customer")
OFFSET 0 LIMIT 1
OFFSET 0 LIMIT 2
""";

await PartitionKeyTestAsync(
ctx => ctx.Customers.WithPartitionKey("1").FirstAsync(),
ctx => ctx.Customers.WithPartitionKey("1").SingleAsync(),
readSql,
ctx => ctx.Customers.WithPartitionKey("2").LastAsync(),
ctx => ctx.Customers.WithPartitionKey("2").ToListAsync(),
Expand All @@ -69,7 +67,7 @@ public async Task Can_query_with_implicit_partition_key_filter()
"""
SELECT c
FROM root c
WHERE ((c["Discriminator"] = "Customer") AND ((c["Id"] = 42) OR (c["Name"] = "John Snow")))
WHERE ((c["Id"] = 42) OR (c["Name"] = "John Snow"))
OFFSET 0 LIMIT 1
""";

Expand Down
12 changes: 7 additions & 5 deletions test/EFCore.Cosmos.FunctionalTests/ReloadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public TestSqlLoggerFactory TestSqlLoggerFactory
public class ReloadTestContext(DbContextOptions dbContextOptions) : DbContext(dbContextOptions)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
=> modelBuilder.Entity<Item>(b => b.HasPartitionKey(e => e.Id));

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
modelBuilder.Entity<Item>(
b =>
{
b.HasPartitionKey(e => e.Id);
});
base.OnConfiguring(optionsBuilder);

// TODO: Remove this after #33893 - once Reload is implemented via ReadItem, the warning shouldn't be emitted
optionsBuilder.ConfigureWarnings(w => w.Log(CoreEventId.FirstWithoutOrderByAndFilterWarning));
}

public DbSet<Item> Items { get; set; }
Expand Down

0 comments on commit 2e69af4

Please sign in to comment.