From 3c0eefe12efffe6c568f05321904b734d7312fbf Mon Sep 17 00:00:00 2001 From: Praburaj Date: Tue, 22 Jul 2014 16:44:23 -0700 Subject: [PATCH] Merging the MusicStore & MusicStoreIdentity Db into one. This has been a feedback from identity team for a while. Just got time to do it now. --- src/MusicStore/LocalConfig.json | 3 --- src/MusicStore/Models/IdentityModels.cs | 25 ---------------------- src/MusicStore/Models/MusicStoreContext.cs | 13 ++++++++--- src/MusicStore/Models/SampleData.cs | 22 ++----------------- src/MusicStore/MusicStore.kproj | 3 +-- src/MusicStore/Startup.cs | 10 +++------ test/E2ETests/SmokeTests.cs | 6 +----- 7 files changed, 17 insertions(+), 65 deletions(-) delete mode 100644 src/MusicStore/Models/IdentityModels.cs diff --git a/src/MusicStore/LocalConfig.json b/src/MusicStore/LocalConfig.json index 1492df9e75..c4e905e13c 100644 --- a/src/MusicStore/LocalConfig.json +++ b/src/MusicStore/LocalConfig.json @@ -4,9 +4,6 @@ "Data": { "DefaultConnection": { "Connectionstring": "Server=(localdb)\\MSSQLLocalDB;Database=MusicStore;Trusted_Connection=True;MultipleActiveResultSets=true" - }, - "IdentityConnection": { - "Connectionstring": "Server=(localdb)\\MSSQLLocalDB;Database=MusicStoreIdentity;Trusted_Connection=True;MultipleActiveResultSets=true" } } } \ No newline at end of file diff --git a/src/MusicStore/Models/IdentityModels.cs b/src/MusicStore/Models/IdentityModels.cs deleted file mode 100644 index 51a1ce6c0a..0000000000 --- a/src/MusicStore/Models/IdentityModels.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using Microsoft.AspNet.Identity; -using Microsoft.AspNet.Identity.EntityFramework; -using Microsoft.Data.Entity; -using Microsoft.Framework.OptionsModel; - -namespace MusicStore.Models -{ - public class ApplicationUser : IdentityUser { } - - public class ApplicationDbContext : IdentityDbContext - { - public ApplicationDbContext(IServiceProvider serviceProvider, IOptionsAccessor optionsAccessor) - : base(serviceProvider, optionsAccessor.Options) - { - } - } - - public class IdentityDbContextOptions : DbContextOptions - { - public string DefaultAdminUserName { get; set; } - - public string DefaultAdminPassword { get; set; } - } -} \ No newline at end of file diff --git a/src/MusicStore/Models/MusicStoreContext.cs b/src/MusicStore/Models/MusicStoreContext.cs index 94ab76bb82..980f527785 100644 --- a/src/MusicStore/Models/MusicStoreContext.cs +++ b/src/MusicStore/Models/MusicStoreContext.cs @@ -1,11 +1,15 @@ using System; +using Microsoft.AspNet.Identity; +using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Metadata; using Microsoft.Framework.OptionsModel; namespace MusicStore.Models { - public class MusicStoreContext : DbContext + public class ApplicationUser : IdentityUser { } + + public class MusicStoreContext : IdentityDbContext { public MusicStoreContext(IServiceProvider serviceProvider, IOptionsAccessor optionsAccessor) : base(serviceProvider, optionsAccessor.Options) @@ -20,20 +24,23 @@ namespace MusicStore.Models public DbSet CartItems { get; set; } public DbSet OrderDetails { get; set; } - protected override void OnModelCreating(ModelBuilder builder) { builder.Entity().Key(a => a.AlbumId); builder.Entity().Key(a => a.ArtistId); - builder.Entity().Key(o => o.OrderId).Properties(p => p.Property(o => o.OrderId).ColumnName("Order")); + builder.Entity().Key(o => o.OrderId); builder.Entity().Key(g => g.GenreId); builder.Entity().Key(c => c.CartItemId); builder.Entity().Key(o => o.OrderDetailId); + + base.OnModelCreating(builder); } } public class MusicStoreDbContextOptions : DbContextOptions { + public string DefaultAdminUserName { get; set; } + public string DefaultAdminPassword { get; set; } } } \ No newline at end of file diff --git a/src/MusicStore/Models/SampleData.cs b/src/MusicStore/Models/SampleData.cs index 336c40db40..e07ea7ec89 100644 --- a/src/MusicStore/Models/SampleData.cs +++ b/src/MusicStore/Models/SampleData.cs @@ -25,29 +25,12 @@ namespace MusicStore.Models if (await db.Database.EnsureCreatedAsync()) { await InsertTestData(serviceProvider); - } - } - else - { - await InsertTestData(serviceProvider); - } - } - } - - public static async Task InitializeIdentityDatabaseAsync(IServiceProvider serviceProvider) - { - using (var db = serviceProvider.GetService()) - { - var sqlServerDataStore = db.Configuration.DataStore as SqlServerDataStore; - if (sqlServerDataStore != null) - { - if (await db.Database.EnsureCreatedAsync()) - { await CreateAdminUser(serviceProvider); } } else { + await InsertTestData(serviceProvider); await CreateAdminUser(serviceProvider); } } @@ -88,7 +71,6 @@ namespace MusicStore.Models } } - /// /// Creates a store manager user who can manage the inventory. /// @@ -96,7 +78,7 @@ namespace MusicStore.Models /// private static async Task CreateAdminUser(IServiceProvider serviceProvider) { - var options = serviceProvider.GetService>().Options; + var options = serviceProvider.GetService>().Options; //const string adminRole = "Administrator"; var userManager = serviceProvider.GetService>(); diff --git a/src/MusicStore/MusicStore.kproj b/src/MusicStore/MusicStore.kproj index 920f634b54..f0e4bc61b2 100644 --- a/src/MusicStore/MusicStore.kproj +++ b/src/MusicStore/MusicStore.kproj @@ -91,7 +91,6 @@ - @@ -103,4 +102,4 @@ - + \ No newline at end of file diff --git a/src/MusicStore/Startup.cs b/src/MusicStore/Startup.cs index 5d179ef6a1..e0bf0729a4 100644 --- a/src/MusicStore/Startup.cs +++ b/src/MusicStore/Startup.cs @@ -33,18 +33,15 @@ namespace MusicStore services.AddScoped(); // Configure DbContext - services.SetupOptions(options => + services.SetupOptions(options => { options.DefaultAdminUserName = configuration.Get("DefaultAdminUsername"); options.DefaultAdminPassword = configuration.Get("DefaultAdminPassword"); - options.UseSqlServer(configuration.Get("Data:IdentityConnection:ConnectionString")); + options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString")); }); - services.SetupOptions(options => - options.UseSqlServer(configuration.Get("Data:DefaultConnection:ConnectionString"))); - // Add Identity services to the services container - services.AddIdentitySqlServer() + services.AddIdentitySqlServer() .AddHttpSignIn(); // Add MVC services to the services container @@ -81,7 +78,6 @@ namespace MusicStore //Populates the MusicStore sample data SampleData.InitializeMusicStoreDatabaseAsync(app.ApplicationServices).Wait(); - SampleData.InitializeIdentityDatabaseAsync(app.ApplicationServices).Wait(); } } } \ No newline at end of file diff --git a/test/E2ETests/SmokeTests.cs b/test/E2ETests/SmokeTests.cs index 93bc4f2b9c..3140ca4281 100644 --- a/test/E2ETests/SmokeTests.cs +++ b/test/E2ETests/SmokeTests.cs @@ -28,14 +28,11 @@ namespace E2ETests var testStartTime = DateTime.Now; var musicStoreDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); - var musicStoreIdentityDbName = Guid.NewGuid().ToString().Replace("-", string.Empty); Console.WriteLine("Pointing MusicStore DB to '{0}'", string.Format(Connection_string_Format, musicStoreDbName)); - Console.WriteLine("Pointing MusicStoreIdentity DB to '{0}'", string.Format(Connection_string_Format, musicStoreIdentityDbName)); //Override the connection strings using environment based configuration Environment.SetEnvironmentVariable("SQLAZURECONNSTR_DefaultConnection", string.Format(Connection_string_Format, musicStoreDbName)); - Environment.SetEnvironmentVariable("SQLAZURECONNSTR_IdentityConnection", string.Format(Connection_string_Format, musicStoreIdentityDbName)); ApplicationBaseUrl = applicationBaseUrl; Process hostProcess = null; @@ -43,7 +40,7 @@ namespace E2ETests try { - hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, musicStoreIdentityDbName); + hostProcess = DeploymentUtility.StartApplication(hostType, kreFlavor, musicStoreDbName); httpClientHandler = new HttpClientHandler(); httpClient = new HttpClient(httpClientHandler) { BaseAddress = new Uri(applicationBaseUrl) }; @@ -147,7 +144,6 @@ namespace E2ETests } DbUtils.DropDatabase(musicStoreDbName); - DbUtils.DropDatabase(musicStoreIdentityDbName); } }