public void Setup()
        {
            _employeeRepositorySubstitute = Substitute.For <IEmployeeRepository>();
            _mapper = MappingConfiguration.Configure();

            _employeeService = new EmployeeService(_employeeRepositorySubstitute, _mapper);
        }
Exemple #2
0
        protected void Application_Start()
        {
            HttpConfiguration config = new HttpConfiguration();

            WebApiConfig.Register(config);
            // autofac container
            var builder = new ContainerBuilder();

            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModule <UserModule>();
            builder.RegisterModule <DataAccessModule>();

            // Auto Mapper v5 Support
            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                MappingConfiguration.Configure(typeof(UserModule).Assembly, cfg);
                MappingConfiguration.Configure(typeof(UsersBusinessProviderModule).Assembly, cfg);
            });

            var mapper = mapperConfiguration.CreateMapper();

            builder.RegisterInstance(mapper).As <IMapper>();

            var container = builder.Build();
            var resolver  = new AutofacWebApiDependencyResolver(container);

            GlobalConfiguration.Configuration.DependencyResolver = resolver;
            GlobalConfiguration.Configure(WebApiConfig.Register);
        }
Exemple #3
0
 public static void ConfigureMappings()
 {
     if (_configured)
     {
         return;
     }
     MappingConfiguration.Configure();
     _configured = true;
 }
 public void Configuration(IAppBuilder app)
 {
     app.UseCookieAuthentication(new CookieAuthenticationOptions
     {
         AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
         LoginPath          = new PathString("/Account/LogInPage"),
     });
     MappingConfiguration.Configure();
 }
Exemple #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //TODO: refactor...

            // AutoMapper
            services.AddScoped <IMapper, Mapper>();

            // Application
            services.AddScoped <ICustomerAppService, CustomerAppService>();
            services.AddScoped <IProjectAppService, ProjectAppService>();
            services.AddScoped <IUserAppService, UserAppService>();
            services.AddScoped <IUserProfileAppService, UserProfileAppService>();
            services.AddScoped <IUsersInProjectsAppService, UsersInProjectsAppService>();
            services.AddScoped <IPasswordAppService, PasswordAppService>();
            services.AddScoped <ITestPlanAppService, TestPlanAppService>();
            services.AddScoped <ITestCaseAppService, TestCaseAppService>();
            services.AddScoped <ITestSuiteAppService, TestSuiteAppService>();

            // Repositories
            services.AddScoped <ICustomerRepository, CustomerRepository>();
            services.AddScoped <IProjectRepository, ProjectRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IUserProfileRepository, UserProfileRepository>();
            services.AddScoped <IUsersInProjectsRepository, UsersInProjectsRepository>();
            services.AddScoped <IPasswordRepository, PasswordRepository>();
            services.AddScoped <ITestPlanRepository, TestPlanRepository>();
            services.AddScoped <ITestCaseRepository, TestCaseRepository>();
            services.AddScoped <ITestSuiteRepository, TestSuiteRepository>();

            // Enable the use of an [Authorize("Bearer")] attribute on methods and classes to protect.
            services.AddAuthorization(auth =>
            {
                auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme‌​)
                               .RequireAuthenticatedUser().Build());
            });

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.WithOrigins(Configuration["StarcWebUrl"])
                                  //.AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .WithMethods("*")
                                  .AllowCredentials());
            });

            MappingConfiguration.Configure();

            // Add framework services.
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
            });
        }
Exemple #6
0
        public void Setup()
        {
            _cosmosDbConfiguration = new CosmosDbConfiguration("https://localhost:8081",
                                                               "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "People", "PeopleCollection");

            _documentsToDelete = new List <Documents.Person>();

            var mapper = MappingConfiguration.Configure(new MappingProfile());

            _commandCosmosDbRepository = new CommandCosmosDbRepository <Person, Documents.Person>(_cosmosDbConfiguration, mapper);
        }
Exemple #7
0
        public static void AddDependencyInjectionServices(this IServiceCollection services)
        {
            var mapper = MappingConfiguration.Configure();

            services.AddSingleton(mapper);

            services.AddScoped <IRestClient, RestClient>();

            services.AddScoped <IEmployeeRepository, EmployeeRepository>();

            services.AddScoped <IEmployeeService, EmployeeService>();
        }
Exemple #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionString = Configuration.GetConnectionString("DefaultConnection");

            services.AddMvc();
            services.AddTradeHelperDbContext(connectionString);
            services.AddUnitOfWork();
            services.AddScoped();
            services.AddBll();

            MappingConfiguration.Configure();
        }
Exemple #9
0
        public async Task SetupAsync()
        {
            _cosmosDbConfiguration = new CosmosDbConfiguration("https://localhost:8081",
                                                               "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", "People", "PeopleCollection");

            _mapper = MappingConfiguration.Configure(new MappingProfile());

            _queryCosmosDbRepository = new QueryCosmosDbRepository <Entities.Person, Person>(_cosmosDbConfiguration, _mapper);

            _querySameEntityAndDocumentCosmosDbRepository = new QueryCosmosDbRepository <Entities.Person, Entities.Person>(_cosmosDbConfiguration, _mapper);

            _peopleListToTest = await IntegrationTestsUtils.AddDocumentListToTestAsync(_cosmosDbConfiguration, _mapper).ConfigureAwait(false);
        }
