コード例 #1
0
        public void GetStatusAsync_ThrowsOnNull()
        {
            var clientMoq = new Mock <IConsulClient>();
            var agentMoq  = new Mock <IAgentEndpoint>();

            clientMoq.Setup(c => c.Agent).Returns(agentMoq.Object);

            var opts = new ConsulDiscoveryOptions();
            var sch  = new TtlScheduler(opts, clientMoq.Object);

            var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch);

            Assert.ThrowsAsync <ArgumentNullException>(() => reg.GetStatusAsync(null));
        }
コード例 #2
0
        public async void GetStatusAsync_ReturnsExpected()
        {
            var opts    = new ConsulDiscoveryOptions();
            var builder = new ConfigurationBuilder()
                          .AddInMemoryCollection(new Dictionary <string, string>()
            {
                { "spring:application:name", "foobar" }
            });
            var config       = builder.Build();
            var registration = ConsulRegistration.CreateRegistration(config, opts);

            var queryResult = new QueryResult <HealthCheck[]>()
            {
                Response = new HealthCheck[]
                {
                    new HealthCheck()
                    {
                        ServiceID = registration.InstanceId,
                        Name      = "Service Maintenance Mode"
                    },
                    new HealthCheck()
                    {
                        ServiceID = "foobar",
                        Name      = "Service Maintenance Mode"
                    }
                }
            };
            var result = Task.FromResult(queryResult);

            var clientMoq = new Mock <IConsulClient>();
            var healthMoq = new Mock <IHealthEndpoint>();

            clientMoq.Setup(c => c.Health).Returns(healthMoq.Object);
            healthMoq.Setup(h => h.Checks(registration.ServiceId, QueryOptions.Default, default(CancellationToken))).Returns(result);

            var sch = new TtlScheduler(opts, clientMoq.Object);
            var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch);

            var ret = await reg.GetStatusAsync(registration);

            Assert.Equal("OUT_OF_SERVICE", ret);
        }