Exemplo n.º 1
0
        public void GetTokens_GraphCycleTypeReferences_ThrowsGraphCycleException()
        {
            var input = new Person
            {
                Name   = "John, Jr.",
                Father = new Person
                {
                    Name = "John, Sr."
                },
                Mother = new Person
                {
                    Name = "Sally"
                }
            };

            // create multiple cycles
            input.Father.Children = input.Mother.Children = new Person[]
            {
                input
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.Reference
            });

            GraphCycleException ex = Assert.Throws <GraphCycleException>(
                delegate
            {
                walker.GetTokens(input).ToArray();
            });

            Assert.Equal(GraphCycleType.Reference, ex.CycleType);
        }
Exemplo n.º 2
0
        public void GetTokens_GraphCycleTypeMaxDepthNoMaxDepth_ThrowsArgumentException()
        {
            var input = new Person
            {
                Name   = "John, Jr.",
                Father = new Person
                {
                    Name = "John, Sr."
                },
                Mother = new Person
                {
                    Name = "Sally"
                }
            };

            // create multiple cycles
            input.Father.Children = input.Mother.Children = new Person[]
            {
                input
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.MaxDepth,
                MaxDepth    = 0
            });

            ArgumentException ex = Assert.Throws <ArgumentException>(
                delegate
            {
                walker.GetTokens(input).ToArray();
            });

            Assert.Equal("maxDepth", ex.ParamName);
        }
Exemplo n.º 3
0
        public void Ctor_NullSettings_ThrowsArgumentNullException()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var transformer = new XmlReader.XmlInTransformer(null);
            });

            // verify exception is coming from expected param
            Assert.Equal("settings", ex.ParamName);
        }
Exemplo n.º 4
0
        public void Ctor_NullSettings_ThrowsArgumentNullException()
        {
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var walker = new ModelWalker(null);
            });

            // verify exception is coming from expected param
            Assert.Equal("settings", ex.ParamName);
        }
        public void Format_NullTokens_ThrowsArgumentNullException()
        {
            var input = (IEnumerable <Token <ModelTokenType> >)null;

            var formatter = new BsonWriter.BsonFormatter();

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate()
            {
                var actual = formatter.Format(input);
            });

            Assert.Equal("tokens", ex.ParamName);
        }
        public void Format_NullStream_ThrowsArgumentNullException()
        {
            var input = new Token <ModelTokenType> [0];

            var formatter = new BsonWriter.BsonFormatter();

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate()
            {
                formatter.Format(input, null);
            });

            Assert.Equal("stream", ex.ParamName);
        }
Exemplo n.º 7
0
        public void Format_NullInput_ThrowsArgumentNullException()
        {
            var input = (IEnumerable <Token <ModelTokenType> >)null;

            var formatter = new JsonWriter.JsonFormatter(new DataWriterSettings());

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var actual = formatter.Format(input);
            });

            // verify exception is coming from expected param
            Assert.Equal("tokens", ex.ParamName);
        }
Exemplo n.º 8
0
        public void GetTokens_NullStream_ThrowsArgumentNullException()
        {
            var input    = (Stream)null;
            var expected = new Token <ModelTokenType> [0];

            var tokenizer = new BsonReader.BsonTokenizer();

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate()
            {
                var actual = tokenizer.GetTokens(input).ToArray();
            });

            Assert.Equal("stream", ex.ParamName);
        }
Exemplo n.º 9
0
        public void Analyze_NullInput_ThrowsArgumentNullException()
        {
            var input = (IEnumerable <Token <ModelTokenType> >)null;

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected param
            Assert.Equal("tokens", ex.ParamName);
        }
Exemplo n.º 10
0
        public void Format_NullInput_ThrowsArgumentNullException()
        {
            var input = (IEnumerable <Token <MarkupTokenType> >)null;

            var transformer = new XmlReader.XmlInTransformer(new DataReaderSettings());

            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(
                delegate
            {
                var actual = transformer.Transform(input).ToArray();
            });

            // verify exception is coming from expected param
            Assert.Equal("input", ex.ParamName);
        }
