Esempio n. 1
0
        protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
        {
            var dependencies = new CachedModelDependencyContainer <Room>(base.CreateChildDependencies(parent));

            dependencies.Model.BindTo(selectedRoom);
            return(dependencies);
        }
Esempio n. 2
0
        public void TestSetModelToNullAfterResolved()
        {
            var resolver = new FieldModelResolver();

            var model = new FieldModel {
                Bindable = { Value = 2 }
            };

            var dependencies = new CachedModelDependencyContainer <FieldModel>(null)
            {
                Model = { Value = model }
            };

            dependencies.Inject(resolver);

            Assert.AreEqual(2, resolver.Model.Bindable.Value);

            dependencies.Model.Value = null;

            // Should be reset to the default value
            Assert.AreEqual(1, resolver.Model.Bindable.Value);

            model.Bindable.Value = 3;

            Assert.AreEqual(1, resolver.Model.Bindable.Value);
        }
Esempio n. 3
0
        public void TestSubClassedModelCachedAllSuperClasses()
        {
            var resolver     = new DerivedFieldModelResolver();
            var dependencies = new CachedModelDependencyContainer <DerivedFieldModel>(null)
            {
                Model =
                {
                    Value              = new DerivedFieldModel
                    {
                        Bindable       = { Value =   2 },
                        BindableString = { Value = "2" }
                    }
                }
            };

            dependencies.Inject(resolver);

            Assert.AreEqual(2, resolver.Model.Bindable.Value);
            Assert.AreEqual("2", resolver.Model.BindableString.Value);

            dependencies.Model.Value.Bindable.Value       = 3;
            dependencies.Model.Value.BindableString.Value = "3";

            Assert.AreEqual(3, resolver.Model.Bindable.Value);
            Assert.AreEqual("3", resolver.Model.BindableString.Value);
        }
Esempio n. 4
0
        public void TestModelWithNonReadOnlyFieldsFails()
        {
            IReadOnlyDependencyContainer unused;

            Assert.Throws <TypeInitializationException>(() => unused = new CachedModelDependencyContainer <NonReadOnlyFieldModel>(null));
            Assert.Throws <TypeInitializationException>(() => unused = new CachedModelDependencyContainer <PropertyModel>(null));
        }
Esempio n. 5
0
        public void TestChangeModelPropagatesAllChanges()
        {
            var resolver = new FieldModelResolver();

            var model1 = new FieldModel {
                Bindable = { Value = 2 }
            };
            var model2 = new FieldModel {
                Bindable = { Value = 3 }
            };

            var dependencies = new CachedModelDependencyContainer <FieldModel>(null)
            {
                Model = { Value = model1 }
            };

            dependencies.Inject(resolver);

            Assert.AreEqual(2, resolver.Model.Bindable.Value);

            dependencies.Model.Value = model2;

            Assert.AreEqual(3, resolver.Model.Bindable.Value);

            model1.Bindable.Value = 4;

            Assert.AreEqual(3, resolver.Model.Bindable.Value);

            model2.Bindable.Value = 4;

            Assert.AreEqual(4, resolver.Model.Bindable.Value);
        }
Esempio n. 6
0
        public void TestCrossDependentBindsDoNotPollute()
        {
            var model1 = new CrossDependentFieldModel {
                Bindable = { Value = 2 }
            };
            var model2 = new CrossDependentFieldModel {
                Bindable = { Value = 3 }
            };

            var dependencies = new CachedModelDependencyContainer <CrossDependentFieldModel>(null)
            {
                Model = { Value = model1 }
            };

            Assert.AreEqual(2, model1.Bindable.Value);
            Assert.AreEqual(2, model1.BindableTwo.Value);

            Assert.AreEqual(3, model2.Bindable.Value);
            Assert.AreEqual(3, model2.BindableTwo.Value);

            dependencies.Model.Value = model2;

            Assert.AreEqual(2, model1.Bindable.Value);
            Assert.AreEqual(2, model1.BindableTwo.Value);

            Assert.AreEqual(3, model2.Bindable.Value);
            Assert.AreEqual(3, model2.BindableTwo.Value);
        }
Esempio n. 7
0
        public void TestSettingNoModelResolvesDefault()
        {
            var resolver     = new FieldModelResolver();
            var dependencies = new CachedModelDependencyContainer <FieldModel>(null);

            dependencies.Inject(resolver);

            Assert.AreEqual(1, resolver.Model.Bindable.Value);
        }
Esempio n. 8
0
        public void TestModelWithBindablePropertiesPropagatesToChildren()
        {
            var resolver     = new FieldModelResolver();
            var dependencies = new CachedModelDependencyContainer <FieldModel>(null)
            {
                Model = { Value        = new FieldModel {
                              Bindable =                { Value= 2 }
                          } }
            };

            dependencies.Inject(resolver);

            Assert.AreEqual(2, resolver.Model.Bindable.Value);
        }
Esempio n. 9
0
        public void TestInjectionResolvesDifferingShadowModels()
        {
            var resolver1 = new FieldModelResolver();
            var resolver2 = new FieldModelResolver();

            var dependencies = new CachedModelDependencyContainer <FieldModel>(null)
            {
                Model = { Value = new FieldModel() }
            };

            dependencies.Inject(resolver1);
            dependencies.Inject(resolver2);

            Assert.AreNotSame(resolver1.Model, resolver2.Model);
        }
        public void TestChangeModelValuePropagatesToChildren()
        {
            var resolver     = new PropertyModelResolver();
            var dependencies = new CachedModelDependencyContainer <PropertyModel>(null)
            {
                Model = { Value        = new PropertyModel {
                              Bindable =                   { Value= 2 }
                          } }
            };

            dependencies.Inject(resolver);

            Assert.AreEqual(2, resolver.Model.Bindable.Value);

            dependencies.Model.Value.Bindable.Value = 3;

            Assert.AreEqual(3, resolver.Model.Bindable.Value);
        }
Esempio n. 11
0
        public void TestResolveIndividualProperties()
        {
            var resolver = new DerivedFieldModelPropertyResolver();

            var model1 = new DerivedFieldModel
            {
                Bindable       = { Value = 2 },
                BindableString = { Value = "2" }
            };

            var model2 = new DerivedFieldModel
            {
                Bindable       = { Value = 3 },
                BindableString = { Value = "3" }
            };

            var dependencies = new CachedModelDependencyContainer <DerivedFieldModel>(null)
            {
                Model = { Value = model1 }
            };

            dependencies.Inject(resolver);

            Assert.AreEqual(2, resolver.Bindable.Value);
            Assert.AreEqual("2", resolver.BindableString.Value);

            dependencies.Model.Value = model2;

            Assert.AreEqual(3, resolver.Bindable.Value);
            Assert.AreEqual("3", resolver.BindableString.Value);

            dependencies.Model.Value = null;

            Assert.AreEqual(1, resolver.Bindable.Value);
            Assert.AreEqual(null, resolver.BindableString.Value);
        }
Esempio n. 12
0
 protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
 {
     dependencies             = new CachedModelDependencyContainer <Room>(base.CreateChildDependencies(parent));
     dependencies.Model.Value = Room;
     return(dependencies);
 }