public void QueryNotDefinendShouldFallBackToMaster()
        {
            SetMockToReturnHost(_masterService);
            SetMockToReturnQueryNotFound(_originatingService);
            var nextHost = GetServiceDiscovey.GetNextHost();

            nextHost.Result.HostName.ShouldBe(_masterService);
        }
        public async Task ScopeDataCenterShouldUseServiceNameAsConsoleQuery()
        {
            _configDic[$"Discovery.Services.{SERVICE_NAME}.Scope"] = "DataCenter";
            SetMockToReturnHost(SERVICE_NAME);
            var nextHost = GetServiceDiscovey.GetNextHost();

            (await nextHost).HostName.ShouldBe(SERVICE_NAME);
        }
        public async Task NoFallBackShouldNotHavMasterServiceHealth()
        {
            SetMockToReturnQueryNotFound(_masterService);
            SetMockToReturnHost(_originatingService);
            var nextHost = await GetServiceDiscovey.GetNextHost();

            HealthChecks.GetStatus().Results.Single(_ => _.Name == _originatingService).Check.IsHealthy.ShouldBeTrue();
            HealthChecks.GetStatus().Results.ShouldNotContain(_ => _.Name == _masterService);
        }
        public async Task QueryDefinendShouldNotFallBackToMaster()
        {
            SetMockToReturnHost(_masterService);
            SetMockToReturnHost(_originatingService);

            var nextHost = GetServiceDiscovey.GetNextHost();

            (await nextHost).HostName.ShouldBe(_originatingService);
        }
        public void MasterShouldNotFallBack()
        {
            _environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>();
            _environmentVariableProvider.DataCenter.Returns("il3");
            _environmentVariableProvider.DeploymentEnvironment.Returns(MASTER_ENVIRONMENT);
            _unitTestingKernel.Rebind <IEnvironmentVariableProvider>().ToConstant(_environmentVariableProvider);

            SetMockToReturnQueryNotFound(_masterService);

            Should.Throw <EnvironmentException>(() => GetServiceDiscovey.GetNextHost());
        }
        public void ShouldNotFallBackToMasterOnConsulError()
        {
            SetMockToReturnHost(MasterService);
            SetMockToReturnError(OriginatingService);
            var exception = Should.Throw <EnvironmentException>(() => GetServiceDiscovey.GetNextHost());

            exception.UnencryptedTags["responseLog"].ShouldBe("Mock: some error");
            exception.UnencryptedTags["queryDefined"].ShouldBe("True");
            exception.UnencryptedTags["consulError"].ShouldNotBeNullOrEmpty();
            exception.UnencryptedTags["requestedService"].ShouldBe(OriginatingService);
        }
        public async Task WhenQueryAddShouldNotFallBackToMaster()
        {
            var reloadInterval = TimeSpan.FromMilliseconds(5);

            _configDic[$"Discovery.Services.{SERVICE_NAME}.ReloadInterval"] = reloadInterval.ToString();

            SetMockToReturnHost(_masterService);
            SetMockToReturnQueryNotFound(_originatingService);
            var nextHost = GetServiceDiscovey.GetNextHost();

            (await nextHost).HostName.ShouldBe(_masterService);
            SetMockToReturnHost(_originatingService);

            await Task.Delay((int)reloadInterval.TotalMilliseconds * 10);

            nextHost = GetServiceDiscovey.GetNextHost();
            nextHost.Result.HostName.ShouldBe(_originatingService);
        }
        public async Task WhenQueryAddShouldNotFallBackToMaster()
        {
            var reloadInterval = TimeSpan.FromMilliseconds(5);

            _configDic[$"Discovery.Services.{_serviceName}.ReloadInterval"] = reloadInterval.ToString();

            SetMockToReturnHost(MasterService);
            SetMockToReturnQueryNotFound(OriginatingService);

            var discovey      = GetServiceDiscovey;
            var waitForEvents = discovey.EndPointsChanged.WhenEventReceived(_timeOut);

            var nextHost = discovey.GetNextHost();

            (await nextHost).HostName.ShouldBe(MasterService);
            SetMockToReturnHost(OriginatingService);

            await waitForEvents;

            nextHost = GetServiceDiscovey.GetNextHost();
            nextHost.Result.HostName.ShouldBe(OriginatingService);
        }
 public void ShouldNotFallBackToMasterOnConsulError()
 {
     SetMockToReturnHost(_masterService);
     SetMockToReturnError(_originatingService);
     Should.Throw <EnvironmentException>(() => GetServiceDiscovey.GetNextHost());
 }