public virtual void TearDown()
 {
     if (!_kernelCreatedAsSingleTone)
     {
         _unitTestingKernel.Dispose();
     }
 }
        public void SetUp()
        {
            _unitTestingKernel?.Dispose();
            _serviceName = $"ServiceName{++id}";

            _environmentVariableProvider = Substitute.For <IEnvironmentVariableProvider>();
            _environmentVariableProvider.DataCenter.Returns("il3");
            _environmentVariableProvider.DeploymentEnvironment.Returns(ORIGINATING_ENVIRONMENT);

            _configDic = new Dictionary <string, string> {
                { "Discovery.EnvironmentFallbackEnabled", "true" }
            };
            _unitTestingKernel = new TestingKernel <ConsoleLog>(k =>
            {
                k.Rebind <IEnvironmentVariableProvider>().ToConstant(_environmentVariableProvider);

                k.Rebind <IDiscoverySourceLoader>().To <DiscoverySourceLoader>().InSingletonScope();
                SetupConsulClientMocks();
                k.Rebind <Func <string, IConsulClient> >().ToMethod(_ => (s => _consulClients[s]));

                _dateTimeMock = Substitute.For <IDateTime>();
                _dateTimeMock.Delay(Arg.Any <TimeSpan>()).Returns(c => Task.Delay(TimeSpan.FromMilliseconds(100)));
                k.Rebind <IDateTime>().ToConstant(_dateTimeMock);
            }, _configDic);
            _configRefresh = _unitTestingKernel.Get <ManualConfigurationEvents>();

            var environmentVariableProvider = _unitTestingKernel.Get <IEnvironmentVariableProvider>();

            Assert.AreEqual(_environmentVariableProvider, environmentVariableProvider);
        }
Example #3
0
        public void AllPropertiesExceptNullableShouldBeSet()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "il3-_env_func-infraTest" },
                { "BusSettings.RequestTimeoutInMs", "30000" },
                { "BusSettings.MessageFormat", "Json" },
                { "BusSettings.DateTime", "2016-11-08 15:57:20" },
                { "BusSettings.Date", "2016/11/08" },
                { "BusSettings.TimeSpan", "00:00:01" },
                { "BusSettings.Regex", "/ab+c/" },
                { "BusSettings.Uri", "http://data.com" },
            });
            var extractor = infraKernel.Get <Func <BusSettings> >();

            var busSettings = extractor();

            busSettings.TopicName.ShouldBe("il3-_env_func-infraTest");
            busSettings.MessageFormatNullable.ShouldBeNull();
            busSettings.MessageFormat.ShouldBe(MessageFormat.Json);
            busSettings.RequestTimeoutInMs.ShouldBe(30000);
            busSettings.RequestTimeoutInMsNullable.ShouldBeNull();
            busSettings.Date.ShouldBe(dateTime.Date);
            busSettings.DateTime.ShouldBe(dateTime);
            busSettings.TimeSpan.ShouldBe(TimeSpan.FromSeconds(1));
            busSettings.Regex.ShouldNotBeNull();
            busSettings.Uri.ShouldBe(new Uri("http://data.com"));
            infraKernel.Dispose();
        }
Example #4
0
        public async Task ChangeToBrokenConfiguration()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "OldValue" },
                { "BusSettings.RequestTimeoutInMs", "30000" },
            });

            var extractor   = infraKernel.Get <Func <BusSettings> >();
            var configItems = infraKernel.Get <OverridableConfigItems>();
            var eventSource = infraKernel.Get <ManualConfigurationEvents>();

            //Make sure a good configuration have been parsed.
            var busSettings = extractor();

            busSettings.RequestTimeoutInMs.ShouldBe(30000);

            configItems.SetValue("BusSettings.RequestTimeoutInMs", "NotNumber");

            eventSource.RaiseChangeEvent();
            await Task.Delay(100);

            //Make sure last good configuration is returned.
            busSettings = extractor();
            busSettings.RequestTimeoutInMs.ShouldBe(30000);

            const string healthComponentName = "BusSettings Configuration";
            var          healthMonitor       = (FakeHealthMonitor)infraKernel.Get <IHealthMonitor>();

            healthMonitor.Monitors.ShouldContainKey(healthComponentName);
            healthMonitor.Monitors[healthComponentName]().IsHealthy.ShouldBe(false);

            infraKernel.Dispose();
        }
