public async void SetStatusAsync_CallsConsulClient()
        {
            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 builder = new ConfigurationBuilder()
                          .AddInMemoryCollection(new Dictionary <string, string>()
            {
                { "spring:application:name", "foobar" }
            });
            var config       = builder.Build();
            var registration = ConsulRegistration.CreateRegistration(config, opts);

            var reg = new ConsulServiceRegistry(clientMoq.Object, opts, sch);
            await reg.SetStatusAsync(registration, "Up");

            agentMoq.Verify(a => a.DisableServiceMaintenance(registration.InstanceId, default(CancellationToken)), Times.Once);
            await reg.SetStatusAsync(registration, "Out_of_Service");

            agentMoq.Verify(a => a.EnableServiceMaintenance(registration.InstanceId, "OUT_OF_SERVICE", default(CancellationToken)), Times.Once);
        }
        public void SetStatusAsync_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.SetStatusAsync(null, string.Empty));
        }
        public void SetStatusAsync_ThrowsInvalidStatus()
        {
            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 builder = new ConfigurationBuilder()
                          .AddInMemoryCollection(new Dictionary <string, string>()
            {
                { "spring:application:name", "foobar" }
            });
            var config       = builder.Build();
            var registration = ConsulRegistration.CreateRegistration(config, opts);

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

            Assert.ThrowsAsync <ArgumentException>(() => reg.SetStatusAsync(registration, string.Empty));
        }