コード例 #1
0
        public AdminResources(BusinessDbContext context, ILogger <AdminResources> logger, TokenService tokenService, ExternalServicesConfig config)
        {
            _context = context;
            _logger  = logger;

            _tokenService = tokenService;
            _config       = config;
        }
コード例 #2
0
        public void SetUp()
        {
            _externalConfigContext = new ExternalServicesConfig
            {
                Hr = new HR
                {
                    BaseUrl = "http://10.37.35.103:5100",
                    IdentityCertificationPath = "hrapi_external/Portal_dlemp",
                    Account  = "PortalAPP",
                    PassWord = "******"
                }
            };
            _httpClient = new HttpClient();

            _targetObj = new RestfulApiClient(_httpClient);
        }
コード例 #3
0
        public void Validate_External_Config()
        {
            //Arrange
            ExpectedObject expected = new ExternalServicesConfig
            {
                Hr = new HR
                {
                    BaseUrl = "http://10.37.35.103:5100",
                    IdentityCertificationPath = "hrapi_external/Portal_dlemp",
                    Account  = "PortalAPP",
                    PassWord = "******"
                }
            }.ToExpectedObject();

            //Assert
            expected.ShouldEqual(_externalConfigContext);
        }
コード例 #4
0
        public async Task GetWeatherForecastAsync_ReturnsNull_WhenAnExceptionOccurs()
        {
            var config = new ExternalServicesConfig {
                Url = "http://www.example.com", MinsToCache = 0
            };

            var mockOptions = new Mock <IOptionsMonitor <ExternalServicesConfig> >();

            mockOptions.Setup(x => x.Get(It.IsAny <string>())).Returns(config);

            var client = new HttpClient(new ExceptionHandler());

            var sut = new WeatherApiClient(client, mockOptions.Object, NullLogger <WeatherApiClient> .Instance);

            var result = await sut.GetWeatherForecastAsync();

            Assert.Null(result);
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: hoosierhub/cal-notify
        /// <summary>
        /// Inits our Configuration and Loggers
        /// Depending on the environment it may load up different configurations which affect api keys, logging, etc.
        /// The environment is typically set to one of Development, Staging, or Production
        /// </summary>
        /// <param name="env"></param>
        public Startup(IHostingEnvironment env)
        {
            // save our environemnt for later
            _hostingEnv = env;

            // Setting up our configuration

            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile(path: "appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile(path: $"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
                          .AddJsonFile(path: "appsettings.Local.json", optional: true, reloadOnChange: true);

            //.AddEnvironmentVariables();  // not adding environment variables for now

            Configuration = builder.Build();

            // use poco for config
            ExternalServicesConfig = new ExternalServicesConfig();
            Configuration.GetSection("Services").Bind(ExternalServicesConfig);


            var loggerConfig = new LoggerConfiguration();


            loggerConfig
            .Enrich.FromLogContext().Enrich.WithProperty("SourceContext", AssemblyName)
            // Application level events
            .WriteTo.Logger(lc => lc
                            .Filter.ByIncludingOnly(Matching.FromSource(AssemblyName))
                            .WriteTo.Console().WriteTo.RollingFile("logs/api-{Date}.txt"))
            // DB logging
            .WriteTo.Logger(lc => lc
                            .Filter.ByIncludingOnly(Matching.FromSource("Microsoft.EntityFramework"))
                            .WriteTo.RollingFile("logs/db-{Date}.txt"))
            // All events
            .WriteTo.RollingFile("logs/all-{Date}.txt");


            Log.Logger = loggerConfig.CreateLogger();

            Log.Information("Our Content Root is {ContentRoot}", _hostingEnv.ContentRootPath);
            Log.Information("Running server under a {env} environment", env.EnvironmentName);
        }
コード例 #6
0
        public async Task GetWeatherForecastAsync_ReturnsWeatherApiResult_WhenHttpRequestSucceeds()
        {
            var config = new ExternalServicesConfig {
                Url = "http://www.example.com", MinsToCache = 0
            };

            var mockOptions = new Mock <IOptionsMonitor <ExternalServicesConfig> >();

            mockOptions.Setup(x => x.Get(It.IsAny <string>())).Returns(config);

            var client = new HttpClient(new SuccessHandler());

            var sut = new WeatherApiClient(client, mockOptions.Object, NullLogger <WeatherApiClient> .Instance);

            var result = await sut.GetWeatherForecastAsync();

            Assert.IsType <WeatherApiResult>(result);
            Assert.Equal("London", result.City);
        }
コード例 #7
0
        public void SetUp()
        {
            ExternalServicesConfig externalServicesConfig = new ExternalServicesConfig
            {
                Hr = new HR
                {
                    BaseUrl = "http://10.37.35.103:5100",
                    IdentityCertificationPath = "hrapi_external/Portal_dlemp",
                    Account  = "PortalAPP",
                    PassWord = "******"
                }
            };

            _optionsExternalServicesConfig = Options.Create(externalServicesConfig);

            _restfulApiClient = Substitute.For <IRestfulApiClient>();

            _targetObj = new HrProxy(_optionsExternalServicesConfig, _restfulApiClient);
        }
コード例 #8
0
        public GenericUserAuth(
            BusinessDbContext context,
            ValidationSender validation,
            ILogger <GenericUserAuth> logger,
            ITokenMemoryCache memoryCache,

            TokenService tokenService,
            IHostingEnvironment hostingEnvironment, ExternalServicesConfig config)
        {
            _context    = context;
            _validation = validation;
            _logger     = logger;


            _tokenService = tokenService;
            _memoryCache  = memoryCache;

            _hostingEnvironment = hostingEnvironment;
            _config             = config;
        }
コード例 #9
0
 public PaymentsCommandHandler(ExternalServicesConfig externalServicesConfig,
                               IExternalCommandBus externalCommandBus)
 {
     this.externalServicesConfig = externalServicesConfig;
     this.externalCommandBus     = externalCommandBus;
 }
コード例 #10
0
ファイル: HrProxy.cs プロジェクト: Gary418Wu/AppStore-MVC
 public HrProxy(IOptions <ExternalServicesConfig> config, IRestfulApiClient restfulApiClient)
 {
     _config           = config.Value;
     _restfulApiClient = restfulApiClient;
 }
コード例 #11
0
 public HandleDiscardPayment(ExternalServicesConfig externalServicesConfig,
                             IExternalCommandBus externalCommandBus)
 {
     this.externalServicesConfig = externalServicesConfig;
     this.externalCommandBus     = externalCommandBus;
 }
コード例 #12
0
        private async void InitializeToken(ExternalServicesConfig config)
        {
            var tokenResponse = await PostForTokenAsync(config.TokenEndpoint, config.UserName, config.Password);

            _httpClient.SetBearerToken(tokenResponse.data.token);
        }
コード例 #13
0
 public HandleSendPackage(ExternalServicesConfig externalServicesConfig, IExternalCommandBus externalCommandBus)
 {
     this.externalServicesConfig = externalServicesConfig;
     this.externalCommandBus     = externalCommandBus;
 }