public async Task Setup() { IDiscovery discovery = Substitute.For <IDiscovery>(); _discoveryConfig = new DiscoveryConfig { Services = new ServiceDiscoveryCollection(new Dictionary <string, ServiceDiscoveryConfig>(), new ServiceDiscoveryConfig(), new PortAllocationConfig()) }; Dictionary <string, string> configDic = new Dictionary <string, string>(); _currentEnvironment = Prod; var environment = Substitute.For <IEnvironment>(); environment.DeploymentEnvironment.Returns(_ => _currentEnvironment); _unitTestingKernel = new TestingKernel <ConsoleLog>(mockConfig: configDic); _unitTestingKernel.Rebind <IEnvironment>().ToConstant(environment); _unitTestingKernel.Rebind <IDiscovery>().ToConstant(discovery); _unitTestingKernel.Rebind <Func <DiscoveryConfig> >().ToMethod(_ => () => _discoveryConfig); _loadBalancerByEnvironment = new Dictionary <string, ILoadBalancer>(); _loadBalancerByEnvironment.Add(Prod, new MasterLoadBalancer()); _loadBalancerByEnvironment.Add(Staging, new StagingLoadBalancer()); _loadBalancerByEnvironment.Add(Canary, new PreferredEnvironmentLoadBalancer()); discovery.CreateLoadBalancer(Arg.Any <DeploymentIdentifier>(), Arg.Any <ReachabilityCheck>(), TrafficRoutingStrategy.RandomByRequestID) .ReturnsForAnyArgs(c => _loadBalancerByEnvironment[c.Arg <DeploymentIdentifier>().DeploymentEnvironment]); _serviceDiscovery = _unitTestingKernel.Get <Func <string, ReachabilityCheck, IMultiEnvironmentServiceDiscovery> >()(ServiceName, (x, y) => new Task(null)); TracingContext.SetPreferredEnvironment(null); }
public void TearDown() { _unitTestingKernel.Dispose(); _loadBalancerByEnvironment.Clear(); _serviceDiscovery = null; }