public AdminResources(BusinessDbContext context, ILogger <AdminResources> logger, TokenService tokenService, ExternalServicesConfig config) { _context = context; _logger = logger; _tokenService = tokenService; _config = config; }
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); }
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); }
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); }
/// <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); }
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); }
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); }
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; }
public PaymentsCommandHandler(ExternalServicesConfig externalServicesConfig, IExternalCommandBus externalCommandBus) { this.externalServicesConfig = externalServicesConfig; this.externalCommandBus = externalCommandBus; }
public HrProxy(IOptions <ExternalServicesConfig> config, IRestfulApiClient restfulApiClient) { _config = config.Value; _restfulApiClient = restfulApiClient; }
public HandleDiscardPayment(ExternalServicesConfig externalServicesConfig, IExternalCommandBus externalCommandBus) { this.externalServicesConfig = externalServicesConfig; this.externalCommandBus = externalCommandBus; }
private async void InitializeToken(ExternalServicesConfig config) { var tokenResponse = await PostForTokenAsync(config.TokenEndpoint, config.UserName, config.Password); _httpClient.SetBearerToken(tokenResponse.data.token); }
public HandleSendPackage(ExternalServicesConfig externalServicesConfig, IExternalCommandBus externalCommandBus) { this.externalServicesConfig = externalServicesConfig; this.externalCommandBus = externalCommandBus; }