示例#1
0
        public PlanesControllerTests()
        {
            var            mapper  = MyMapperConfiguration.GetConfiguration().CreateMapper();
            AirportService service = new AirportService(new FakeUnitOfWork());

            _controller = new PlanesController(mapper, service);
        }
示例#2
0
        public CreateUpdateTests()
        {
            _mapper = MyMapperConfiguration.GetConfiguration().CreateMapper();
            var unitOfWork = new FakeUnitOfWork();

            _service = new AirportService(unitOfWork);
        }
示例#3
0
        public FullAPITests()
        {
            var kernel = new StandardKernel(new AirPortServiceModule());
            var mapper = MyMapperConfiguration.GetConfiguration().CreateMapper();

            _flightController = new FlightsController(mapper, kernel.Get <AirportService>());
            _ticketController = new TicketsController(mapper, kernel.Get <AirportService>());
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddScoped <IUnitOfWork, AirportUnitOfWork>();
            services.AddScoped <AirportService>();
            services.AddScoped <UserService>();
            services.AddMvc();
            services.AddScoped <IMapper>(sp => MyMapperConfiguration.GetConfiguration());


            services.AddDbContext <AirportContext>(options =>
                                                   options.UseSqlServer(Configuration.GetConnectionString("AirportConnectionString"), b => b.MigrationsAssembly("Presentation Layer")));


            // configure strongly typed settings objects
            var appSettingsSection = Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);

            // configure jwt authentication
            var appSettings = appSettingsSection.Get <AppSettings>();
            var key         = Encoding.ASCII.GetBytes(appSettings.Secret);

            services.AddAuthentication(x => {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x => {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false
                };
            });

            // Cors
            services.AddCors(o => o.AddPolicy("MyPolicy", builder => {
                builder.WithOrigins("http://localhost:8080")
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials();
            }));
        }
示例#5
0
        public MapperConfiguration MapperConfiguration()
        {
            var config = MyMapperConfiguration.GetConfiguration();

            return(config);
        }