Standardize sql db names for tests
This commit is contained in:
parent
00261c1984
commit
19d6805c7c
|
|
@ -12,7 +12,6 @@ namespace Microsoft.AspNet.Identity.SqlServer
|
|||
{
|
||||
public IdentityDbContext() { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider) : base(serviceProvider) { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider, string nameOrConnectionString) : base(serviceProvider, nameOrConnectionString) { }
|
||||
public IdentityDbContext(DbContextOptions options) : base(options) { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider, DbContextOptions options) : base(serviceProvider, options) { }
|
||||
}
|
||||
|
|
@ -23,7 +22,6 @@ namespace Microsoft.AspNet.Identity.SqlServer
|
|||
{
|
||||
public IdentityDbContext() { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider) : base(serviceProvider) { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider, string nameOrConnectionString) : base(serviceProvider, nameOrConnectionString) { }
|
||||
public IdentityDbContext(DbContextOptions options) : base(options) { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider, DbContextOptions options) : base(serviceProvider, options) { }
|
||||
}
|
||||
|
|
@ -40,25 +38,11 @@ namespace Microsoft.AspNet.Identity.SqlServer
|
|||
public DbSet<TRole> Roles { get; set; }
|
||||
public DbSet<IdentityRoleClaim<TKey>> RoleClaims { get; set; }
|
||||
|
||||
private readonly string _nameOrConnectionString;
|
||||
|
||||
public IdentityDbContext() { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider, string nameOrConnectionString) : base(serviceProvider)
|
||||
{
|
||||
_nameOrConnectionString = nameOrConnectionString;
|
||||
}
|
||||
public IdentityDbContext(IServiceProvider serviceProvider) : base(serviceProvider) { }
|
||||
public IdentityDbContext(DbContextOptions options) : base(options) { }
|
||||
public IdentityDbContext(IServiceProvider serviceProvider, DbContextOptions options) : base(serviceProvider, options) { }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptions builder)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_nameOrConnectionString))
|
||||
{
|
||||
builder.UseSqlServer(_nameOrConnectionString);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.Entity<TUser>(b =>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Identity.Test;
|
||||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Data.Entity.Metadata;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.Fallback;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -12,9 +13,10 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNet.Identity.SqlServer.Test
|
||||
{
|
||||
[TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.SqlServer.Test")]
|
||||
public class CustomPocoTest
|
||||
{
|
||||
private const string ConnectionString = @"Server=(localdb)\v11.0;Database=CustomPocoTest;Trusted_Connection=True;";
|
||||
private readonly string ConnectionString = @"Server=(localdb)\v11.0;Database=CustomUserContextTest" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ";Trusted_Connection=True;";
|
||||
|
||||
public class User<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
|
|
@ -23,33 +25,27 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
}
|
||||
|
||||
public class CustomDbContext<TUser> : DbContext where TUser : class
|
||||
//where TUser : User<TKey> where TKey : IEquatable<TKey>
|
||||
{
|
||||
public DbSet<TUser> Users { get; set; }
|
||||
|
||||
public CustomDbContext(IServiceProvider services) : base(services) { }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptions builder)
|
||||
{
|
||||
builder.UseSqlServer(ConnectionString);
|
||||
}
|
||||
|
||||
//protected override void OnModelCreating(ModelBuilder builder)
|
||||
//{
|
||||
// builder.Entity<TUser>()
|
||||
// .Key(u => u.Id)
|
||||
// .Properties(ps => ps.Property(u => u.UserName));
|
||||
//}
|
||||
public CustomDbContext(IServiceProvider services) :
|
||||
base(services, services.GetService<IOptionsAccessor<DbContextOptions>>().Options) { }
|
||||
}
|
||||
|
||||
//public static CustomDbContext<User<TKey>, TKey> CreateContext<TKey>(bool delete = false) where TKey : IEquatable<TKey>
|
||||
public static CustomDbContext<TUser> CreateContext<TUser>(bool delete = false) where TUser : class
|
||||
|
||||
public CustomDbContext<TUser> GetContext<TUser>() where TUser : class
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.Add(OptionsServices.GetDefaultServices());
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.SetupOptions<DbContextOptions>(options => options.UseSqlServer(ConnectionString));
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
return new CustomDbContext<TUser>(serviceProvider);
|
||||
}
|
||||
|
||||
var db = new CustomDbContext<TUser>(serviceProvider);
|
||||
public CustomDbContext<TUser> CreateContext<TUser>(bool delete = false) where TUser : class
|
||||
{
|
||||
var db = GetContext<TUser>();
|
||||
if (delete)
|
||||
{
|
||||
db.Database.EnsureDeleted();
|
||||
|
|
@ -58,6 +54,26 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
return db;
|
||||
}
|
||||
|
||||
[TestPriority(-1000)]
|
||||
[Fact]
|
||||
public void DropDatabaseStart()
|
||||
{
|
||||
DropDb();
|
||||
}
|
||||
|
||||
[TestPriority(10000)]
|
||||
[Fact]
|
||||
public void DropDatabaseDone()
|
||||
{
|
||||
DropDb();
|
||||
}
|
||||
|
||||
public void DropDb()
|
||||
{
|
||||
var db = GetContext<User<string>>();
|
||||
db.Database.EnsureDeleted();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CanUpdateNameGuid()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,32 +6,44 @@ using Microsoft.AspNet.Identity.Test;
|
|||
using Microsoft.Data.Entity;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.DependencyInjection.Fallback;
|
||||
using Microsoft.Framework.OptionsModel;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.Identity.SqlServer.Test
|
||||
{
|
||||
[TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.SqlServer.Test")]
|
||||
public class DefaultPocoTest
|
||||
{
|
||||
private const string ConnectionString = @"Server=(localdb)\v11.0;Database=DefaultPocoTest;Trusted_Connection=True;";
|
||||
public static IdentityDbContext CreateContext(bool delete = false)
|
||||
private readonly string ConnectionString = @"Server=(localdb)\v11.0;Database=DefaultSchemaTest" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ";Trusted_Connection=True;";
|
||||
public IdentityDbContext CreateContext(bool ensureCreated = false)
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.Add(OptionsServices.GetDefaultServices());
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
services.SetupOptions<DbContextOptions>(options => options.UseSqlServer(ConnectionString));
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
var db = new IdentityDbContext(serviceProvider, ConnectionString);
|
||||
if (delete)
|
||||
var db = new IdentityDbContext(serviceProvider,
|
||||
serviceProvider.GetService<IOptionsAccessor<DbContextOptions>>().Options);
|
||||
if (ensureCreated)
|
||||
{
|
||||
db.Database.EnsureDeleted();
|
||||
db.Database.EnsureCreated();
|
||||
}
|
||||
db.Database.EnsureCreated();
|
||||
return db;
|
||||
}
|
||||
|
||||
public static void EnsureDatabase()
|
||||
public void DropDb()
|
||||
{
|
||||
CreateContext();
|
||||
var db = CreateContext();
|
||||
db.Database.EnsureDeleted();
|
||||
}
|
||||
|
||||
[TestPriority(-1000)]
|
||||
[Fact]
|
||||
public void DropDatabaseStart()
|
||||
{
|
||||
DropDb();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -62,5 +74,12 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password));
|
||||
IdentityResultAssert.IsSuccess(await userManager.DeleteAsync(user));
|
||||
}
|
||||
|
||||
[TestPriority(10000)]
|
||||
[Fact]
|
||||
public void DropDatabaseDone()
|
||||
{
|
||||
DropDb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -30,11 +30,13 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
[TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.SqlServer.Test")]
|
||||
public class UserStoreGuidTest : SqlStoreTestBase<GuidUser, GuidRole, Guid>
|
||||
{
|
||||
private readonly string _connectionString = @"Server=(localdb)\v11.0;Database=SqlUserStoreGuidTest" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ";Trusted_Connection=True;";
|
||||
|
||||
public override string ConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"Server=(localdb)\v11.0;Database=SqlUserStoreGuidTest;Trusted_Connection=True;";
|
||||
return _connectionString;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,13 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
[TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.SqlServer.Test")]
|
||||
public class UserStoreIntTest : SqlStoreTestBase<IntUser, IntRole, int>
|
||||
{
|
||||
private readonly string _connectionString = @"Server=(localdb)\v11.0;Database=SqlUserStoreIntTest" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ";Trusted_Connection=True;";
|
||||
|
||||
public override string ConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"Server=(localdb)\v11.0;Database=SqlUserStoreIntTest;Trusted_Connection=True;";
|
||||
return _connectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,13 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
[TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.SqlServer.Test")]
|
||||
public class UserStoreStringKeyTest : SqlStoreTestBase<StringUser, StringRole, string>
|
||||
{
|
||||
private readonly string _connectionString = @"Server=(localdb)\v11.0;Database=SqlUserStoreStringTest" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ";Trusted_Connection=True;";
|
||||
|
||||
public override string ConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return @"Server=(localdb)\v11.0;Database=SqlUserStoreStringTest;Trusted_Connection=True;";
|
||||
return _connectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
[TestCaseOrderer("Microsoft.AspNet.Identity.Test.PriorityOrderer", "Microsoft.AspNet.Identity.SqlServer.Test")]
|
||||
public class UserStoreTest : UserManagerTestBase<IdentityUser, IdentityRole>
|
||||
{
|
||||
private static readonly string ConnectionString = @"Server=(localdb)\v11.0;Database=SqlUserStoreTest;Trusted_Connection=True;";
|
||||
private readonly string ConnectionString = @"Server=(localdb)\v11.0;Database=SqlUserStoreTest" + DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ";Trusted_Connection=True;";
|
||||
|
||||
public class ApplicationUser : IdentityUser { }
|
||||
|
||||
|
|
@ -135,9 +135,10 @@ namespace Microsoft.AspNet.Identity.SqlServer.Test
|
|||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddEntityFramework().AddSqlServer();
|
||||
var dbOptions = new DbContextOptions();
|
||||
dbOptions.UseSqlServer(ConnectionString);
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
var db = new IdentityDbContext(serviceProvider, ConnectionString);
|
||||
var db = new IdentityDbContext(serviceProvider, dbOptions);
|
||||
if (delete)
|
||||
{
|
||||
db.Database.EnsureDeleted();
|
||||
|
|
|
|||
Loading…
Reference in New Issue