public async Task GetServicesAsync_NotUseCache_Test()
        {
            string serviceName = "test";

            var consulClient = A.Fake <IConsulClient>();
            var discovery    = new ConsulServiceDiscovery(consulClient, false, 0);

            A.CallTo(() => consulClient.Health.Service(serviceName, "", true, default))
            .Returns(
                Task.FromResult(
                    new QueryResult <ServiceEntry[]>(new QueryResult(), new ServiceEntry[] { }))
                );

            var services = await discovery.GetServicesAsync("test");

            var services2 = await discovery.GetServicesAsync("test");

            A.CallTo(() => consulClient.Health.Service(serviceName, "", true, default)).MustHaveHappened(2, Times.Exactly);
        }
Ejemplo n.º 2
0
        static void RegisterAndGetServices()
        {
            var consulClient = ConsulClientFactory.Create(new ConsulDiscoveryConfiguration()
            {
                Address = consulAddress
            });
            ConsulServiceRegistrar registrar = new ConsulServiceRegistrar(consulClient);
            var info  = registrar.RegisterServiceAsync("testServiceName", "v1.0", "192.168.0.81", 8080).Result;
            var info2 = registrar.RegisterServiceAsync("testServiceName", "v1.1", "192.168.0.81", 8090).Result;
            var info3 = registrar.RegisterServiceAsync("testServiceName", "v1.0", "192.168.0.81", 10101).Result;

            ConsulServiceDiscovery discovery = new ConsulServiceDiscovery(consulClient, new ConsulDiscoveryConfiguration()
            {
                Address = consulAddress
            });

            var services = discovery.GetServicesAsync("testServiceName").Result;

            var services2 = discovery.GetServicesAsync("testServiceName", "v1.0").Result;

            var service = discovery.GetServiceAsync("testServiceName").Result;
        }