Example #5
0
        public async Task ConfigObjectValuesChangedAfterUpdate()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "OldValue" },
            });

            var manualConfigurationEvents = infraKernel.Get <ManualConfigurationEvents>();
            var configItems   = infraKernel.Get <OverridableConfigItems>();
            var configFactory = infraKernel.Get <IConfiguration>();

            var busSettings = configFactory.GetObject <BusSettings>();

            busSettings.TopicName.ShouldBe("OldValue");

            configItems.SetValue("BusSettings.TopicName", "NewValue");
            busSettings = await manualConfigurationEvents.ApplyChanges <BusSettings>();

            busSettings.TopicName.ShouldBe("NewValue");

            busSettings = configFactory.GetObject <BusSettings>();
            busSettings.TopicName.ShouldBe("NewValue");

            infraKernel.Dispose();
        }
Example #6
0
        public async Task ObjectValuesChangedAfterUpdate()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "OldValue" },
                { "BusSettings.MessageFormatNullable", "Json" },
                { "BusSettings.RequestTimeoutInMs", "30000" },
                { "BusSettings.RequestTimeoutInMsNullable", "30000" },
                { "BusSettings.MessageFormat", "Json" },
                { "BusSettings.Date", "2016/11/08" },
                { "BusSettings.DateTime", "2016-11-08 15:57:20" },
            });

            var extractor   = infraKernel.Get <Func <BusSettings> >();
            var configItems = infraKernel.Get <OverridableConfigItems>();
            var eventSource = infraKernel.Get <ManualConfigurationEvents>();

            var busSettings = extractor();

            busSettings.TopicName.ShouldBe("OldValue");

            configItems.SetValue("BusSettings.TopicName", "NewValue");

            eventSource.RaiseChangeEvent();
            await Task.Delay(100);

            busSettings = extractor();
            busSettings.TopicName.ShouldBe("NewValue");

            infraKernel.Dispose();
        }
        private async Task <HttpRequestMessage> GetRequestFor <T>(Func <T, Task> action)
        {
            HttpRequestMessage request        = null;
            string             requestContent = null;
            var mockHandler = new MockHttpMessageHandler();

            mockHandler.When("*").Respond(async r =>
            {
                request        = r;
                requestContent = await r.Content.ReadAsStringAsync();
                return(HttpResponseFactory.GetResponse(content: "''"));
            });
            var kernel = new TestingKernel <ConsoleLog>();
            var client = kernel
                         .Get <ServiceProxyProviderSpy <T> >(new ConstructorArgument("httpMessageHandler", mockHandler))
                         .Client;

            await action(client);

            var contentClone = new StringContent(requestContent, Encoding.UTF8, "application/json");

            foreach (KeyValuePair <string, IEnumerable <string> > header in request.Content.Headers.Where(h => h.Key.StartsWith("X")))
            {
                contentClone.Headers.Add(header.Key, header.Value);
            }

            kernel.Dispose();

            return(new HttpRequestMessage(request.Method, request.RequestUri)
            {
                Content = contentClone
            });
        }
Example #8
0
        public async Task RunInConfigurationVerification_ShouldWriteResults()
        {
            NonOrleansServiceTester <CalculatorServiceHost> serviceTester = null;
            var testingKernel = new TestingKernel <ConsoleLog>();

            try
            {
                var buffer = new StringBuilder();
                var prOut  = Console.Out;
                Console.SetOut(new StringWriter(buffer));

                serviceTester = testingKernel.GetServiceTesterForNonOrleansService <CalculatorServiceHost>(
                    1112,
                    TimeSpan.FromSeconds(10),
                    ServiceStartupMode.VerifyConfigurations);

                var canaryType = typeof(MetricsConfiguration);

                Console.SetOut(prOut);

                Regex.IsMatch(buffer.ToString(), $"(OK|ERROR).*{canaryType.FullName}")
                .ShouldBeTrue("Output should contain a row with validation of the type");

                Console.WriteLine(buffer);
            }
            finally
            {
                Should.Throw <InvalidOperationException>(() => serviceTester?.Dispose())
                .Message.ShouldContain("Service is already stopped");
                testingKernel.Dispose();
            }
        }
Example #9
0
 public void TearDown()
 {
     _unitTestingKernel.Dispose();
     foreach (var consulClient in _consulClient)
     {
         consulClient.Value.Dispose();
     }
 }
 public void Teardown()
 {
     _unitTestingKernel?.Dispose();
     _configDic?.Clear();
     _configDic     = null;
     _configRefresh = null;
     _consulClient?.Clear();
     _consulClient = null;
 }
