public void ReturnedObjectsImplementIConfigReloadingProxyInterface()
        {
            IConfigurationRoot configuration = GetConfig();

            IFoo foo = configuration.GetSection("foo").CreateReloadingProxy <IFoo>();

            ConfigReloadingProxy <IFoo> proxyFoo = (ConfigReloadingProxy <IFoo>)foo;

            var initialObject = proxyFoo.Object;

            Assert.IsType <Foo>(initialObject);

            IFoo reloadingFoo = null;
            IFoo reloadedFoo  = null;

            proxyFoo.Reloading += (s, e) => { reloadingFoo = proxyFoo.Object; };
            proxyFoo.Reloaded  += (s, e) => { reloadedFoo = proxyFoo.Object; };

            ChangeConfig(configuration, new KeyValuePair <string, string>("foo:value:qux", "xyz"));

            var changedObject = proxyFoo.Object;

            Assert.NotSame(initialObject, changedObject);
            Assert.Same(initialObject, reloadingFoo);
            Assert.Same(changedObject, reloadedFoo);
        }
Exemple #2
0
        public void TypeSpecifiedByDefaultType()
        {
            var config = GetNonTypeSpecifiedConfig();

            var garplies  = 0;
            var reloading = 0;
            var reloaded  = 0;

            var defaultTypes = new DefaultTypes().Add(typeof(IFoo), typeof(Foo));

            IFoo foo = new ProxyFoo(config.GetSection("foo"), defaultTypes, new ValueConverters(), null, null);

            ConfigReloadingProxy <IFoo> proxyFoo = (ConfigReloadingProxy <IFoo>)foo;
            Foo initialFoo = (Foo)proxyFoo.Object;

            foo.Qux     = "xyz";
            foo.Garply += (s, e) => { garplies++; };

            proxyFoo.Reloading += (s, e) => { reloading++; };
            proxyFoo.Reloaded  += (s, e) => { reloaded++; };

            initialFoo.OnGarply();

            Assert.Equal(123, foo.Bar);
            Assert.Equal("xyz", foo.Qux);
            Assert.Equal(1, garplies);

            Assert.False(initialFoo.IsDisposed);
            Assert.Equal(0, reloading);
            Assert.Equal(0, reloaded);

            ChangeNonTypeSpecifiedConfig(config);

            Assert.True(initialFoo.IsDisposed);
            Assert.Equal(1, reloading);
            Assert.Equal(1, reloaded);

            Foo changedFoo = (Foo)proxyFoo.Object;

            changedFoo.OnGarply();

            Assert.Equal(456, foo.Bar);
            Assert.Equal("xyz", foo.Qux);
            Assert.Equal(2, garplies);

            Assert.False(changedFoo.IsDisposed);

            ((IDisposable)foo).Dispose();

            Assert.True(changedFoo.IsDisposed);
        }
Exemple #3
0
        public void WhenReloadOnChangeIsChangedToFalseObjectIsNotReloaded()
        {
            var config = GetConfig();

            var garplies  = 0;
            var reloading = 0;
            var reloaded  = 0;

            IFoo foo = new ProxyFoo(config.GetSection("foo"), new DefaultTypes(), new ValueConverters(), null, null);

            ConfigReloadingProxy <IFoo> proxyFoo = (ConfigReloadingProxy <IFoo>)foo;
            Foo initialFoo = (Foo)proxyFoo.Object;

            foo.Qux     = "xyz";
            foo.Garply += (s, e) => { garplies++; };

            proxyFoo.Reloading += (s, e) => { reloading++; };
            proxyFoo.Reloaded  += (s, e) => { reloaded++; };

            initialFoo.OnGarply();

            Assert.Equal(123, foo.Bar);
            Assert.Equal("xyz", foo.Qux);
            Assert.Equal(1, garplies);

            Assert.False(initialFoo.IsDisposed);
            Assert.Equal(0, reloading);
            Assert.Equal(0, reloaded);

            ChangeConfig(config, new KeyValuePair <string, string>("foo:reloadOnChange", "false"));

            Assert.False(initialFoo.IsDisposed);
            Assert.Equal(0, reloading);
            Assert.Equal(0, reloaded);

            Foo changedFoo = (Foo)proxyFoo.Object;

            Assert.Same(initialFoo, changedFoo);
        }