示例#1
0
        public void TestSimpleDependencyChangeParent()
        {
            var container = new Types.DependentPropertyContainer {
                Title = "Title", Instance = new Types.SimpleObject {
                    Name = "Test"
                }
            };
            var testContext     = new TestContext();
            var instanceContext = testContext.CreateInstanceContext(container);

            testContext.ObservableViewModelService.RegisterPropertyNodeUpdater(new SimpleDependentPropertiesUpdater());
            var viewModel    = instanceContext.CreateViewModel();
            var titleNode    = viewModel.RootNode.GetChild(Title);
            var instanceNode = viewModel.RootNode.GetChild(Instance);

            Assert.AreEqual(true, titleNode.AssociatedData.ContainsKey(TestDataKey));
            Assert.AreEqual("Test", titleNode.AssociatedData[TestDataKey]);
            Assert.AreEqual(0, titleNode.AssociatedData[UpdateCountKey]);

            instanceNode.Value = new Types.SimpleObject {
                Name = "NewValue"
            };
            Assert.AreEqual(true, titleNode.AssociatedData.ContainsKey(TestDataKey));
            Assert.AreEqual("NewValue", titleNode.AssociatedData[TestDataKey]);
            Assert.AreEqual(1, titleNode.AssociatedData[UpdateCountKey]);

            instanceNode.Value = new Types.SimpleObject {
                Name = "NewValue2"
            };
            Assert.AreEqual(true, titleNode.AssociatedData.ContainsKey(TestDataKey));
            Assert.AreEqual("NewValue2", titleNode.AssociatedData[TestDataKey]);
            Assert.AreEqual(2, titleNode.AssociatedData[UpdateCountKey]);
        }
        public void TestSimpleDependency()
        {
            var container = new Types.DependentPropertyContainer { Title = "Title", Instance = new Types.SimpleObject { Name = "Test" } };
            var testContext = new TestContext();
            var instanceContext = testContext.CreateInstanceContext(container);
            testContext.ObservableViewModelService.RegisterPropertyNodeUpdater(new SimpleDependentPropertiesUpdater());
            var viewModel = instanceContext.CreateViewModel();
            var titleNode = viewModel.RootNode.GetChild(Title);
            var nameNode = viewModel.RootNode.GetChild(Instance).GetChild(Name);

            Assert.AreEqual(true, titleNode.AssociatedData.ContainsKey(TestDataKey));
            Assert.AreEqual("Test", titleNode.AssociatedData[TestDataKey]);
            Assert.AreEqual(0, titleNode.AssociatedData[UpdateCountKey]);

            nameNode.Value = "NewValue";
            Assert.AreEqual(true, titleNode.AssociatedData.ContainsKey(TestDataKey));
            Assert.AreEqual("NewValue", titleNode.AssociatedData[TestDataKey]);
            Assert.AreEqual(1, titleNode.AssociatedData[UpdateCountKey]);

            nameNode.Value = "NewValue2";
            Assert.AreEqual(true, titleNode.AssociatedData.ContainsKey(TestDataKey));
            Assert.AreEqual("NewValue2", titleNode.AssociatedData[TestDataKey]);
            Assert.AreEqual(2, titleNode.AssociatedData[UpdateCountKey]);
        }
 public TestInstanceContext(TestContext context, IGraphNode rootNode)
 {
     this.context = context;
     RootNode = rootNode;
     PropertiesProvider = new Types.TestPropertiesProvider(rootNode);
 }