public void AddInfoActuator_AddsCorrectServices()
        {
            ServiceCollection services = new ServiceCollection();
            var    appsettings         = @"
{
    'management': {
        'endpoints': {
            'enabled': false,
            'sensitive': false,
            'path': '/management',
            'info' : {
                'enabled': false,
                'sensitive': false,
                'id': 'infomanagement'
            }
        }
    }
}";
            var    path      = TestHelpers.CreateTempFile(appsettings);
            string directory = Path.GetDirectoryName(path);
            string fileName  = Path.GetFileName(path);
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.SetBasePath(directory);

            configurationBuilder.AddJsonFile(fileName);
            var config = configurationBuilder.Build();

            services.AddInfoActuator(config);

            IInfoContributor extra = new TestInfoContributor();

            services.AddSingleton <IInfoContributor>(extra);
            ILogger <InfoEndpoint> logger = new TestLogger();

            services.AddSingleton <ILogger <InfoEndpoint> >(logger);

            var serviceProvider = services.BuildServiceProvider();
            var options         = serviceProvider.GetService <IInfoOptions>();

            Assert.NotNull(options);
            var contribs = serviceProvider.GetServices <IInfoContributor>();

            Assert.NotNull(contribs);
            var listOfContribs = contribs.ToList();

            Assert.Equal(3, listOfContribs.Count);

            Assert.Contains(contribs, (item) => {
                return
                (item.GetType() == typeof(GitInfoContributor) ||
                 item.GetType() == typeof(AppSettingsInfoContributor) ||
                 item.GetType() == typeof(TestInfoContributor));
            }
                            );

            var ep = serviceProvider.GetService <InfoEndpoint>();

            Assert.NotNull(ep);
        }
예제 #2
0
        public void AddInfoActuator_AddsCorrectServices()
        {
            ServiceCollection services = new ServiceCollection();
            var appSettings            = new Dictionary <string, string>()
            {
                ["management:endpoints:enabled"]        = "false",
                ["management:endpoints:sensitive"]      = "false",
                ["management:endpoints:path"]           = "/management",
                ["management:endpoints:info:enabled"]   = "false",
                ["management:endpoints:info:sensitive"] = "false",
                ["management:endpoints:info:id"]        = "infomanagement"
            };
            ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddInMemoryCollection(appSettings);
            var config = configurationBuilder.Build();

            services.AddInfoActuator(config);

            IInfoContributor extra = new TestInfoContributor();

            services.AddSingleton <IInfoContributor>(extra);
            ILogger <InfoEndpoint> logger = new TestLogger();

            services.AddSingleton <ILogger <InfoEndpoint> >(logger);

            var serviceProvider = services.BuildServiceProvider();
            var options         = serviceProvider.GetService <IInfoOptions>();

            Assert.NotNull(options);
            var contribs = serviceProvider.GetServices <IInfoContributor>();

            Assert.NotNull(contribs);
            var listOfContribs = contribs.ToList();

            Assert.Equal(3, listOfContribs.Count);

            Assert.Contains(contribs, (item) =>
            {
                return
                (item.GetType() == typeof(GitInfoContributor) ||
                 item.GetType() == typeof(AppSettingsInfoContributor) ||
                 item.GetType() == typeof(TestInfoContributor));
            });

            var ep = serviceProvider.GetService <InfoEndpoint>();

            Assert.NotNull(ep);
        }