コード例 #1
0
        public void AddServiceDiscovery_IWebHostBuilder_AddsServiceDiscovery_Consul()
        {
            // Arrange
            var hostBuilder = new WebHostBuilder().Configure(configure => { }).ConfigureAppConfiguration(cbuilder => cbuilder.AddInMemoryCollection(ConsulSettings));

            // Act
            var host            = hostBuilder.AddServiceDiscovery(builder => builder.UseConsul()).Build();
            var discoveryClient = host.Services.GetServices <IDiscoveryClient>();
            var hostedService   = host.Services.GetService <IHostedService>();

            // Assert
            Assert.Single(discoveryClient);
            Assert.IsType <ConsulDiscoveryClient>(discoveryClient.First());
            Assert.IsType <DiscoveryClientService>(hostedService);
        }
コード例 #2
0
        public void AddServiceDiscovery_IWebHostBuilder_AddsServiceDiscovery_Eureka()
        {
            // Arrange
            var hostBuilder = new WebHostBuilder().Configure(configure => { }).ConfigureAppConfiguration(cbuilder => cbuilder.AddInMemoryCollection(eurekaSettings));

            // Act
            var host            = hostBuilder.AddServiceDiscovery().Build();
            var discoveryClient = host.Services.GetServices <IDiscoveryClient>();
            var filters         = host.Services.GetServices <IStartupFilter>();

            // Assert
            Assert.Single(discoveryClient);
            Assert.IsType <EurekaDiscoveryClient>(discoveryClient.First());
            Assert.NotEmpty(filters);
            Assert.Contains(filters, f => f.GetType() == typeof(DiscoveryClientStartupFilter));
        }