public void CannotReuseServiceNames() { var registrar = new BindingRegistrar(); var serviceName = "repeat-me"; registrar.RegisterRandom(serviceName, new Uri("http://first-time")); Action action = () => registrar.RegisterRoundRobin(serviceName, new Uri("http://second-time")); action.Should().Throw <ArgumentException>().WithMessage("Service name is already registered*"); }
public static IServiceCollection AddLoadBalancing(this IServiceCollection services, Action <BindingRegistrar> configure) { var mapper = new BindingRegistrar(); configure(mapper); services.AddSingleton(mapper.Bindings); services.AddTransient <BindingHandler>(); services.AddHttpClient(Options.DefaultName) .AddHttpMessageHandler <BindingHandler>(); return(services); }
public void ScoreFunctionRequiredForAdaptiveBalancers() { var registrar = new BindingRegistrar(); var testUri = new Uri("https://not-really/here"); foreach (var action in new Action[] { () => registrar.RegisterAdaptive("adaptive", null, testUri), () => registrar.RegisterUpdateableAdaptive("updateable", null, testUri) }) { action.Should().Throw <ArgumentNullException>(); } }
public void AtLeastOneUriRequired() { var registrar = new BindingRegistrar(); foreach (var action in new Action[] { () => registrar.RegisterRandom("random"), () => registrar.RegisterRoundRobin("round-robin"), () => registrar.RegisterAdaptive("adaptive", uri => 0), () => registrar.RegisterUpdateableAdaptive("updateable", uri => 1) }) { action.Should().Throw <ArgumentException>().WithMessage("You must provide at least one URI to load balance*"); } }
public void HostNameIsRequired() { var registrar = new BindingRegistrar(); var testUri = new Uri("http://localhost"); foreach (var action in new Action[] { () => registrar.RegisterRandom(null, testUri), () => registrar.RegisterRoundRobin(null, testUri), () => registrar.RegisterAdaptive(null, uri => 0, testUri), () => registrar.RegisterUpdateableAdaptive(null, uri => 1, testUri) }) { action.Should().Throw <ArgumentNullException>(); } }