Ejemplo n.º 1
0
        public void TestGetJsonDefaultOf() {
            var cfg = new AttributeCfg(@"{}");
            Assert.IsNotNull(cfg);
            Assert.IsNotNull(cfg.Sites);
            Assert.AreEqual(0, cfg.Sites.Count);

            var sites = new AttributeSite().WithDefaults();
            Assert.IsNotNull(sites);
            Assert.IsNotNull(sites.Something);
        }
Ejemplo n.º 2
0
        public void TestInvalidProcess() {
            var cfg = new AttributeCfg(
                @"<cfg>
                    <sites>
                        <add/>
                    </sites>
                </cfg>"
            );

            var problems = cfg.Errors();

            Assert.AreEqual(2, problems.Length);

            foreach (var problem in problems) {
                Console.WriteLine(problem);
            }
            Assert.IsTrue(problems[0] == "A 'sites' 'add' element is missing a 'name' attribute.");
            Assert.IsTrue(problems[1] == "A 'sites' 'add' element is missing a 'url' attribute.");
        }
Ejemplo n.º 3
0
 public void TestEmptyJsonSites() {
     var cfg = new AttributeCfg("{\"sites\":[]}");
     Assert.AreEqual(1, cfg.Errors().Length);
     Assert.AreEqual("A 'sites' element with at least one item is required.", cfg.Errors()[0]);
 }
Ejemplo n.º 4
0
 public void TestEmptySites() {
     var cfg = new AttributeCfg(@"<cfg><sites/></cfg>");
     Assert.AreEqual(1, cfg.Errors().Length);
     Assert.AreEqual("A 'sites' element with at least one item is required in cfg.", cfg.Errors()[0]);
 }
Ejemplo n.º 5
0
 public void TestNewJson() {
     var cfg = new AttributeCfg(@"{}");
     Assert.IsNotNull(cfg);
     Assert.IsNotNull(cfg.Sites);
     Assert.AreEqual(0, cfg.Sites.Count);
 }
Ejemplo n.º 6
0
        public void TestMultipleSites() {
            var xml = @"<cfg>
                    <sites>
                        <add name='google' url='http://www.google.com' something='&lt;'/>
                        <add name='github' url='http://www.github.com' numeric='x'/>
                        <add name='stackoverflow' url='http://www.stackoverflow.com' numeric='7' />
                        <add name='github' url='http://www.anotherGitHub.com' something='this is a duplicate!' />
                    </sites>
                </cfg>".Replace("'", "\"");

            var stopWatch = new Stopwatch();
            stopWatch.Start();
            var cfg = new AttributeCfg(xml);
            stopWatch.Stop();

            Console.WriteLine("cfg.net load ms:" + stopWatch.ElapsedMilliseconds);

            stopWatch.Restart();
            var doc = XDocument.Parse(xml);
            stopWatch.Stop();

            Console.WriteLine("xdoc parse ms:" + stopWatch.ElapsedMilliseconds);

            Assert.IsNotNull(doc);

            var problems = cfg.Errors();

            foreach (var problem in problems) {
                Console.WriteLine(problem);
            }

            Assert.AreEqual(2, problems.Length);
            Assert.AreEqual("Could not set 'numeric' to 'x' inside 'sites' 'add'. Input string was not in a correct format.", problems[0]);
            Assert.AreEqual("Duplicate 'name' value 'github' in 'sites'.", problems[1]);

            Assert.AreEqual(4, cfg.Sites.Count);

            Assert.AreEqual("google", cfg.Sites[0].Name);
            Assert.AreEqual("http://www.google.com", cfg.Sites[0].Url);
            Assert.AreEqual("<", cfg.Sites[0].Something);
            Assert.AreEqual(0, cfg.Sites[0].Numeric);

            Assert.AreEqual("github", cfg.Sites[1].Name);
            Assert.AreEqual("http://www.github.com", cfg.Sites[1].Url);

            Assert.AreEqual(7, cfg.Sites[2].Numeric);

        }
Ejemplo n.º 7
0
        public void TestInvalidSiteAttribute() {
            var cfg = new AttributeCfg(
                @"<cfg>
                    <sites>
                        <add name='dale' invalid='true' />
                    </sites>
                </cfg>".Replace("'", "\"")
            );

            var problems = cfg.Errors();

            foreach (var problem in problems) {
                Console.WriteLine(problem);
            }

            Assert.AreEqual(2, problems.Length);
            Assert.AreEqual("A 'sites' 'add' element contains an invalid 'invalid' attribute.  Valid attributes are: name, url, something, numeric, common.", problems[0]);
            Assert.AreEqual("A 'sites' 'add' element is missing a 'url' attribute.", problems[1]);

        }