Ejemplo n.º 1
0
            public void DoesNotSuspendNotifications()
            {
                var pluginChangeNotifications = 0;
                var presetChangeNotifications = 0;

                var pluginContainer = new PluginContainer
                {
                    Name = "test"
                };

                for (int i = 0; i < 100; i++)
                {
                    var plugin = new Plugin
                    {
                    };

                    plugin.PropertyChanged += (sender, e) =>
                    {
                        pluginChangeNotifications++;
                    };

                    for (int j = 0; j < 500; j++)
                    {
                        var preset = new Preset
                        {
                            Foo = (j + 1).ToString()
                        };

                        preset.PropertyChanged += (sender, e) =>
                        {
                            presetChangeNotifications++;
                        };

                        plugin.Presets.Add(preset);
                    }

                    pluginContainer.Plugins.Add(plugin);
                }

                // Set up the test data (change all values)
                foreach (var plugin in pluginContainer.Plugins)
                {
                    plugin.Name = "dummy";
                    Assert.IsTrue(plugin.IsDirty);

                    foreach (var preset in plugin.Presets)
                    {
                        preset.Foo = "test";
                        Assert.IsTrue(preset.IsDirty);
                    }
                }

                pluginChangeNotifications = 0;
                presetChangeNotifications = 0;

                Assert.IsTrue(pluginContainer.IsDirty);

                pluginContainer.ClearIsDirtyOnAllChildren();

                Assert.AreEqual(100, pluginChangeNotifications);
                Assert.AreEqual(50000, presetChangeNotifications);

                // Test https://github.com/Catel/Catel/issues/1262
                Assert.IsFalse(pluginContainer.IsDirty);

                foreach (var plugin in pluginContainer.Plugins)
                {
                    Assert.IsFalse(plugin.IsDirty);
                }
            }