示例#1
0
        public AuthorizeTest()
        {
            var confFileName = Path.Combine(
                Path.GetDirectoryName(GetType().Assembly.Location) ?? string.Empty,
                $"Monica.Crm.WebApi.dll.config");
            var build           = new ConfigurationBuilder().AddXmlFile(confFileName);
            var configiguration = build.Build();

            var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

            foreach (var file in files)
            {
                if (file.IndexOf("testhost.dll", StringComparison.Ordinal) > -1)
                {
                    continue;
                }

                System.Runtime.Loader.AssemblyLoadContext.Default
                .LoadFromAssemblyPath(file);
            }

            AutoFac.Init(DataBaseName.MySql, builder =>
            {
                builder.RegisterInstance(configiguration).As <IConfiguration>();
            });
            _monicaAuthorizeDataAdapter = AutoFac.Resolve <IMonicaAuthorizeDataAdapter>();
        }
示例#2
0
        protected BaseServiceTest()
        {
            var mockDataBaseMain = new Mock <IDataBaseMain>();
            var mockDataBaseIs4  = new Mock <IDataBaseIs4>();
            var logger           = new Mock <ILogger>();

            var configiguration     = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
            var connectionString    = configiguration.ConnectionStrings.ConnectionStrings["MySqlDatabase"].ConnectionString;
            var connectionStringIs4 = configiguration.ConnectionStrings.ConnectionStrings["MySqlDatabaseIS4"].ConnectionString;

            GlobalSettingsApp.CurrentAppDirectory =
                Path.GetDirectoryName(Assembly.GetAssembly(typeof(BaseEfTest)).Location);
            mockDataBaseMain.Setup(main => main.ConntectionString).Returns(connectionString);
            mockDataBaseIs4.Setup(main => main.ConntectionString).Returns(connectionStringIs4);
            var events   = new OnStartupEvents();
            var services = new ServiceCollection();

            services.AddSingleton(mockDataBaseMain.Object);
            services.AddSingleton(mockDataBaseIs4.Object);
            events.OnConfigureServicesAfterAddMvc(services, null);


            var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

            foreach (var file in files)
            {
                if (file.IndexOf("testhost.dll", StringComparison.Ordinal) > -1)
                {
                    continue;
                }

                System.Runtime.Loader.AssemblyLoadContext.Default
                .LoadFromAssemblyPath(file);
            }

            AutoFac.Init(DataBaseName.MySql, builder =>
            {
                builder.Populate(services);
                builder.RegisterInstance(logger.Object);
                //builder.RegisterInstance(mockDataBaseIs4);
                //builder.RegisterInstance(mockDataBaseMain);
            });
            Service = AutoFac.Resolve <TService>();
        }
示例#3
0
        public GenerateFieldsMySqlTest()
        {
            var mockDataBaseMain = new Mock <IDataBaseMain>();
            var mockDataBaseIs4  = new Mock <IDataBaseIs4>();
            var logger           = new Mock <ILogger>();

            var configiguration     = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
            var connectionString    = configiguration.ConnectionStrings.ConnectionStrings["MySqlDatabase"].ConnectionString;
            var connectionStringIs4 = configiguration.ConnectionStrings.ConnectionStrings["MySqlDatabaseIS4"].ConnectionString;

            mockDataBaseMain.Setup(main => main.ConntectionString).Returns(connectionString);
            mockDataBaseIs4.Setup(main => main.ConntectionString).Returns(connectionStringIs4);

            var services = new ServiceCollection();

            services.AddSingleton(mockDataBaseMain.Object);
            services.AddSingleton(mockDataBaseIs4.Object);
            services.AddDbContextCore();


            var files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");

            foreach (var file in files)
            {
                if (file.IndexOf("testhost.dll", StringComparison.Ordinal) > -1)
                {
                    continue;
                }

                System.Runtime.Loader.AssemblyLoadContext.Default
                .LoadFromAssemblyPath(file);
            }

            AutoFac.Init(DataBaseName.MySql, builder =>
            {
                builder.Populate(services);
                builder.RegisterInstance(logger.Object);
                //builder.RegisterInstance(mockDataBaseIs4);
                //builder.RegisterInstance(mockDataBaseMain);
            });
            Service = AutoFac.ResolveNamed <IGenerateField>(nameof(GenerateFieldMySql));
        }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            LoaderExtensions.OnConfigureServicesBeforeAddMvc(services);
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy", builder =>
                {
                    builder.AllowAnyMethod()
                    .AllowAnyHeader()
                    .WithOrigins("*")
                    .WithMethods("*")
                    .WithHeaders("*")
                    .DisallowCredentials();
                });
            });
            IMvcBuilder mvcBuilder = MvcServiceCollectionExtensions.AddMvc(services).AddNewtonsoftJson();

            //services.Configure<MvcOptions>(options =>
            //{
            //    options.Filters.Add(new AuthorizeFilter("CorsPolicyAll"));
            //});
            services.AddControllers(mvcOtions =>
            {
                mvcOtions.EnableEndpointRouting = false;
            });
            mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            services.AddScoped <IDataBaseMain, DataBaseMain>();
            services.AddScoped <IDataBaseIs4, DataBaseIs4>();
            LoaderExtensions.OnConfigureServicesAfterAddMvc(services, mvcBuilder, Configuration);
            LoaderExtensions.LoadMvc(mvcBuilder, GlobalSettingsApp.CurrentAppDirectory);
            LoaderExtensions.OnInitBackendService(services);

            ApplicationContainer = AutoFac.Init(DataBaseName.MySql, cb =>
            {
                cb.Populate(services);
            });
            return(new AutofacServiceProvider(ApplicationContainer));
        }
