public void NotifiesIfSavedChanges()
        {
            MockNamedConfigurationSettingB setting = CreateMockNamedConfigurationSettingB("Baz", "Foo", "Bar");

            setting.Changed      += this.Changed;
            setting.SourceElement = new TestConfigurationSection();             // just so Commit works

            setting.Publish();

            using (System.Management.ManagementObjectCollection.ManagementObjectEnumerator resultEnumerator
                       = new ManagementObjectSearcher("root\\enterpriselibrary", "SELECT * FROM MockNamedConfigurationSettingB")
                         .Get().GetEnumerator())
            {
                Assert.IsTrue(resultEnumerator.MoveNext());

                ManagementObject managementObject = resultEnumerator.Current as ManagementObject;

                setting.performSave = false;
                Assert.IsNull(this.changedObject);
                managementObject.Put();
                Assert.IsNull(this.changedObject);                              // no change notified

                setting.performSave = true;
                Assert.IsNull(this.changedObject);
                managementObject.Put();
                Assert.IsNotNull(this.changedObject);                   // change notified
            }
        }
        public void CanPublishInstancesOfSiblingClassesWithTheSameKey()
        {
            MockNamedConfigurationSetting  setting  = CreateMockNamedConfigurationSetting("Baz", "Foo", "Bar");
            MockNamedConfigurationSettingB setting2 = CreateMockNamedConfigurationSettingB("Baz", "Foo", "Bar");

            setting.Publish();
            setting2.Publish();

            using (System.Management.ManagementObjectCollection.ManagementObjectEnumerator resultEnumerator
                       = new ManagementObjectSearcher("root\\enterpriselibrary", "SELECT * FROM MockNamedConfigurationSetting")
                         .Get().GetEnumerator())
            {
                Assert.IsTrue(resultEnumerator.MoveNext());
                Assert.AreEqual("Baz", resultEnumerator.Current.Properties["Name"].Value);
                Assert.AreEqual("MockNamedConfigurationSetting", resultEnumerator.Current.SystemProperties["__CLASS"].Value);
                Assert.IsFalse(resultEnumerator.MoveNext());
            }

            using (System.Management.ManagementObjectCollection.ManagementObjectEnumerator resultEnumerator
                       = new ManagementObjectSearcher("root\\enterpriselibrary", "SELECT * FROM MockNamedConfigurationSettingB")
                         .Get().GetEnumerator())
            {
                Assert.IsTrue(resultEnumerator.MoveNext());
                Assert.AreEqual("Baz", resultEnumerator.Current.Properties["Name"].Value);
                Assert.AreEqual("MockNamedConfigurationSettingB", resultEnumerator.Current.SystemProperties["__CLASS"].Value);
                Assert.IsFalse(resultEnumerator.MoveNext());
            }
        }
        private static MockNamedConfigurationSettingB CreateMockNamedConfigurationSettingB(string name, string applicationName, string sectionName)
        {
            MockNamedConfigurationSettingB setting = new MockNamedConfigurationSettingB(name);

            setting.ApplicationName = applicationName;
            setting.SectionName     = sectionName;
            return(setting);
        }