Example #11
0
        public void ShouldThrowOnValidateError()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>  {
                { "BusSettings.ConsumerSettings.ConsumerId", "consID" },
            });

            var extractor = infraKernel.Get <Func <BusSettings> >();

            Should.Throw <ConfigurationException>(() => extractor());

            infraKernel.Dispose();
        }
Example #12
0
        public void DeepNestedShouldThrowOnValidateError()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>  {
                { "FirstLevel.NextLevel.NextLevel.Name", "Name" },
            });

            var extractor = infraKernel.Get <Func <FirstLevel> >();

            Should.Throw <ConfigurationException>(() => extractor());

            infraKernel.Dispose();
        }
Example #13
0
        public void ShouldThrowOnMissingInt()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "il3-_env_func-infraTest" },
                { "BusSettings.MessageFormat", "Json" }
            });
            var extractor = infraKernel.Get <Func <BusSettings> >();

            Should.Throw <ConfigurationException>(() => extractor());

            infraKernel.Dispose();
        }
Example #14
0
        public void DeepNestedShouldWork()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>  {
                { "FirstLevel.NextLevel.NextLevel.ID", "ID" },
            });

            var extractor = infraKernel.Get <Func <FirstLevel> >();
            var deep      = extractor();

            deep?.NextLevel?.NextLevel?.ID?.ShouldBe("ID");

            infraKernel.Dispose();
        }
Example #15
0
        public void CanReadWithReplacingPrefix()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "Prefix1.Prefix2.GatorConfig.Name", "infraTest" },
            });
            var extractor = infraKernel.Get <Func <Gator> >();

            var busSettings = extractor();

            busSettings.ShouldNotBeNull();
            busSettings.Name.ShouldBe("infraTest");

            infraKernel.Dispose();
        }
Example #16
0
        public async Task ShouldCallSelfHostServcie()
        {
            NonOrleansServiceTester <CalculatorServiceHost> serviceTester = null;
            var testingKernel = new TestingKernel <TraceLog>();

            try
            {
                serviceTester = testingKernel.GetServiceTesterForNonOrleansService <CalculatorServiceHost>(1111, TimeSpan.FromSeconds(10));
                (await serviceTester.GetServiceProxy <ICalculatorService>().Add(1, 2)).ShouldBe(3);
            }
            finally
            {
                serviceTester?.Dispose();
                testingKernel.Dispose();
            }
        }
        private async Task <HttpRequestMessage> GetRequestFor <T>(Func <T, Task> action)
        {
            HttpRequestMessage request        = null;
            string             requestContent = null;
            Func <HttpClientConfiguration, HttpMessageHandler> messageHandlerFactory = _ =>
            {
                var mockHandler = new MockHttpMessageHandler();
                mockHandler.When("*").Respond(async r =>
                {
                    if (r.Method != HttpMethod.Get)
                    {
                        request        = r;
                        requestContent = await r.Content.ReadAsStringAsync();
                    }

                    return(HttpResponseFactory.GetResponse(content: "''"));
                });

                return(mockHandler);
            };
            var kernel = new TestingKernel <ConsoleLog>();

            kernel.Rebind <Func <HttpClientConfiguration, HttpMessageHandler> >().ToMethod(c => messageHandlerFactory);
            var client = kernel.Get <ServiceProxyProviderSpy <T> >();

            client.DefaultPort = _testinghost.BasePort;

            await action(client.Client);

            var contentClone = new StringContent(requestContent, Encoding.UTF8, "application/json");

            foreach (KeyValuePair <string, IEnumerable <string> > header in request.Content.Headers.Where(h =>
                                                                                                          h.Key.StartsWith("X")))
            {
                contentClone.Headers.Add(header.Key, header.Value);
            }

            kernel.Dispose();

            return(new HttpRequestMessage(request.Method, request.RequestUri)
            {
                Content = contentClone
            });
        }
Example #18
0
        public void Test_GetConfigObject()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "il3-_env_func-infraTest" },
                { "BusSettings.MessageFormatNullable", "Json" },
                { "BusSettings.RequestTimeoutInMs", "30000" },
                { "BusSettings.RequestTimeoutInMsNullable", "30000" },
                { "BusSettings.MessageFormat", "Json" },
                { "BusSettings.Date", "2016/11/08" },
                { "BusSettings.DateTime", "2016-11-08 15:57:20" },
            });

            var kafkaSettings = infraKernel.Get <SomeGrain>();

            kafkaSettings.DoWork();

            infraKernel.Dispose();
        }
