Пример #1
0
        public virtual void TestSetBeforeAndGetAfterDeprecationAndDefaults()
        {
            Configuration conf = new Configuration();

            conf.Set("tests.fake-default.old-key", "hello");
            Configuration.AddDeprecation("tests.fake-default.old-key", new string[] { "tests.fake-default.new-key" });
            Assert.Equal("hello", conf.Get("tests.fake-default.new-key"));
        }
Пример #2
0
        public virtual void TestSetBeforeAndGetAfterDeprecation()
        {
            Configuration conf = new Configuration();

            conf.Set("oldkey", "hello");
            Configuration.AddDeprecation("oldkey", new string[] { "newkey" });
            Assert.Equal("hello", conf.Get("newkey"));
        }
Пример #3
0
 private void AddDeprecationToConfiguration()
 {
     Configuration.AddDeprecation("A", new string[] { "B" });
     Configuration.AddDeprecation("C", new string[] { "D" });
     Configuration.AddDeprecation("E", new string[] { "F" });
     Configuration.AddDeprecation("G", new string[] { "H" });
     Configuration.AddDeprecation("I", new string[] { "J" });
     Configuration.AddDeprecation("M", new string[] { "N" });
     Configuration.AddDeprecation("X", new string[] { "Y", "Z" });
     Configuration.AddDeprecation("P", new string[] { "Q", "R" });
 }
Пример #4
0
        public virtual void TestNoFalseDeprecationWarning()
        {
            Configuration conf = new Configuration();

            Configuration.AddDeprecation("AA", "BB");
            conf.Set("BB", "bb");
            conf.Get("BB");
            conf.WriteXml(new ByteArrayOutputStream());
            Assert.Equal(false, Configuration.HasWarnedDeprecation("AA"));
            conf.Set("AA", "aa");
            Assert.Equal(true, Configuration.HasWarnedDeprecation("AA"));
        }
Пример #5
0
        public virtual void TestIteratorWithDeprecatedKeysMappedToMultipleNewKeys()
        {
            Configuration conf = new Configuration();

            Configuration.AddDeprecation("dK", new string[] { "nK1", "nK2" });
            conf.Set("k", "v");
            conf.Set("dK", "V");
            Assert.Equal("V", conf.Get("dK"));
            Assert.Equal("V", conf.Get("nK1"));
            Assert.Equal("V", conf.Get("nK2"));
            conf.Set("nK1", "VV");
            Assert.Equal("VV", conf.Get("dK"));
            Assert.Equal("VV", conf.Get("nK1"));
            Assert.Equal("VV", conf.Get("nK2"));
            conf.Set("nK2", "VVV");
            Assert.Equal("VVV", conf.Get("dK"));
            Assert.Equal("VVV", conf.Get("nK2"));
            Assert.Equal("VVV", conf.Get("nK1"));
            bool kFound   = false;
            bool dKFound  = false;
            bool nK1Found = false;
            bool nK2Found = false;

            foreach (KeyValuePair <string, string> entry in conf)
            {
                if (entry.Key.Equals("k"))
                {
                    Assert.Equal("v", entry.Value);
                    kFound = true;
                }
                if (entry.Key.Equals("dK"))
                {
                    Assert.Equal("VVV", entry.Value);
                    dKFound = true;
                }
                if (entry.Key.Equals("nK1"))
                {
                    Assert.Equal("VVV", entry.Value);
                    nK1Found = true;
                }
                if (entry.Key.Equals("nK2"))
                {
                    Assert.Equal("VVV", entry.Value);
                    nK2Found = true;
                }
            }
            Assert.True("regular Key not found", kFound);
            Assert.True("deprecated Key not found", dKFound);
            Assert.True("new Key 1 not found", nK1Found);
            Assert.True("new Key 2 not found", nK2Found);
        }
Пример #6
0
        public virtual void TestUnsetWithDeprecatedKeys()
        {
            Configuration conf = new Configuration();

            Configuration.AddDeprecation("dK", new string[] { "nK" });
            conf.Set("nK", "VV");
            Assert.Equal("VV", conf.Get("dK"));
            Assert.Equal("VV", conf.Get("nK"));
            conf.Unset("dK");
            NUnit.Framework.Assert.IsNull(conf.Get("dK"));
            NUnit.Framework.Assert.IsNull(conf.Get("nK"));
            conf.Set("nK", "VV");
            Assert.Equal("VV", conf.Get("dK"));
            Assert.Equal("VV", conf.Get("nK"));
            conf.Unset("nK");
            NUnit.Framework.Assert.IsNull(conf.Get("dK"));
            NUnit.Framework.Assert.IsNull(conf.Get("nK"));
        }
Пример #7
0
        //Tests reading / writing a conf file with deprecation after setting
        /// <exception cref="System.Exception"/>
        public virtual void TestReadWriteWithDeprecatedKeys()
        {
            Configuration conf = new Configuration();

            conf.SetBoolean("old.config.yet.to.be.deprecated", true);
            Configuration.AddDeprecation("old.config.yet.to.be.deprecated", new string[] { "new.conf.to.replace.deprecated.conf" });
            ByteArrayOutputStream @out = new ByteArrayOutputStream();
            string fileContents;

            try
            {
                conf.WriteXml(@out);
                fileContents = @out.ToString();
            }
            finally
            {
                @out.Close();
            }
            Assert.True(fileContents.Contains("old.config.yet.to.be.deprecated"
                                              ));
            Assert.True(fileContents.Contains("new.conf.to.replace.deprecated.conf"
                                              ));
        }