Skip to content

Commit

Permalink
Cleanup in Identity tests
Browse files Browse the repository at this point in the history
Fixes #10671 by using updated EF API
Fixes #5812 so tests are re-enabled for PRs
Also part of #10668 since one of the changed EF queries is now working

Finally, I removed all remaining platform skips since with SQLite these tests should now run anywhere.
  • Loading branch information
ajcvickers committed Jun 5, 2019
1 parent 1ca6145 commit a86a811
Show file tree
Hide file tree
Showing 13 changed files with 5 additions and 146 deletions.
3 changes: 1 addition & 2 deletions src/Identity/EntityFrameworkCore/src/UserOnlyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ protected override Task<TUserLogin> FindUserLoginAsync(string loginProvider, str
throw new ArgumentNullException(nameof(user));
}

// TODO: Fix once EF query works Issue #10668
return (await UserClaims.Where(uc => uc.UserId.Equals(user.Id)).ToListAsync(cancellationToken)).Select(c => c.ToClaim()).ToList();
return await UserClaims.Where(uc => uc.UserId.Equals(user.Id)).Select(c => c.ToClaim()).ToListAsync(cancellationToken);
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Identity/EntityFrameworkCore/src/UserStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ where userRole.UserId.Equals(userId)
throw new ArgumentNullException(nameof(user));
}

// TODO: Fix once EF query works Issue #10668
return (await UserClaims.Where(uc => uc.UserId.Equals(user.Id)).ToListAsync(cancellationToken)).Select(c => c.ToClaim()).ToList();
return await UserClaims.Where(uc => uc.UserId.Equals(user.Id)).Select(c => c.ToClaim()).ToListAsync(cancellationToken);
}

