Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ public virtual string SingleLineCommentToken
/// A valid name based on the candidate name.
/// </returns>
public virtual string GenerateParameterName(string name)
=> name.StartsWith("@", StringComparison.Ordinal)
? name
: "@" + name;
=> name.StartsWith('@') ? name : "@" + name;

/// <summary>
/// Writes a valid parameter name for the given candidate name.
Expand Down
4 changes: 2 additions & 2 deletions test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ protected override object GetAdditionalModelCacheKey(DbContext context)
public Task InitializeAsync()
=> Task.CompletedTask;

public Task DisposeAsync()
=> TestStore.DisposeAsync();
public async Task DisposeAsync()
=> await TestStore.DisposeAsync();
}

public record class EmbeddedTransportationContextOptions(DbContextOptions Options, Action<ModelBuilder> OnModelCreating);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,7 @@ private static async Task SeedAsync(DbContext context)
await creator.SeedDataAsync(created: true).ConfigureAwait(false);
}

public override void Dispose()
=> throw new InvalidOperationException("Calling Dispose can cause deadlocks. Use DisposeAsync instead.");

public override async Task DisposeAsync()
public override async ValueTask DisposeAsync()
{
if (_initialized
&& _dataFilePath == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,19 +288,13 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
public async Task InitializeAsync()
=> ExistingTestStore = await Fixture.CreateTestStoreAsync(SqlServerTestStoreFactory.Instance, StoreName, SeedAsync);

public Task DisposeAsync()
{
ExistingTestStore.Dispose();
return Task.CompletedTask;
}
public async Task DisposeAsync()
=> await ExistingTestStore.DisposeAsync();
}

public async Task InitializeAsync()
=> ExistingTestStore = await Fixture.CreateTestStoreAsync(SqlServerTestStoreFactory.Instance, StoreName, SeedAsync);

public Task DisposeAsync()
{
ExistingTestStore.Dispose();
return Task.CompletedTask;
}
public async Task DisposeAsync()
=> await ExistingTestStore.DisposeAsync();
}
7 changes: 2 additions & 5 deletions test/EFCore.CrossStore.FunctionalTests/EndToEndTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@ protected CrossStoreContext CreateContext()
public async Task InitializeAsync()
=> TestStore = await Fixture.CreateTestStoreAsync(TestStoreFactory, "CrossStoreTest");

public Task DisposeAsync()
{
TestStore.Dispose();
return Task.CompletedTask;
}
public async Task DisposeAsync()
=> await TestStore.DisposeAsync();
}

public class InMemoryEndToEndTest(CrossStoreFixture fixture) : EndToEndTest(fixture), IClassFixture<CrossStoreFixture>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
modelBuilder.Entity<NullSemanticsEntity2>().Property(e => e.StringC).IsRequired();

modelBuilder.HasDbFunction(
typeof(NullSemanticsQueryFixtureBase).GetMethod(nameof(Cases)),
typeof(NullSemanticsQueryFixtureBase).GetMethod(nameof(Cases))!,
b => b.HasTranslation(
args => new CaseExpression(
[
new CaseWhenClause(args[0], args[1]),
new CaseWhenClause(args[2], args[3]),
new CaseWhenClause(args[4], args[5]),
]))
);
new CaseWhenClause(args[4], args[5])
])));

modelBuilder.HasDbFunction(
typeof(NullSemanticsQueryFixtureBase).GetMethod(nameof(BoolSwitch)),
typeof(NullSemanticsQueryFixtureBase).GetMethod(nameof(BoolSwitch))!,
b => b.HasTranslation(
args => new CaseExpression(
operand: args[0],
[
new CaseWhenClause(new SqlConstantExpression(true, typeMapping: BoolTypeMapping.Default), args[1]),
new CaseWhenClause(new SqlConstantExpression(false, typeMapping: BoolTypeMapping.Default), args[2]),
]))
);
new CaseWhenClause(new SqlConstantExpression(false, typeMapping: BoolTypeMapping.Default), args[2])
])));
}

public static int? Cases(bool c1, int v1, bool c2, int v2, bool c3, int v3)
Expand All @@ -151,9 +149,5 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
null;