Exemplo n.º 11
0
        public void Format_UnopenedCloseTag_ThrowsTokenException()
        {
            var input = new []
            {
                MarkupGrammar.TokenElementEnd
            };

            var formatter = new XmlWriter.XmlFormatter(new DataWriterSettings());
            TokenException <MarkupTokenType> ex = Assert.Throws <TokenException <MarkupTokenType> >(
                delegate()
            {
                var actual = formatter.Format(input);
            });

            Assert.Equal(input[0], ex.Token);
        }
Exemplo n.º 12
0
        public void GetTokens_XmlDocTypeExternal_ReturnsUnparsed()
        {
            const string input =
                @"<!DOCTYPE html PUBLIC
	""-//W3C//DTD XHTML 1.1//EN""
	""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"">
<root />";

            var tokenizer = new XmlReader.XmlTokenizer();
            DeserializationException ex = Assert.Throws <DeserializationException>(
                delegate()
            {
                var actual = tokenizer.GetTokens(input).ToArray();
            });

            Assert.Equal(0, ex.Index);
        }
Exemplo n.º 13
0
        public void Read_ArrayExtraClose_ThrowsDeserializationException()
        {
            // input from fail8.json in test suite at http://www.json.org/JSON_checker/
            var input = @"[""Extra close""]]";

            var reader = new JsonReader(new DataReaderSettings {
                AllowTrailingContent = false
            });

            DeserializationException ex = Assert.Throws <DeserializationException>(
                delegate
            {
                var actual = reader.Read(input);
            });

            // verify exception is coming from expected position
            Assert.Equal(15L, ex.Index);
        }
