Create_Should_Return_Previous_Object_If_Configuration_Had_Been_Changed_And_Is_Invalid_To_Create_New_One()
        {
            var tesTConfigClassProvider = new TesTConfigClassProvider();

            tesTConfigClassProvider.Set(ExtensionMethods.CreateKeyName <SampleConfiguration>(x => x.IntValue), "10");
            var configuration = new ConfigurationRoot(new List <IConfigurationProvider> {
                tesTConfigClassProvider
            });
            var factory = new TrackingConfigurationChangesFactory <SampleConfiguration>(
                configuration.GetSection(nameof(SampleConfiguration)),
                BindPolicy.Default);
            var lastValidConfig = factory.Create();

            tesTConfigClassProvider.Clear();
            // act && assert
            var actualConfig = factory.Create();

            Assert.Same(lastValidConfig, actualConfig);
        }
Ejemplo n.º 2
0
        When_Configuration_Has_Been_Changed_And_Now_Causes_Instatnion_Errors_The_Last_Object_Is_Returned_For_A_New_Scope()
        {
            // arrange
            var configurationProvider = new TesTConfigClassProvider().SetSection(100, "any");
            var configuration         = new ConfigurationRoot(new List <IConfigurationProvider> {
                configurationProvider
            });

            _serviceCollection.AddBoundToConfig <SampleConfiguration>(configuration, nameof(SampleConfiguration));
            var provider   = _serviceCollection.BuildServiceProvider(true);
            var myOptions1 = provider.CreateScope().ServiceProvider.GetRequiredService <SampleConfiguration>();

            // act
            configurationProvider.Clear();
            configurationProvider.Reload();
            var myOptions2 = provider.CreateScope().ServiceProvider.GetRequiredService <SampleConfiguration>();

            // assert
            Assert.Same(myOptions1, myOptions2);
        }
Ejemplo n.º 3
0
        public void When_Configuration_Has_Been_Changed_And_Causes_Instatnion_Errors_Registered_Handler_Is_Called()
        {
            // arrange
            var configurationProvider = new TesTConfigClassProvider().SetSection(100, "any");
            var configuration         = new ConfigurationRoot(new List <IConfigurationProvider> {
                configurationProvider
            });
            var resetEvent = new ManualResetEventSlim(false);

            _serviceCollection.AddBoundToConfig <SampleConfiguration>(
                configuration,
                nameof(SampleConfiguration),
                (ex, type) => { resetEvent.Set(); });
            var provider = _serviceCollection.BuildServiceProvider(true);

            // act
            configurationProvider.Clear();
            configurationProvider.Reload();
            provider.CreateScope().ServiceProvider.GetRequiredService <SampleConfiguration>();
            // assert
            resetEvent.Wait(TimeSpan.FromMilliseconds(1000)).Should().BeTrue("Error handler should be called.");
        }