Beispiel #1
0
        public async Task Register_ConsulClientThrowsException_CallsConsulAndThrowException()
        {
            var loggerFactory = Substitute.For <ILoggerFactory>();
            var consulClient  = Substitute.For <IConsulClient>();

            var expectedException = new Exception();

            consulClient.Agent.ServiceRegister(Arg.Any <AgentServiceRegistration>())
            .Throws(expectedException);

            var service   = new AgentServiceRegistration();
            var registrar = new ConsulServiceRegistrar(loggerFactory, consulClient, service);

            Exception actualException = null;

            try
            {
                await registrar.Register();
            }
            catch (Exception ex)
            {
                actualException = ex;
            }

            Assert.Same(expectedException, actualException);
            await consulClient.Agent.Received(1).ServiceRegister(Arg.Any <AgentServiceRegistration>());
        }
Beispiel #2
0
        public async Task Register_SuccessfulRegistration_CallsConsulAndDoesNotThrowException()
        {
            var loggerFactory = Substitute.For <ILoggerFactory>();
            var consulClient  = Substitute.For <IConsulClient>();

            consulClient.Agent.ServiceRegister(Arg.Any <AgentServiceRegistration>())
            .Returns(new WriteResult {
                RequestTime = TimeSpan.Zero, StatusCode = HttpStatusCode.Created
            });

            var service   = new AgentServiceRegistration();
            var registrar = new ConsulServiceRegistrar(loggerFactory, consulClient, service);

            await registrar.Register();

            await consulClient.Agent.Received(1).ServiceRegister(Arg.Any <AgentServiceRegistration>());
        }