Skip to content

Commit

Permalink
Code cleanup for tests (#22187)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 23, 2020
1 parent 659ebed commit cc756cd
Show file tree
Hide file tree
Showing 750 changed files with 14,116 additions and 8,331 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace Microsoft.EntityFrameworkCore
{
public class InternalUsageDiagnosticAnalyzerTest : DiagnosticAnalyzerTestBase
{
protected override DiagnosticAnalyzer CreateDiagnosticAnalyzer() => new InternalUsageDiagnosticAnalyzer();
protected override DiagnosticAnalyzer CreateDiagnosticAnalyzer()
=> new InternalUsageDiagnosticAnalyzer();

[ConditionalFact]
public Task Invocation_on_type_in_internal_namespace()
Expand All @@ -38,14 +39,16 @@ class MyClass : Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalPara

var diagnostics = await GetDiagnosticsFullSourceAsync(source);

Assert.Collection(diagnostics,
Assert.Collection(
diagnostics,
diagnostic =>
{
Assert.Equal(InternalUsageDiagnosticAnalyzer.Id, diagnostic.Id);
Assert.Equal(DiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(
string.Format(
InternalUsageDiagnosticAnalyzer.MessageFormat, "Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalParameter"),
InternalUsageDiagnosticAnalyzer.MessageFormat,
"Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalParameter"),
diagnostic.GetMessage());
var span = diagnostic.Location.SourceSpan;
Expand All @@ -59,7 +62,8 @@ class MyClass : Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalPara
Assert.Equal(DiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(
string.Format(
InternalUsageDiagnosticAnalyzer.MessageFormat, "Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalParameter"),
InternalUsageDiagnosticAnalyzer.MessageFormat,
"Microsoft.EntityFrameworkCore.Storage.Internal.RawRelationalParameter"),
diagnostic.GetMessage());
var span = diagnostic.Location.SourceSpan;
Expand Down
30 changes: 20 additions & 10 deletions test/EFCore.Cosmos.FunctionalTests/BuiltInDataTypesCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,35 @@ private void AssertSql(params string[] expected)

public class BuiltInDataTypesCosmosFixture : BuiltInDataTypesFixtureBase
{
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
protected override ITestStoreFactory TestStoreFactory
=> CosmosTestStoreFactory.Instance;

public override bool StrictEquality => true;
public override bool StrictEquality
=> true;

public override int IntegerPrecision => 53;
public override int IntegerPrecision
=> 53;

public override bool SupportsAnsi => false;
public override bool SupportsAnsi
=> false;

public override bool SupportsUnicodeToAnsiConversion => false;
public override bool SupportsUnicodeToAnsiConversion
=> false;

public override bool SupportsLargeStringComparisons => true;
public override bool SupportsLargeStringComparisons
=> true;

public override bool SupportsBinaryKeys => true;
public override bool SupportsBinaryKeys
=> true;

public override bool SupportsDecimalComparisons => true;
public override bool SupportsDecimalComparisons
=> true;

public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;
public TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;

public override DateTime DefaultDateTime => new DateTime();
public override DateTime DefaultDateTime
=> new DateTime();

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

public class CosmosFixture : ServiceProviderFixtureBase
{
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
protected override ITestStoreFactory TestStoreFactory
=> CosmosTestStoreFactory.Instance;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public async Task Specifying_connection_string_and_account_endpoint_throws()

using var context = new BloggingContextWithConnectionConflict(testDatabase);

Assert.Equal(CosmosStrings.ConnectionStringConflictingConfiguration,
Assert.Equal(
CosmosStrings.ConnectionStringConflictingConfiguration,
Assert.Throws<InvalidOperationException>(() => context.GetService<IDatabaseCreator>()).Message);
}

Expand Down
32 changes: 25 additions & 7 deletions test/EFCore.Cosmos.FunctionalTests/CosmosConcurrencyTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.TestUtilities;
Expand All @@ -21,14 +24,22 @@ public CosmosConcurrencyTest(CosmosFixture fixture)
public virtual Task Adding_the_same_entity_twice_results_in_DbUpdateException()
{
return ConcurrencyTestAsync<DbUpdateException>(
ctx => ctx.Customers.Add(new Customer { Id = "1", Name = "CreatedTwice", }));
ctx => ctx.Customers.Add(
new Customer
{
Id = "1", Name = "CreatedTwice",
}));
}

[ConditionalFact]
public virtual Task Updating_then_deleting_the_same_entity_results_in_DbUpdateConcurrencyException()
{
return ConcurrencyTestAsync<DbUpdateConcurrencyException>(
ctx => ctx.Customers.Add(new Customer { Id = "2", Name = "Added", }),
ctx => ctx.Customers.Add(
new Customer
{
Id = "2", Name = "Added",
}),
ctx => ctx.Customers.Single(c => c.Id == "2").Name = "Updated",
ctx => ctx.Customers.Remove(ctx.Customers.Single(c => c.Id == "2")));
}
Expand All @@ -37,7 +48,11 @@ public virtual Task Updating_then_deleting_the_same_entity_results_in_DbUpdateCo
public virtual Task Updating_then_updating_the_same_entity_results_in_DbUpdateConcurrencyException()
{
return ConcurrencyTestAsync<DbUpdateConcurrencyException>(
ctx => ctx.Customers.Add(new Customer { Id = "3", Name = "Added", }),
ctx => ctx.Customers.Add(
new Customer
{
Id = "3", Name = "Added",
}),
ctx => ctx.Customers.Single(c => c.Id == "3").Name = "Updated",
ctx => ctx.Customers.Single(c => c.Id == "3").Name = "Updated");
}
Expand Down Expand Up @@ -90,13 +105,16 @@ protected virtual async Task ConcurrencyTestAsync<TException>(
Assert.IsAssignableFrom<Customer>(entry.Entity);
}

protected ConcurrencyContext CreateContext() => Fixture.CreateContext();
protected ConcurrencyContext CreateContext()
=> Fixture.CreateContext();

public class CosmosFixture : SharedStoreFixtureBase<ConcurrencyContext>
{
protected override string StoreName => DatabaseName;
protected override string StoreName
=> DatabaseName;

protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
protected override ITestStoreFactory TestStoreFactory
=> CosmosTestStoreFactory.Instance;
}

public class ConcurrencyContext : PoolableDbContext
Expand Down
32 changes: 22 additions & 10 deletions test/EFCore.Cosmos.FunctionalTests/CustomConvertersCosmosTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,35 @@ private void AssertSql(params string[] expected)

public class CustomConvertersCosmosFixture : CustomConvertersFixtureBase
{
protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
public override bool StrictEquality => true;
protected override ITestStoreFactory TestStoreFactory
=> CosmosTestStoreFactory.Instance;

public override int IntegerPrecision => 53;
public override bool StrictEquality
=> true;

public override bool SupportsAnsi => false;
public override int IntegerPrecision
=> 53;

public override bool SupportsUnicodeToAnsiConversion => false;
public override bool SupportsAnsi
=> false;

public override bool SupportsLargeStringComparisons => true;
public override bool SupportsUnicodeToAnsiConversion
=> false;

public override bool SupportsBinaryKeys => true;
public override bool SupportsLargeStringComparisons
=> true;

public override bool SupportsDecimalComparisons => true;
public override bool SupportsBinaryKeys
=> true;

public override DateTime DefaultDateTime => new DateTime();
public TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)ListLoggerFactory;
public override bool SupportsDecimalComparisons
=> true;

public override DateTime DefaultDateTime
=> new DateTime();

public TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;

protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext context)
{
Expand Down
20 changes: 14 additions & 6 deletions test/EFCore.Cosmos.FunctionalTests/EmbeddedDocumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ public virtual async Task Can_change_principal_instance_non_derived()
}
}

protected TestSqlLoggerFactory TestSqlLoggerFactory => (TestSqlLoggerFactory)Fixture.ListLoggerFactory;
protected TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)Fixture.ListLoggerFactory;

protected void AssertSql(params string[] expected)
=> TestSqlLoggerFactory.AssertBaseline(expected);
Expand All @@ -464,7 +465,9 @@ public CosmosFixture()
TestStore = CosmosTestStore.Create(DatabaseName);
}

protected override ITestStoreFactory TestStoreFactory => CosmosTestStoreFactory.Instance;
protected override ITestStoreFactory TestStoreFactory
=> CosmosTestStoreFactory.Instance;

public virtual CosmosTestStore TestStore { get; }
private Action<ModelBuilder> OnModelCreatingAction { get; set; }
private object AdditionalModelCacheKey { get; set; }
Expand All @@ -475,7 +478,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder, DbContext con
}

public DbContextOptions CreateOptions(
Action<ModelBuilder> onModelCreating = null, object additionalModelCacheKey = null, bool seed = true)
Action<ModelBuilder> onModelCreating = null,
object additionalModelCacheKey = null,
bool seed = true)
{
OnModelCreatingAction = onModelCreating;
AdditionalModelCacheKey = additionalModelCacheKey;
Expand All @@ -497,9 +502,11 @@ protected override IServiceCollection AddServices(IServiceCollection serviceColl
=> base.AddServices(serviceCollection)
.AddSingleton<IModelCacheKeyFactory>(new TestModelCacheKeyFactory(() => AdditionalModelCacheKey));

public Task InitializeAsync() => Task.CompletedTask;
public Task InitializeAsync()
=> Task.CompletedTask;

public Task DisposeAsync() => TestStore.DisposeAsync();
public Task DisposeAsync()
=> TestStore.DisposeAsync();

private class TestModelCacheKeyFactory : IModelCacheKeyFactory
{
Expand All @@ -510,7 +517,8 @@ public TestModelCacheKeyFactory(Func<object> getAdditionalKey)
_getAdditionalKey = getAdditionalKey;
}

public object Create(DbContext context) => Tuple.Create(context.GetType(), _getAdditionalKey());
public object Create(DbContext context)
=> Tuple.Create(context.GetType(), _getAdditionalKey());
}
}

Expand Down
Loading

0 comments on commit cc756cd

Please sign in to comment.