/// <summary>
Expand Down
18 changes: 0 additions & 18 deletions src/Identity/EntityFrameworkCore/test/EF.Test/CustomPocoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public CustomDbContext(DbContextOptions options) : base(options)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanUpdateNameGuid()
{
using (var db = new CustomDbContext<Guid>(
Expand All @@ -54,9 +51,6 @@ public async Task CanUpdateNameGuid()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanUpdateNameString()
{
using (var db = new CustomDbContext<string>(
Expand All @@ -79,9 +73,6 @@ public async Task CanUpdateNameString()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanCreateUserInt()
{
using (var db = new CustomDbContext<int>(
Expand All @@ -102,9 +93,6 @@ public async Task CanCreateUserInt()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanCreateUserIntViaSet()
{
using (var db = new CustomDbContext<int>(
Expand All @@ -126,9 +114,6 @@ public async Task CanCreateUserIntViaSet()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanUpdateNameInt()
{
using (var db = new CustomDbContext<int>(
Expand All @@ -151,9 +136,6 @@ public async Task CanUpdateNameInt()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanUpdateNameIntWithSet()
{
using (var db = new CustomDbContext<int>(
Expand Down
6 changes: 2 additions & 4 deletions src/Identity/EntityFrameworkCore/test/EF.Test/DbUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public static bool VerifyMaxLength(DbContext context, string table, int maxLengt
{
var count = 0;

// TODO: Use new API once EF is updated. Issue #10671
foreach (var property in context.Model.GetEntityTypes().Single(e => (string)e.FindAnnotation("Relational:TableName")?.Value == table).GetProperties())
foreach (var property in context.Model.GetEntityTypes().Single(e => e.GetTableName() == table).GetProperties())
{
// TODO: Use new API once EF is updated. Issue #10671
if (!columns.Contains((string)property.FindAnnotation("Relational:ColumnName")?.Value ?? property.Name))
if (!columns.Contains(property.GetColumnName()))
{
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
public class DefaultPocoTest : IClassFixture<ScratchDatabaseFixture>
{
private readonly ApplicationBuilder _builder;
private const string DatabaseName = nameof(DefaultPocoTest);

public DefaultPocoTest(ScratchDatabaseFixture fixture)
{
Expand All @@ -42,9 +41,6 @@ public DefaultPocoTest(ScratchDatabaseFixture fixture)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task EnsureStartupUsageWorks()
{
var userStore = _builder.ApplicationServices.GetRequiredService<IUserStore<IdentityUser>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
public class MaxKeyLengthSchemaTest : IClassFixture<ScratchDatabaseFixture>
{
private readonly ApplicationBuilder _builder;
private const string DatabaseName = nameof(MaxKeyLengthSchemaTest);

public MaxKeyLengthSchemaTest(ScratchDatabaseFixture fixture)
{
Expand Down Expand Up @@ -49,9 +48,6 @@ public VerstappenDbContext(DbContextOptions options)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public void EnsureDefaultSchema()
{
using (var scope = _builder.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<!-- These tests are broken in Azure Pipelines right now due to deadlocks in EFCore on machines with few CPU cores. -->
<SkipTests Condition=" '$(BUILD_REASON)' == 'PullRequest' ">true</SkipTests>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.Test;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -73,9 +71,6 @@ protected override void SetUserPasswordHash(TUser user, string hashedPassword)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public void EnsureDefaultSchema()
{
VerifyDefaultSchema(CreateContext());
Expand Down Expand Up @@ -107,9 +102,6 @@ internal static void VerifyDefaultSchema(TestUserDbContext dbContext)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task DeleteUserRemovesTokensTest()
{
// Need fail if not empty?
Expand All @@ -127,9 +119,6 @@ public async Task DeleteUserRemovesTokensTest()


[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public void CanCreateUserUsingEF()
{
using (var db = CreateContext())
Expand All @@ -143,9 +132,6 @@ public void CanCreateUserUsingEF()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanCreateUsingManager()
{
var manager = CreateManager();
Expand All @@ -172,9 +158,6 @@ private async Task LazyLoadTestSetup(TestUserDbContext db, TUser user)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByIdTest()
{
var db = CreateContext();
Expand All @@ -191,9 +174,6 @@ public async Task LoadFromDbFindByIdTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByNameTest()
{
var db = CreateContext();
Expand All @@ -209,9 +189,6 @@ public async Task LoadFromDbFindByNameTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByLoginTest()
{
var db = CreateContext();
Expand All @@ -227,9 +204,6 @@ public async Task LoadFromDbFindByLoginTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByEmailTest()
{
var db = CreateContext();
Expand Down
35 changes: 0 additions & 35 deletions src/Identity/EntityFrameworkCore/test/EF.Test/SqlStoreTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Data.SqlClient;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity.Test;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -120,9 +118,6 @@ protected override void SetUserPasswordHash(TUser user, string hashedPassword)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public void EnsureDefaultSchema()
{
VerifyDefaultSchema(CreateContext());
Expand Down Expand Up @@ -155,9 +150,6 @@ internal static void VerifyDefaultSchema(TestDbContext dbContext)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task DeleteRoleNonEmptySucceedsTest()
{
// Need fail if not empty?
Expand All @@ -183,9 +175,6 @@ public async Task DeleteRoleNonEmptySucceedsTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task DeleteUserRemovesFromRoleTest()
{
// Need fail if not empty?
Expand All @@ -209,9 +198,6 @@ public async Task DeleteUserRemovesFromRoleTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task DeleteUserRemovesTokensTest()
{
// Need fail if not empty?
Expand All @@ -229,9 +215,6 @@ public async Task DeleteUserRemovesTokensTest()


[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public void CanCreateUserUsingEF()
{
using (var db = CreateContext())
Expand All @@ -245,9 +228,6 @@ public void CanCreateUserUsingEF()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task CanCreateUsingManager()
{
var manager = CreateManager();
Expand Down Expand Up @@ -281,9 +261,6 @@ private async Task LazyLoadTestSetup(TestDbContext db, TUser user)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByIdTest()
{
var db = CreateContext();
Expand All @@ -300,9 +277,6 @@ public async Task LoadFromDbFindByIdTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByNameTest()
{
var db = CreateContext();
Expand All @@ -318,9 +292,6 @@ public async Task LoadFromDbFindByNameTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByLoginTest()
{
var db = CreateContext();
Expand All @@ -336,9 +307,6 @@ public async Task LoadFromDbFindByLoginTest()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task GetSecurityStampThrowsIfNull()
{
var manager = CreateManager();
Expand All @@ -350,9 +318,6 @@ public async Task GetSecurityStampThrowsIfNull()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task LoadFromDbFindByEmailTest()
{
var db = CreateContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test
public class UserOnlyCustomContextTest : IClassFixture<ScratchDatabaseFixture>
{
private readonly ApplicationBuilder _builder;
private const string DatabaseName = nameof(UserOnlyCustomContextTest);

public class CustomContext : DbContext
{
Expand Down Expand Up @@ -87,9 +86,6 @@ public UserOnlyCustomContextTest(ScratchDatabaseFixture fixture)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[OSSkipCondition(OperatingSystems.Linux)]
[OSSkipCondition(OperatingSystems.MacOSX)]
public async Task EnsureStartupUsageWorks()
{
var userStore = _builder.ApplicationServices.GetRequiredService<IUserStore<IdentityUser>>();
Expand Down
Loading

0 comments on commit a86a811

Please sign in to comment.