Пример #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseCors("CorsPolicy");

            var mapper = app.ApplicationServices.GetService <IMapper>();

            GlobalMapper.Init(mapper);

            if (AppSettings.IS_DEBUG)
            {
                app.UseDeveloperExceptionPage();
            }
            UseExceptionBinder_Local(app, AppSettings.IS_DEBUG);
            if (AppSettings.IS_DEBUG)
            {
                app.UseMiddleware <RewindHttpStreamsMiddleware>();
                app.UseAllRequestsLogging("requestsLogs");
            }
            //app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            UseSwaggerUI_Local(app);
        }
Пример #2
0
        public void ShouldBeSuccessToPaidOrder()
        {
            //Arrange
            var order = FakerOrder.GetSampleWithItems(3);

            order.Close();

            var model = new PaidOrderModel()
            {
                Id = order.Id,
                TotalPaidInCents = order.TotalInCents
            };

            _repositoryMock.Setup(r => r.Get(It.Is <Guid>(id => id == order.Id))).Returns(order);
            _repositoryMock.Setup(r => r.Update(It.Is <Order>(o => o.Id == order.Id))).Returns(order);

            //Act
            var response = _service.PaidOrder(model);

            //Assert
            var output = GlobalMapper.Map <Result <OrderModelOutput> >(response);

            var validateTest = response.Success &&
                               output.Data.Status == EOrderStatus.Paid;

            _repositoryMock.Verify(r => r.Get(It.Is <Guid>(id => id == order.Id)), Times.Once);
            _repositoryMock.Verify(r => r.Update(It.Is <Order>(o => o.Id == order.Id)), Times.Once);

            validateTest.Should().BeTrue();
        }
Пример #3
0
        public static void LoadAllAssembliesFromBin()
        {
            string binPath          = System.AppDomain.CurrentDomain.BaseDirectory; // note: don't use CurrentEntryAssembly or anything like that.
            var    thisAssemblyName = Assembly.GetExecutingAssembly().ManifestModule.ToString();

            foreach (string dll in Directory.GetFiles(binPath, "*.dll", SearchOption.AllDirectories))
            {
                try
                {
                    if (dll.EndsWith(thisAssemblyName))
                    {
                        continue;
                    }
                    Assembly loadedAssembly = Assembly.LoadFrom(dll);
                    var      asm            = AppDomain.CurrentDomain.Load(loadedAssembly.FullName);
                    foreach (var type in asm.GetTypes())
                    {
                        if (type.GetInterfaces().Contains(typeof(IServicesRegistration)))
                        {
                            var registration = Activator.CreateInstance(type) as IServicesRegistration;
                            servicesRegistrationList.Add(registration);
                        }
                        if (!type.IsAbstract && type.GetInterfaces().Contains(typeof(IProfileConfiguration)) && type.GetConstructor(Type.EmptyTypes) != null)
                        {
                            var profile = Activator.CreateInstance(type) as Profile;
                            profileList.Add(profile);
                        }
                    }
                }
                catch (FileLoadException)
                { } // The Assembly has already been loaded.
                catch (BadImageFormatException)
                { } // If a BadImageFormatException exception is thrown, the file is not an assembly.
                catch (FileNotFoundException)
                { }
            }
            var container = ContainerBuilder;

            // foreach dll
            servicesRegistrationList.OrderBy(x => x.Priority).ToList()
            .ForEach(x =>
            {
                x.Register(ref container);
            });
            GlobalMapper.Init(profileList);
        }
Пример #4
0
        public void ShouldBeSuccessToBeginOrder()
        {
            //Arrange
            _repositoryMock.Setup(r => r.Insert(It.IsAny <Order>())).Returns(FakerOrder.GetSample());

            //Act
            var response = _service.BeginOrder();

            //Assert
            var output = GlobalMapper.Map <Result <OrderModelOutput> >(response);

            var validateTest = response.Success &&
                               output.Data.Status == EOrderStatus.Pending;

            _repositoryMock.Verify(r => r.Insert(It.IsAny <Order>()), Times.Once);

            validateTest.Should().BeTrue();
        }
        public object CreateUser()
        {
            var form    = this.BindFromForm <CreateUserRequest>();
            var request = this.BindFromBody <CreateUserRequest>();
            var query   = this.BindFromQuery <CreateUserRequest>();

            this.AdditionalInfo.Data.Add("AccountId", "Test");
            this.AdditionalInfo.Data.Add("MerchantId", "Test2");

            this.ValidateRequest(form);
            this.ValidateRequest(request);
            this.ValidateRequest(query);

            var response = new ApiResponse {
                StatusCode = System.Net.HttpStatusCode.OK
            };

            response.Content = GlobalMapper.Map <GetUserResponse>(request);

            return(this.CreateJsonResponse(response));
        }