public static int BoolSwitch(bool x, int whenTrue, int whenFalse)
=> x switch
{
true => whenTrue,
false => whenFalse,
};
=> x ? whenTrue : whenFalse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1973,8 +1973,7 @@ public virtual Task CaseWhen_equal_to_first_or_third_select(bool async)
x.StringC == "Foo", 3
)
== 3),
assertOrder: true
);
assertOrder: true);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
Expand All @@ -1985,10 +1984,8 @@ public virtual Task CaseOpWhen_projection(bool async)
.OrderBy(x => x.Id)
.Select(
x => NullSemanticsQueryFixtureBase.BoolSwitch(
x.StringA == "Foo", 3, 2
)),
assertOrder: true
);
x.StringA == "Foo", 3, 2)),
assertOrder: true);

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public override async Task<TestStore> InitializeAsync(
return this;
}

public override void Dispose()
public override async ValueTask DisposeAsync()
{
Connection?.Dispose();
base.Dispose();
await Connection.DisposeAsync();
await base.DisposeAsync();
}

public virtual string NormalizeDelimitersInRawString(string sql)
Expand Down
9 changes: 6 additions & 3 deletions test/EFCore.Specification.Tests/MonsterFixupTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.EntityFrameworkCore;

#nullable disable

public abstract class MonsterFixupTestBase<TFixture> : IClassFixture<TFixture>, IDisposable
public abstract class MonsterFixupTestBase<TFixture> : IClassFixture<TFixture>, IAsyncLifetime
where TFixture : MonsterFixupTestBase<TFixture>.MonsterFixupFixtureBase, new()
{
protected MonsterFixupTestBase(TFixture fixture)
Expand Down Expand Up @@ -1405,8 +1405,11 @@ protected Task CreateAndSeedDatabase(Func<MonsterContext, Task> seed)
protected MonsterContext CreateContext()
=> Fixture.CreateContext(Options);

public virtual void Dispose()
=> TestStore.Dispose();
public Task InitializeAsync()
=> Task.CompletedTask;

public virtual async Task DisposeAsync()
=> await TestStore.DisposeAsync();

public abstract class MonsterFixupFixtureBase : ServiceProviderFixtureBase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ public virtual Task String_Join_with_predicate(bool async)
.Select(
g => new
{
City = g.Key, Customers = string.Join("|", g.Where(e => e.ContactName.Length > 10).Select(e => e.CustomerID))
City = g.Key,
Customers = string.Join("|", g.Where(e => e.ContactName.Length > 10).Select(e => e.CustomerID))
}),
elementSorter: x => x.City,
elementAsserter: (e, a) =>
Expand Down
4 changes: 2 additions & 2 deletions test/EFCore.Specification.Tests/SharedStoreFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ protected virtual Task CleanAsync(DbContext context)
return Task.CompletedTask;
}

public virtual Task DisposeAsync()
=> TestStore.DisposeAsync();
public virtual async Task DisposeAsync()
=> await TestStore.DisposeAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
});

modelBuilder.Entity<OrderDetail>(
e =>
{
e.HasKey(
od => new { od.OrderID, od.ProductID });
});
e => e.HasKey(od => new { od.OrderID, od.ProductID }));

modelBuilder.Entity<CustomerQuery>().HasNoKey();
modelBuilder.Entity<OrderQuery>().HasNoKey();
Expand Down
13 changes: 3 additions & 10 deletions test/EFCore.Specification.Tests/TestUtilities/TestStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.EntityFrameworkCore.TestUtilities;

public abstract class TestStore(string name, bool shared) : IDisposable
public abstract class TestStore(string name, bool shared) : IAsyncDisposable
{
private static readonly TestStoreIndex GlobalTestStoreIndex = new();
public IServiceProvider? ServiceProvider { get; protected set; }
Expand Down Expand Up @@ -83,15 +83,8 @@ protected virtual DbContext CreateDefaultContext()
protected virtual TestStoreIndex GetTestStoreIndex(IServiceProvider? serviceProvider)
=> GlobalTestStoreIndex;

public virtual void Dispose()
{
}

public virtual Task DisposeAsync()
{
Dispose();
return Task.CompletedTask;
}
public virtual ValueTask DisposeAsync()
=> default;

private static readonly SemaphoreSlim _transactionSyncRoot = new(1);

Expand Down
7 changes: 2 additions & 5 deletions test/EFCore.SqlServer.FunctionalTests/ComputedColumnTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ public void Can_use_computed_columns_with_nullable_enum()
public async Task InitializeAsync()
=> TestStore = await SqlServerTestStore.CreateInitializedAsync("ComputedColumnTest");

public Task DisposeAsync()
{
TestStore.Dispose();
return Task.CompletedTask;
}
public async Task DisposeAsync()
=> await TestStore.DisposeAsync();
}
Loading