public async Task Deregister_ConsulClientThrowsException_CallsConsulAndThrowException() { var loggerFactory = Substitute.For <ILoggerFactory>(); var consulClient = Substitute.For <IConsulClient>(); var expectedException = new Exception(); consulClient.Agent.ServiceDeregister(Arg.Any <string>()) .Throws(expectedException); var service = new AgentServiceRegistration(); var registrar = new ConsulServiceRegistrar(loggerFactory, consulClient, service); Exception actualException = null; try { await registrar.Deregister(); } catch (Exception ex) { actualException = ex; } Assert.Same(expectedException, actualException); await consulClient.Agent.Received(1).ServiceDeregister(Arg.Any <string>()); }
public async Task Deregister_ConsulReturnsNonSuccessfulHttpStatusBelow200_CallsConsulAndThrowException() { var loggerFactory = Substitute.For <ILoggerFactory>(); var consulClient = Substitute.For <IConsulClient>(); consulClient.Agent.ServiceDeregister(Arg.Any <string>()) .Returns(new WriteResult { RequestTime = TimeSpan.Zero, StatusCode = HttpStatusCode.Continue }); var service = new AgentServiceRegistration(); var registrar = new ConsulServiceRegistrar(loggerFactory, consulClient, service); Exception exception = null; try { await registrar.Deregister(); } catch (Exception ex) { exception = ex; } Assert.NotNull(exception); await consulClient.Agent.Received(1).ServiceDeregister(Arg.Any <string>()); }
public void Deregister_CallsRegistry() { var regMoq = new Mock <IConsulServiceRegistry>(); var options = new ConsulDiscoveryOptions(); var registration = new ConsulRegistration(); var reg = new ConsulServiceRegistrar(regMoq.Object, options, registration); reg.Deregister(); regMoq.Verify(a => a.Deregister(registration), Times.Once); }
public void Deregister_DoesNotCallRegistry() { var regMoq = new Mock <IConsulServiceRegistry>(); var options = new ConsulDiscoveryOptions() { Deregister = false }; var registration = new ConsulRegistration(); var reg = new ConsulServiceRegistrar(regMoq.Object, options, registration); reg.Deregister(); regMoq.Verify(a => a.Deregister(registration), Times.Never); }
public async Task Deregister_SuccessfulRegistration_CallsConsulAndDoesNotThrowException() { var loggerFactory = Substitute.For <ILoggerFactory>(); var consulClient = Substitute.For <IConsulClient>(); consulClient.Agent.ServiceDeregister(Arg.Any <string>()) .Returns(new WriteResult { RequestTime = TimeSpan.Zero, StatusCode = HttpStatusCode.Created }); var service = new AgentServiceRegistration(); var registrar = new ConsulServiceRegistrar(loggerFactory, consulClient, service); await registrar.Deregister(); await consulClient.Agent.Received(1).ServiceDeregister(Arg.Any <string>()); }