Пример #6
0
 public ApiFunctions(IConfiguration configuration = null)
 {
     _context = new CupContextFactory(configuration).CreateDbContext(null);
     _mapper  = GlobalMapper.Activate();
 }
Пример #7
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime appLifetime,
                              IDynamicLinkCustomTypeProvider dynamicLinkCustomTypeProvider,
                              ISecretsManager secretsManager)
        {
            // Secrets
            Settings.Get <JwtSettings>().SecretKey = secretsManager.Get(JwtSettings.ConfigKey);

            // Configurations
            app.RegisterOptionsChangeHandlers(typeof(AppSettings),
                                              typeof(JwtSettings));

            // AutoMapper
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(StartupConfig.TempAssemblyList);
            });

            GlobalMapper.Init(mapConfig.CreateMapper());

            // Dynamic Linq
            DynamicLinqConsts.DefaultParsingConfig = new ParsingConfig
            {
                CustomTypeProvider = dynamicLinkCustomTypeProvider
            };

            // HttpContext
            app.ConfigureHttpContext();

            #region Serilog
            if (!_requestLoggingOptions.UseDefaultLogger)
            {
                var requestLogger = Configuration.ParseLogger(
                    LoggingConsts.RequestLoggingOptionsKey, app.ApplicationServices);
                app.UseDefaultSerilogRequestLogging(_requestLoggingOptions, requestLogger);
                _resources.Add(requestLogger);
            }
            else
            {
                app.UseDefaultSerilogRequestLogging(_requestLoggingOptions);
            }
            #endregion

            app.UseExceptionHandler($"/{Routing.Controller.Error.Route}");

            app.UseRequestFeature();

            app.UseStaticFiles();

            app.UseHttpsRedirection();

            app.UseRequestLocalization();

            app.UseRouting();

            // 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", "My API V1");
                c.RoutePrefix = string.Empty;
                c.InjectStylesheet("/custom-swagger-ui.css");
            });

            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowCredentials();
                //builder.AllowAnyOrigin();
                builder.SetIsOriginAllowed(origin =>
                {
                    return(true);
                });
            });

            app.UseAuthentication();

            app.UseRequestDataExtraction();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // app lifetime
            appLifetime.ApplicationStarted.Register(OnApplicationStarted);
            appLifetime.ApplicationStopped.Register(OnApplicationStopped);

            PrepareEnvironment(env);
        }
Пример #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime appLifetime,
                              IDynamicLinkCustomTypeProvider dynamicLinkCustomTypeProvider,
                              ISecretsManager secretsManager)
        {
            // Secrets
            Settings.SecretsManager = secretsManager;
            Settings.Jwt.SecretKey  = secretsManager.Get(JwtSettings.ConfigKey);

            // Configurations
            app.RegisterOptionsChangeHandlers(typeof(AppSettings),
                                              typeof(JwtSettings),
                                              typeof(ApiSettings));

            // AutoMapper
            var mapConfig = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(_tempAssemblyList);
            });

            GlobalMapper.Init(mapConfig.CreateMapper());

            // Dynamic Linq
            DynamicLinqEntityTypeProvider.DefaultParsingConfig = new ParsingConfig
            {
                CustomTypeProvider = dynamicLinkCustomTypeProvider
            };

            // i18n
            Time.Providers.Default      = Time.Providers.Utc;
            Time.ThreadTimeZoneProvider = new HttpThreadTimeZoneProvider();

            // HttpContext
            app.ConfigureHttpContext();

            // BusinessContext
            app.ConfigureBusinessContext();

            // UnitOfWork
            app.ConfigureUnitOfWork();

            PrepareEnvironment(env);

            if (env.IsDevelopment())
            {
                // configure dev settings
            }

            #region Serilog
            if (!_requestLoggingOptions.UseDefaultLogger)
            {
                _requestLogger = Configuration.ParseLogger(
                    ConfigConsts.Logging.RequestLoggingOptionsKey, app.ApplicationServices);
            }

            app.UseDefaultSerilogRequestLogging(_requestLoggingOptions, _requestLogger);
            #endregion

            app.UseExceptionHandler($"/{ApiEndpoint.Error}");

            app.UseRequestFeature();

            app.UseStaticFiles();

            app.UseHttpsRedirection();

            app.UseRequestLocalization();

            app.UseRouting();

            // 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", "My API V1");
                c.RoutePrefix = string.Empty;
            });

            app.UseCors(builder =>
            {
                builder.AllowAnyHeader();
                builder.AllowAnyMethod();
                builder.AllowCredentials();
                //builder.AllowAnyOrigin();
                builder.SetIsOriginAllowed(origin =>
                {
                    return(true);
                });
            });

            app.UseRequestTimeZone();

            app.UseAuthentication();

            app.UseRequestDataExtraction();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            // app lifetime
            appLifetime.ApplicationStarted.Register(OnApplicationStarted);
            appLifetime.ApplicationStopped.Register(OnApplicationStopped);
        }