Exemplo n.º 1
0
        public void Get_and_set_and_remove_description_Should_work()
        {
            /* Arrange */
            var nv = new NameValueSettings();
            string expectedDescription = "this is a description";

            /* Act */
            nv.SetDescription(TestSetting.GuidValue, expectedDescription);
            nv.SetDescription(TestSetting.TimeSpanValue, expectedDescription);
            nv.RemoveDescription(TestSetting.TimeSpanValue);
            nv.RemoveDescription((Enum)null);
            nv.RemoveDescription((string)null);

            string desc1 = nv.GetDescription(TestSetting.GuidValue);
            string desc2 = nv.GetDescription(TestSetting.IntegerValue);
            string desc3 = nv.GetDescription(TestSetting.TimeSpanValue);
            /* Assert */
            desc1.Should().Be(expectedDescription);
            desc2.Should().BeEmpty();
            desc3.Should().BeEmpty();
        }
        private static XElement WriteSettings(string sectionXmlName, NameValueSettings sectionSource, ICryptoProvider cryptoProvider, bool encryptAll)
        {
            //Write the settings
            var section = new XElement(sectionXmlName);

            var rawSource = sectionSource.RawSettings;
            foreach (string key in rawSource.AllKeys)
            {
                //Add the description if appropriate
                string description = sectionSource.GetDescription(key);
                if (description.Length > 0)
                {
                    section.Add(new XComment(description));
                }

                //Encrypt if appropriate
                string val = rawSource[key];
                if (cryptoProvider != null && (encryptAll || sectionSource.IsEncrypted(key)))
                {
                    val = cryptoProvider.Encrypt(val);
                }

                section.Add(new XElement(
                    ConfigElement.KeyValueSettingNode,
                    new XAttribute(ConfigElement.SettingKeyAttribute, key),
                    new XAttribute(ConfigElement.SettingValueAttribute, val)));
            }

            return section;
        }