Beispiel #1
0
        public async Task OnlyValueCausesNotification()
        {
            var infraKernel = new TestingKernel <ConsoleLog>(mockConfig: new Dictionary <string, string>
            {
                { "BusSettings.TopicName", "il3-_env_func-infraTest" },
                { "BusSettings.MessageFormatNullable", "Avro" },
            });

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

            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");

            configFromNotification = null;
            configItems.SetValue("BusSettings.MessageFormatNullable", "Invalid");
            eventSource.RaiseChangeEvent();
            await Task.Delay(100);

            // Since the config is invalid, the config object isn't updated and the event wasn't triggered
            configFromNotification.ShouldBeNull();

            configFromNotification = null;
            configItems.SetValue("BusSettings.MessageFormatNullable", "Json");
            eventSource.RaiseChangeEvent();
            await Task.Delay(100);

            // Since the config is valid AND a property changed (Avro --> Json), the config object was updated and an event was triggered
            configFromNotification.ShouldNotBeNull();
        }
Beispiel #2
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();
        }