public void Initialize()
        {
            var configuration = TestHelper.InitializeConfiguration("appsettings.json");

            Assert.IsNotNull(configuration);

            var generalSettings = GeneralSettingsBuilder.Build(configuration);

            var hrNewClientSettings = HrNewsClientSettingsBuilder.Build(configuration);

            Assert.IsNotNull(hrNewClientSettings);

            const string expectedUrl = "https://hacker-news.firebaseio.com/v0/";

            Assert.AreEqual(expectedUrl, hrNewClientSettings.HrNewsApiUrl);

            const string expectedConnectionString = "DefaultEndpointsProtocol=https;AccountName=hsbhrnewssa;AccountKey=0pJza+M3O0ynLUuiOFwFHje81cU9RlTOp1PbObbcrpFTYy8bk1ryibaWNd9PA5ey7CbBoQBgfITWuxWm+5bFvQ==;EndpointSuffix=core.windows.net";

            Assert.AreEqual(expectedConnectionString, generalSettings.AzureStorageConnectionString);

            _repo = new HrNewsRepository(generalSettings);

            Assert.IsNotNull(_repo);

            _service = new HrNewsWebApiService(hrNewClientSettings);

            Assert.IsNotNull(_service);
        }
Esempio n. 2
0
        private static async Task Main(string[] args)
        {
            var builder = new HostBuilder();

            builder.ConfigureWebJobs((context, jobsBuilder) =>
            {
                jobsBuilder.AddAzureStorageCoreServices();
                jobsBuilder.AddAzureStorage();
                jobsBuilder.AddTimers();
            }).ConfigureAppConfiguration(configurationBuilder =>
            {
                // Adding command line as additional configuration source
                configurationBuilder.AddCommandLine(args);

                configurationBuilder.AddJsonFile("./appsettings.json",
                                                 optional: false,
                                                 reloadOnChange: false);
            })
            .ConfigureLogging(loggingBuilder => { loggingBuilder.AddNLog(); })
            .ConfigureServices((context, services) =>
            {
                services.AddSingleton(context.Configuration);
                services.AddMemoryCache();

                //IHrNewsWebApiService service, IHrNewsRepository repo

                // other DI configuration here
                var generalSettings = GeneralSettingsBuilder.Build(context.Configuration);
                services.AddSingleton(generalSettings);

                var hrSettings = HrNewsClientSettingsBuilder.Build(context.Configuration);
                services.AddSingleton(hrSettings);

                services.AddScoped <IHrNewsRepository, HrNewsRepository>();
                services.AddScoped <IHrNewsWebApiService, HrNewsWebApiService>();

                services.AddSingleton(services);

                // add the hosted service.  HostBuilder will start this automatically
                services.AddSingleton <IHostedService, Host>();
            })
            .UseConsoleLifetime();

            var host = builder.Build();

            Services = host.Services;

            using (host)
            {
                await host.RunAsync();
            }
        }
        public void Initialize()
        {
            var configuration = TestHelper.InitializeConfiguration("appsettings.json");

            Assert.IsNotNull(configuration);

            var hrNewClientSettings = HrNewsClientSettingsBuilder.Build(configuration);

            Assert.IsNotNull(hrNewClientSettings);

            const string expectedUrl = "https://hacker-news.firebaseio.com/v0/";

            Assert.AreEqual(expectedUrl, hrNewClientSettings.HrNewsApiUrl);

            _service = new HrNewsWebApiService(hrNewClientSettings);

            Assert.IsNotNull(_service);
        }