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

Code cleanup for tests #22187

Merged
1 commit merged into from
Aug 23, 2020
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/Shared/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static IReadOnlyList<string> HasNoEmptyElements(
}

[Conditional("DEBUG")]
public static void DebugAssert([CA.DoesNotReturnIf(false)] bool condition, string message)
public static void DebugAssert([CA.DoesNotReturnIfAttribute(false)] bool condition, string message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, don't know why it is doing this. Will investigate after getting stuff merged.

(Note that Code Cleanup processes the shared code for each project, which is why this keeps popping up.)

{
if (!condition)
{
Expand Down
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