示例#1
0
 public static void Initialize(
     UserManager <Usuario> userManager,
     RoleManager <Perfil> roleManager,
     EFApplicationContext context)
 {
     context.Database.EnsureCreated();
     SeedUsers(context, userManager);
 }
        // 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,
            UserManager <Usuario> userManager,
            RoleManager <Perfil> roleManager,
            EFApplicationContext context)
        {
            //StartScheduler();
            app.UseCors("CorsPolicy");

            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            //}
            //else
            //{
            //    app.UseHsts();
            //}

            app.UseResponseCompression();
            app.UseMvc();

            var swaggerSettings = Configuration.GetSection("Swagger").Get <SwaggerSettings>();

            loggerFactory.AddContext(LogLevel.Warning, Configuration.GetConnectionString("DefaultConnection"));

#if DEBUG
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();
            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", swaggerSettings.Title);
                c.RoutePrefix   = string.Empty;
                c.DocumentTitle = swaggerSettings.Title;
            });
#endif

            app.UseDefaultFiles();
            app.UseStaticFiles();
            // for Linux compatibility
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseAuthentication();
            app.UseResponseCompression();
            app.UseCors("CorsPolicy");

            DbInitializer.Initialize(userManager, roleManager, context);
        }
示例#3
0
        public void TEST_MOCK_REPOSITORY()
        {
            var options = new DbContextOptionsBuilder <EFApplicationContext>()
                          .UseInMemoryDatabase("portal_xpto")
                          .Options;

            using (var context = new EFApplicationContext(options))
            {
                context.XptoSet.Add(new Xpto {
                    Id = Guid.NewGuid()
                });
                context.XptoSet.Add(new Xpto {
                    Id = Guid.NewGuid()
                });
                context.SaveChanges();
            }

            using (var context = new EFApplicationContext(options))
            {
                var service = new XptoRepository(context);
                var result  = service.GetAll().ToList();
                Assert.NotNull(result);
            }
        }
 public StoredEventRepository(EFApplicationContext context) : base(context)
 {
 }
示例#5
0
 public XptoRepository(EFApplicationContext context) : base(context)
 {
 }
示例#6
0
        private static void SeedUsers(EFApplicationContext context, UserManager <Usuario> userManager)
        {
            if (userManager.FindByNameAsync("admin").Result == null)
            {
                var user = new Usuario
                {
                    Id       = Guid.Parse("762238c2-7e4e-4033-a59e-ef0eb042b4fa"),
                    Nome     = "Administrador",
                    UserName = "******",
                    Email    = "*****@*****.**"
                };


                var perfil = new Perfil
                {
                    Name          = "Administrador",
                    DataAlteracao = DateTime.Now,
                    DataCriacao   = DateTime.Now,
                    Desativado    = false,
                };

                context.Roles.Add(perfil);

                var modulo = new Modulo
                {
                    Nome   = "Cadastro Equipe",
                    Codigo = "CADASTRO_EQUIPE",
                };

                context.ModulosSet.Add(modulo);

                var perfilModulo = new PerfilModulo
                {
                    PerfilId = perfil.Id,
                    ModuloId = modulo.Id
                };

                context.PerfilModuloSet.Add(perfilModulo);

                var perfilModeloPermissaoRead = new PerfilModuloPermissao
                {
                    PerfilModuloId = perfilModulo.Id,
                    Permissao      = new Permissao
                    {
                        Nome   = "Leitura",
                        Codigo = "READ"
                    }
                };
                context.PerfilModuloPermissaoSet.Add(perfilModeloPermissaoRead);

                var perfilModeloPermissaoCreate = new PerfilModuloPermissao
                {
                    PerfilModuloId = perfilModulo.Id,
                    Permissao      = new Permissao
                    {
                        Nome   = "Criar",
                        Codigo = "CREATE"
                    }
                };
                context.PerfilModuloPermissaoSet.Add(perfilModeloPermissaoCreate);

                var perfilModeloPermissaoUpdate = new PerfilModuloPermissao
                {
                    PerfilModuloId = perfilModulo.Id,
                    Permissao      = new Permissao
                    {
                        Nome   = "Atualizar",
                        Codigo = "UPDATE"
                    }
                };
                context.PerfilModuloPermissaoSet.Add(perfilModeloPermissaoUpdate);

                var perfilModeloPermissaoDelete = new PerfilModuloPermissao
                {
                    PerfilModuloId = perfilModulo.Id,
                    Permissao      = new Permissao
                    {
                        Nome   = "Deletar",
                        Codigo = "DELETE"
                    }
                };
                context.PerfilModuloPermissaoSet.Add(perfilModeloPermissaoDelete);

                context.SaveChanges();

                user.Papeis.Add(new UsuarioPerfil
                {
                    RoleId = perfil.Id,
                    UserId = user.Id,
                });

                var result = userManager.CreateAsync(user, "123456").Result;
            }
        }