示例#5
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.AddCors(options => options.AddPolicy("ApiCorsPolicy", builder =>
            {
                //builder.AllowAnyMethod()
                //    .AllowAnyHeader()
                //    .WithOrigins("*")
                //    .WithMethods("*")
                //    .WithHeaders("*")
                //.DisallowCredentials();
                builder.WithOrigins("http://localhost:4200", "http://localhost:4200/", "https://barbuuuda.ru", "https://barbuuuda.ru/")
                .AllowAnyHeader()
                .AllowAnyMethod()
                .AllowCredentials();
            }));

            #region ПРОД.
            //    services.AddDbContext<ApplicationDbContext>(options =>
            //      options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("Barbuuuda.Core").EnableRetryOnFailure()));

            //    services.AddEntityFrameworkNpgsql().AddDbContext<PostgreDbContext>(opt =>
            //opt.UseNpgsql(Configuration.GetConnectionString("PostgreConnection"), b => b.MigrationsAssembly("Barbuuuda.Core").EnableRetryOnFailure()));

            //    services.AddDbContext<IdentityDbContext>(options =>
            //        options.UseNpgsql(Configuration.GetConnectionString("PostgreConnection"), b => b.MigrationsAssembly("Barbuuuda.Core").EnableRetryOnFailure()));
            #endregion

            #region ТЕСТ.
            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(Configuration.GetConnectionString("TestMsSqlConnection"), b => b.MigrationsAssembly("Barbuuuda.Core").EnableRetryOnFailure()));

            services.AddEntityFrameworkNpgsql().AddDbContext <PostgreDbContext>(opt =>
                                                                                opt.UseNpgsql(Configuration.GetConnectionString("TestNpgSqlConnection"), b => b.MigrationsAssembly("Barbuuuda.Core").EnableRetryOnFailure()));

            services.AddDbContext <IdentityDbContext>(options =>
                                                      options.UseNpgsql(Configuration.GetConnectionString("TestNpgSqlConnection"), b => b.MigrationsAssembly("Barbuuuda.Core").EnableRetryOnFailure()));
            #endregion

            services.AddIdentity <UserEntity, IdentityRole>(opts =>
            {
                opts.Password.RequiredLength         = 5;
                opts.Password.RequireNonAlphanumeric = false;
                opts.Password.RequireLowercase       = false;
                opts.Password.RequireUppercase       = false;
                opts.Password.RequireDigit           = false;
            })
            .AddEntityFrameworkStores <IdentityDbContext>()
            .AddDefaultTokenProviders();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Barbuuuda", Version = "v1"
                });
            });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidIssuer              = AuthOptions.ISSUER,
                    ValidateAudience         = true,
                    ValidAudience            = AuthOptions.AUDIENCE,
                    ValidateLifetime         = true,
                    IssuerSigningKey         = AuthOptions.GetSymmetricSecurityKey(),
                    ValidateIssuerSigningKey = true,
                };
            });

            services.AddSignalR();

            ApplicationContainer = AutoFac.Init(cb =>
            {
                cb.Populate(services);
            });

            return(new AutofacServiceProvider(ApplicationContainer));
        }