Exemplo n.º 1
0
        private static void SeedContextWithTestData(BeautifulContext context)
        {
            var fakeUsers = new TestData.TestUsers(26);
            var fakePosts = new TestData.TestPosts(100, fakeUsers.Data.Select(x => x.Id).ToArray());

            fakeUsers.Seed(context.Users);
            fakePosts.Seed(context.Posts);

            context.SaveChanges();
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            // Seed data store with test data
            var context = app.ApplicationServices.GetService <BeautifulContext>();

            var fakeUsers = new TestData.TestUsers(26);
            var fakePosts = new TestData.TestPosts(100, fakeUsers.Data.Select(x => x.Id).ToArray());

            fakeUsers.Seed(context.Users);
            fakePosts.Seed(context.Posts);

            context.SaveChanges();

            app.UseMvc(opt =>
            {
                opt.MapRoute("default", "{controller}/{id?}/{link?}");
            });
        }