Example #19
0
        public async Task NotificationChange()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "il3-_env_func-infraTest" },
                { "BusSettings.MessageFormatNullable", "Json" },
                { "BusSettings.RequestTimeoutInMs", "30000" },
                { "BusSettings.RequestTimeoutInMsNullable", "30000" },
                { "BusSettings.MessageFormat", "Json" },
                { "BusSettings.Date", "2016/11/08" },
                { "BusSettings.DateTime", "2016-11-08 15:57:20" },
            });

            var         notifications          = infraKernel.Get <ISourceBlock <BusSettings> >();
            BusSettings configFromNotification = null;

            notifications.LinkTo(new ActionBlock <BusSettings>(set =>
            {
                configFromNotification = set;
            }));

            var extractor   = infraKernel.Get <Func <BusSettings> >();
            var busSettings = extractor();

            busSettings.TopicName.ShouldBe("il3-_env_func-infraTest");

            var configItems = infraKernel.Get <OverridableConfigItems>();
            var eventSource = infraKernel.Get <ManualConfigurationEvents>();

            configItems.SetValue("BusSettings.TopicName", "Changed");
            eventSource.RaiseChangeEvent();
            await Task.Delay(100);

            configFromNotification.ShouldNotBeNull();
            configFromNotification.TopicName.ShouldBe("Changed");
            infraKernel.Dispose();
        }
Example #20
0
        public void AllPropertiesShouldBeSet()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>  {
                { "BusSettings.TopicName", "il3-_env_func-infraTest" },
                { "BusSettings.MessageFormatNullable", "Json" },
                { "BusSettings.RequestTimeoutInMs", "30000" },
                { "BusSettings.RequestTimeoutInMsNullable", "30000" },
                { "BusSettings.MessageFormat", "Json" },
                { "BusSettings.DateTime", "2016-11-08 15:57:20" },
                { "BusSettings.Date", "2016/11/08" },
                { "BusSettings.DateTimeNullable", "2016-11-08 15:57:20" },
                { "BusSettings.ConsumerSettings.ConsumerId", "consID" },
                { "BusSettings.ConsumerSettings.ConsumerName", "consName" },
                { "BusSettings.ConsumerSettings.Country.CountryCode", "US" },
            });

            var extractor = infraKernel.Get <Func <BusSettings> >();

            var busSettings = extractor();

            busSettings.TopicName.ShouldBe("il3-_env_func-infraTest");
            busSettings.MessageFormatNullable.ShouldBe(MessageFormat.Json);
            busSettings.MessageFormat.ShouldBe(MessageFormat.Json);
            busSettings.RequestTimeoutInMs.ShouldBe(30000);
            busSettings.RequestTimeoutInMsNullable.ShouldBe(30000);
            busSettings.Date.ShouldBe(dateTime.Date);
            busSettings.DateTime.ShouldBe(dateTime);
            busSettings.DateTimeNullable.ShouldBe(dateTime);
            busSettings.ConsumerSettings.ShouldNotBeNull();
            busSettings.ConsumerSettings.ConsumerId.ShouldBe("consID");

            busSettings.ConsumerSettings.Country.ShouldNotBeNull();
            busSettings.ConsumerSettings.Country.CountryCode.ShouldBe("US");

            infraKernel.Dispose();
        }
Example #21
0
 public void DisposeKernel()
 {
     _kernel.Dispose();
 }
Example #22
0
 public void TearDown()
 {
     kernel.Dispose();
 }
 public void TearDown()
 {
     _unitTestingKernel.Dispose();
 }
 public void TearDown()
 {
     _consulDiscoverySource?.ShutDown();
     _unitTestingKernel.Dispose();
 }
Example #25
0
 public async Task Teardown()
 {
     _nodeSource?.Dispose();
     _testingKernel?.Dispose();
     _consulNodeSourceFactory?.Dispose();
 }
Example #26
0
 public void OneTimeTearDown()
 {
     _consulSimulator.Dispose();
     _testingKernel.Dispose();
 }
Example #27
0
 public void OneTimeTearDown()
 {
     _kernel.Dispose();
 }
Example #28
0
 public void TearDown()
 {
     _unitTestingKernel.Dispose();
     _consulClientMock.Dispose();
 }
Example #29
0
 public void TearDownConsulListener()
 {
     _testingKernel.Dispose();
     _consulSimulator.Dispose();
 }
Example #30
0
 public void TearDown()
 {
     _unitTestingKernel.Dispose();
     _consulResultsTimer.Dispose();
 }