Exemple #10
0
        public CustomersController GetCustomersController()
        {
            var mocker = new AutoMoqer();

            mocker.Create <CustomersController>();

            MappingConfiguration.Configure();
            var customerController = mocker.Resolve <CustomersController>();

            CustomerAppServiceMock = mocker.GetMock <ICustomerAppService>();
            UserAppServiceMock     = mocker.GetMock <IUserAppService>();

            return(customerController);
        }
        public TestPlansController GetTestPlansController()
        {
            var mocker = new AutoMoqer();

            mocker.Create <TestPlansController>();

            MappingConfiguration.Configure();
            var testPlansController = mocker.Resolve <TestPlansController>();

            TestPlanAppServiceMock = mocker.GetMock <ITestPlanAppService>();
            UserAppServiceMock     = mocker.GetMock <IUserAppService>();

            return(testPlansController);
        }
Exemple #12
0
        public ProjectsController GetProjectsController()
        {
            var mocker = new AutoMoqer();

            mocker.Create <ProjectsController>();

            MappingConfiguration.Configure();
            var projectsController = mocker.Resolve <ProjectsController>();

            ProjectAppServiceMock = mocker.GetMock <IProjectAppService>();
            UserAppServiceMock    = mocker.GetMock <IUserAppService>();

            return(projectsController);
        }
Exemple #13
0
        public UsersController GetUsersController()
        {
            var mocker = new AutoMoqer();

            mocker.Create <UsersController>();

            MappingConfiguration.Configure();
            var usersController = mocker.Resolve <UsersController>();

            UserAppServiceMock     = mocker.GetMock <IUserAppService>();
            PasswordAppServiceMock = mocker.GetMock <IPasswordAppService>();

            return(usersController);
        }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMiddleware <ExceptionHandling>();
            app.UseMvc();
            app.UseSwagger();
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint(SwaggerSettings.JsonEndpointAddress, SwaggerSettings.DocumentVersion);
                options.RoutePrefix = string.Empty;
            });

            MappingConfiguration.Configure();
        }
Exemple #15
0
        public void Run(IAppBuilder app)
        {
            MappingConfiguration.Configure();

            Mapper.AssertConfigurationIsValid();

            var adminUsername      = this.configService.GetSetting <string>("AdminUsername", null);
            var adminPassword      = this.configService.GetSetting <string>("AdminPassword", null);
            var identityManagerUri = this.configService.GetSetting <string>("IdentityManagerUri", null);
            var identityAdminUri   = this.configService.GetSetting <string>("IdentityAdminUri", null);

            var options =
                new IdentityServerOptionsService(
                    adminUsername,
                    adminPassword,
                    identityManagerUri,
                    identityAdminUri,
                    userService,
                    externalIdentityProviderService).GetServerOptions();

            app.UseIdentityServer(options);
        }
Exemple #16
0
 public EntityMapper()
 {
     MappingConfiguration.Configure();
 }
Exemple #17
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            Log.Logger.Information("Configuring services...");

            // Add framework services.
            services.AddCors(corsOptions => corsOptions.AddPolicy("default", corsPolicyBuilder =>
            {
                corsPolicyBuilder.AllowAnyOrigin();
                corsPolicyBuilder.AllowAnyHeader();
                corsPolicyBuilder.AllowAnyMethod();
            }));

            services.AddMvc()
            .AddXmlSerializerFormatters()
            .AddJsonOptions(mvcJsonOptions =>
            {
                mvcJsonOptions.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });

            var automapperConfiguration = new MappingConfiguration(Configuration);

            services.AddAutoMapper(config => automapperConfiguration.Configure(config));

            services.AddLogging();
            services.AddMemoryCache();
            services.AddAuthorization(authorizationOptions => AddPolicies(authorizationOptions));
            services.AddDbContext <RuinsContext>(ruinsDbOptions =>
            {
                var connectionString = Configuration.GetSection("connectionStrings:ruinsDb").Value;
                ruinsDbOptions.UseMySql(connectionString);
            });

            services.AddSwaggerGen(swaggerGenOptions =>
            {
                swaggerGenOptions.SwaggerDoc("v1", new Info()
                {
                    Title       = "Canonn API",
                    Version     = "v1",
                    Description = "API for the Canonn research group.",
                    Contact     = new Contact()
                    {
                        Name = "Cmdr. Nopileos",
                        Url  = "https://github.com/gingters",
                    },
                    License = new License()
                    {
                        Name = "Licensed under the MIT license.", Url = "https://opensource.org/licenses/MIT"
                    },
                });

                swaggerGenOptions.AddSecurityDefinition("oauth2", new OAuth2Scheme()
                {
                    Type             = "oauth2",
                    Flow             = "implicit",
                    AuthorizationUrl = $"https://{Configuration.GetSection("clientSecrets:clientDomain").Value}/authorize",
                });

                swaggerGenOptions.OperationFilter <SwaggerSecurityRequirementsOperationFilter>();

                //Set the comments path for the swagger json and ui.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "CanonnApi.Web.xml");
                swaggerGenOptions.IncludeXmlComments(xmlPath);
            });

            services.AddSingleton <IAuthorizationHandler, PermissionAuthorizationHandler>();
            services.Configure <SecretConfiguration>(Configuration.GetSection("clientSecrets"));

            var builder = new ContainerBuilder();

            RegisterAutofacDependencies(builder);

            // When you do service population, it will include your controller types automatically.
            builder.Populate(services);
            // If you want to set up a controller for, say, property injection
            // you can override the controller registration after populating services.

            ApplicationContainer = builder.Build();

            // Create the IServiceProvider based on the container
            return(new AutofacServiceProvider(ApplicationContainer));
        }