Exemplo n.º 14
0
        public void Analyze_ArrayUnclosed_ThrowsAnalyzerException()
        {
            // input from fail2.json in test suite at http://www.json.org/JSON_checker/
            var input = new []
            {
                ModelGrammar.TokenArrayBeginUnnamed,
                ModelGrammar.TokenPrimitive("Unclosed array")
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            TokenException <ModelTokenType> ex = Assert.Throws <TokenException <ModelTokenType> >(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected token
            Assert.Equal(ModelGrammar.TokenNone, ex.Token);
        }
Exemplo n.º 15
0
        public void Read_ObjectExtraValueAfterClose_ThrowsDeserializationException()
        {
            // input from fail10.json in test suite at http://www.json.org/JSON_checker/
            var input = @"{""Extra value after close"": true} ""misplaced quoted value""";

            var reader = new JsonReader(new DataReaderSettings {
                AllowTrailingContent = false
            });

            DeserializationException ex = Assert.Throws <DeserializationException>(
                delegate
            {
                var actual = reader.Read(input);
            });

            // verify exception is coming from expected position
            // note the reader doesn't see the 2nd object until it is read
            // so the index is after the trailing value
            Assert.Equal(57L, ex.Index);
        }
Exemplo n.º 16
0
        public void Analyze_ObjectUnterminated_ThrowsAnalyzerException()
        {
            // input from fail32.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenProperty("Comma instead if closing brace"),
                ModelGrammar.TokenTrue
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            TokenException <ModelTokenType> ex = Assert.Throws <TokenException <ModelTokenType> >(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected token
            Assert.Equal(ModelGrammar.TokenNone, ex.Token);
        }
Exemplo n.º 17
0
        public void Write_CompareObjectOutputToXmlSerializer_Serializes()
        {
            var input = new
            {
                False    = false,
                LeapDay  = new DateTime(2008, 2, 29, 23, 59, 59, 999, DateTimeKind.Utc),
                FortyTwo = 42,
                Text     = "Ordinary string"
            };

            // XmlSerializer cannot serialize Anonymous objects
            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(
                delegate()
            {
                var expected = SystemXmlWriter(input, CreateSettings(false));
            });

            //var actual = new XmlWriter().Serialize(input);

            //Assert.Equal(expected.ToString(), actual);
        }
Exemplo n.º 18
0
        public void Write_CompareDictionaryOutputToXmlSerializer_Serializes()
        {
            var input = new Hashtable()
            {
                { "False", false },
                { "LeapDay", new DateTime(2008, 2, 29, 23, 59, 59, 999, DateTimeKind.Utc) },
                { "FortyTwo", 42 },
                { "Text", "Ordinary string" }
            };

            // XmlSerializer cannot serialize type Hashtable
            NotSupportedException ex = Assert.Throws <NotSupportedException>(
                delegate()
            {
                var expected = SystemXmlWriter(input, CreateSettings(false));
            });

            //var actual = new XmlWriter(new DataWriterSettings(new XmlResolverStrategy())).Serialize(input);

            //Assert.Equal(expected.ToString(), actual);
        }
Exemplo n.º 19
0
        public void Analyze_ValueInsteadOfProperty_ThrowsAnalyzerException()
        {
            // input from fail21.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                ModelGrammar.TokenObjectBeginUnnamed,
                ModelGrammar.TokenPrimitive("Comma instead of colon"),
                ModelGrammar.TokenNull,
                ModelGrammar.TokenObjectEnd
            };

            var analyzer = new ModelAnalyzer(new DataReaderSettings());

            TokenException <ModelTokenType> ex = Assert.Throws <TokenException <ModelTokenType> >(
                delegate
            {
                var actual = analyzer.Analyze <object>(input).Single();
            });

            // verify exception is coming from expected token
            Assert.Equal(ModelGrammar.TokenPrimitive("Comma instead of colon"), ex.Token);
        }
Exemplo n.º 20
0
        public void GetTokens_UndeclaredPrefixes_ThrowsDeserializationException()
        {
            const string input    = @"<a:one><b:two><c:three></d:three></e:two></f:one>";
            var          expected = new[]
            {
                MarkupGrammar.TokenElementBegin(new DataName("one")),
                MarkupGrammar.TokenElementBegin(new DataName("two")),
                MarkupGrammar.TokenElementBegin(new DataName("three")),
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd,
                MarkupGrammar.TokenElementEnd
            };

            var tokenizer = new XmlReader.XmlTokenizer();

            DeserializationException ex = Assert.Throws <DeserializationException>(
                delegate()
            {
                var actual = tokenizer.GetTokens(input).ToArray();
            });

            Assert.Equal(2, ex.Index);
        }
Exemplo n.º 21
0
        public void GetTokens_GraphCycleTypeMaxDepthFalsePositive_ThrowsGraphCycleException()
        {
            // input from fail18.json in test suite at http://www.json.org/JSON_checker/
            var input = new[]
            {
                new []
                {
                    new []
                    {
                        new []
                        {
                            new []
                            {
                                new []
                                {
                                    new []
                                    {
                                        new []
                                        {
                                            new []
                                            {
                                                new []
                                                {
                                                    new []
                                                    {
                                                        new []
                                                        {
                                                            new []
                                                            {
                                                                new []
                                                                {
                                                                    new []
                                                                    {
                                                                        new []
                                                                        {
                                                                            new []
                                                                            {
                                                                                new []
                                                                                {
                                                                                    new []
                                                                                    {
                                                                                        new []
                                                                                        {
                                                                                            "Too deep"
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var walker = new ModelWalker(new DataWriterSettings
            {
                GraphCycles = GraphCycleType.MaxDepth,
                MaxDepth    = 19
            });

            GraphCycleException ex = Assert.Throws <GraphCycleException>(
                delegate
            {
                walker.GetTokens(input).ToArray();
            });

            Assert.Equal(GraphCycleType.MaxDepth, ex.CycleType);
        }