public void CreateKeyDataProgramaticlyTest()
        {
            string strTest = "Test String";
            string strKeyTest = "Mykey";

            List<string> commentListTest = new List<string> ( new string [] {"testComment 1", "testComment 2" } );

            //Create a key data
            KeyData kd = new KeyData(strKeyTest);

            //Assert not null and empty
            Assert.That(kd, Is.Not.Null );
            Assert.That(kd.Comments, Is.Empty );
            Assert.That(kd.Value, Is.Empty );

            //Set key name
            Assert.That(kd.KeyName == strKeyTest);
            kd.KeyName = "";
            Assert.That(kd.KeyName == strKeyTest);
            kd.KeyName = strKeyTest+"_new";
            Assert.That(kd.KeyName == strKeyTest+"_new");

            //Set value data
            kd.Value = strTest;
            Assert.That(kd.Value, Is.EqualTo(strTest) );

            //Add comments
            kd.Comments.Add(strTest);
            Assert.That(kd.Comments.Count, Is.EqualTo(1));
            Assert.That(kd.Comments[0], Is.EqualTo(strTest));

            //Assign comments
            kd.Comments = commentListTest;
            Assert.That(kd.Comments, Is.Not.Null);
            Assert.That(kd.Comments, Is.Not.Empty);
            Assert.That(kd.Comments.Count, Is.EqualTo(commentListTest.Count) );
            Assert.That(kd.Comments[0], Is.EqualTo(commentListTest[0]));
            Assert.That(kd.Comments[1], Is.EqualTo(commentListTest[1]));
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyData"/> class
        /// from a previous instance of <see cref="KeyData"/>.
        /// </summary>
        /// <remarks>
        /// Data is deeply copied
        /// </remarks>
        /// <param name="ori">
        /// The instance of the <see cref="KeyData"/> class
        /// used to create the new instance.</param>
        public KeyData(KeyData ori)
        {
            _value = ori._value;

            _comments = new List <string>(_comments);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyData"/> class
        /// from a previous instance of <see cref="KeyData"/>.
        /// </summary>
        /// <remarks>
        /// Data is deeply copied
        /// </remarks>
        /// <param name="ori">
        /// The instance of the <see cref="KeyData"/> class 
        /// used to create the new instance.</param>
        public KeyData(KeyData ori)
        {
            _value = ori._value;

            _comments = new List<string>(_comments);
        }
示例#4
0
        /// <summary>
        ///     EN: Add key to selected section with key value and comment
        /// </summary>
        /// <param name="key">Key name to add</param>
        /// <param name="value">Value to set</param>
        /// <param name="comment">Comment to set</param>
        /// <example>Example: How to add key with value and comment to selected section</example>
        /// <code>addKeyToSelectedSection("name", "My best frend" ,"Igor")</code>
        public void addKeyToSelectedSection(string key, string value, string comment)
        {
            if (sectionData != null)
            {
                if (sectionData.Keys.GetKeyData(key) != null)
                {
                    // Get key from Section
                    keyData = sectionData.Keys.GetKeyData(key);
                }
                else
                {
                    // Adding key to Sectrion
                    sectionData.Keys.AddKey(key);
                    // Get key from Section
                    keyData = sectionData.Keys.GetKeyData(key);
                }

                if (comment != null && !comment.Equals(""))
                {
                    if (keyData.Comments.Count > 0)
                    {
                        keyData.Comments.Clear();
                    }

                    keyData.Comments.Add(comment);
                }

                if (value != null)
                {
                    // Set value to key
                    keyData.Value = value;
                }
            }
        }
示例#5
0
        /// <summary>
        ///     EN: Add key to selected section with key value
        /// </summary>
        /// <param name="key">Key name to add</param>
        /// <param name="value">Key value to set</param>
        /// <example>Example: How to add key with value to selected section</example>
        /// <code>addKeyToSelectedSection("name", "Igor")</code>
        public void addKeyToSelectedSection(string key, string value)
        {
            if (sectionData != null)
            {
                if (sectionData.Keys.GetKeyData(key) != null)
                {
                    // Get key from Section
                    keyData = sectionData.Keys.GetKeyData(key);
                }
                else
                {
                    // Adding key to Sectrion
                    sectionData.Keys.AddKey(key);
                    // Get key from Section
                    keyData = sectionData.Keys.GetKeyData(key);
                }

                if (value != null)
                {
                    // Set value to key
                    keyData.Value = value;
                }
            }
        }
示例#6
0
        public void Issue5_Tests()
        {
            IniData inidata = new IniData();
            inidata.Sections.AddSection("TestSection");

            KeyData key = new KeyData("TestKey");
            key.Value = "TestValue";
            key.Comments.Add("This is a comment");
            inidata["TestSection"].SetKeyData(key);

            Assert.That(inidata["TestSection"].GetKeyData("TestKey").Comments[0], Is.EqualTo("This is a comment"));
        }