Example #1
0
        public MFTestResults SPOTXml_EnumsTest4()
        {
            /// <summary>
            /// Tests all of the used enumerations in SPOT.Xml
            /// Creates XmlReader using XmlReader.Create(Stream input, XmlReaderSettings settings) and
            /// Sets the ConformanceLevel to Auto (by default it's Document)
            /// Hence, XmlReader should be created using XmlReader.Create(Stream input) 
            /// </summary>
            ///
            bool testResult = true;
            try
            {
                XmlReaderSettings testSettings = new XmlReaderSettings();
                TestStream fragment = new TestStream();

                // Add readstate test for ReadState.Error
                XmlReader testReader = XmlReader.Create(fragment, testSettings);
                if (testReader.ReadState != ReadState.Initial)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to Initial on initialization");
                }

                testReader.Read();
                if (testReader.ReadState != ReadState.Interactive)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to Interactive on read");
                }

                while (testReader.Read()) { }
                if (testReader.ReadState != ReadState.EndOfFile)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to EndOfFile after read");
                }

                testReader.Close();
                if (testReader.ReadState != ReadState.Closed)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to Closed on close");
                }

                Log.Comment("XmlNodeType");
                //Current implementations of XmlReader in SPOT.Xml do not use following XmlNodeTypes 
                //Document, DocumentFragment, Entity, EndEntity or Notation
                //EntityReference, DocumentType          

                TestStream nodeTypes = new TestStream();
                nodeTypes.toNodeTypes();
                testReader = XmlReader.Create(nodeTypes, testSettings);

                if (testReader.NodeType != XmlNodeType.None)
                {
                    testResult = false;
                    Log.Exception("NodeType was not none before read");
                }

                Log.Comment("XmlDeclaration");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.XmlDeclaration)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match XmlDeclaration node");
                }

                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Element)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Element node");
                }

                Log.Comment("CDATA");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.CDATA)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match CDATA node");
                }

                Log.Comment("Comment");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Comment)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Comment node");
                }

                Log.Comment("Element");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Element)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Element node");
                }

                Log.Comment("Text");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Text)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Text node");
                }

                Log.Comment("EndElement");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.EndElement)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match EndElement node");
                }

                Log.Comment("ProcessingInstruction");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.ProcessingInstruction)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match ProcessingInstruction node");
                }

                Log.Comment("Element");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Element)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Element node");
                }

                Log.Comment("SignificantWhitespace");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.SignificantWhitespace)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match SignificantWhitespace node");
                }

                Log.Comment("EndElement");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.EndElement)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match EndElement node");
                }

                try
                {
                    testReader.Read();
                }
                catch (Exception e)
                {
                    if (testReader.ReadState != ReadState.Error)
                    {
                        testResult = false;
                        Log.Exception("ReadState failed to set to Error on parsing error ", e);
                    }
                }
            }
            catch (Exception e)
            {
                testResult = false;
                Log.Exception("Incorrect exception caught: ", e);
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
Example #2
0
        public MFTestResults SPOTXml_EnumsTest4()
        {
            /// <summary>
            /// Tests all of the used enumerations in SPOT.Xml
            /// Creates XmlReader using XmlReader.Create(Stream input, XmlReaderSettings settings) and
            /// Sets the ConformanceLevel to Auto (by default it's Document)
            /// Hence, XmlReader should be created using XmlReader.Create(Stream input)
            /// </summary>
            ///
            bool testResult = true;

            try
            {
                XmlReaderSettings testSettings = new XmlReaderSettings();
                TestStream        fragment     = new TestStream();

                // Add readstate test for ReadState.Error
                XmlReader testReader = XmlReader.Create(fragment, testSettings);
                if (testReader.ReadState != ReadState.Initial)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to Initial on initialization");
                }

                testReader.Read();
                if (testReader.ReadState != ReadState.Interactive)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to Interactive on read");
                }

                while (testReader.Read())
                {
                }
                if (testReader.ReadState != ReadState.EndOfFile)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to EndOfFile after read");
                }

                testReader.Close();
                if (testReader.ReadState != ReadState.Closed)
                {
                    testResult = false;
                    Log.Exception("ReadState failed to set to Closed on close");
                }

                Log.Comment("XmlNodeType");
                //Current implementations of XmlReader in SPOT.Xml do not use following XmlNodeTypes
                //Document, DocumentFragment, Entity, EndEntity or Notation
                //EntityReference, DocumentType

                TestStream nodeTypes = new TestStream();
                nodeTypes.toNodeTypes();
                testReader = XmlReader.Create(nodeTypes, testSettings);

                if (testReader.NodeType != XmlNodeType.None)
                {
                    testResult = false;
                    Log.Exception("NodeType was not none before read");
                }

                Log.Comment("XmlDeclaration");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.XmlDeclaration)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match XmlDeclaration node");
                }

                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Element)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Element node");
                }

                Log.Comment("CDATA");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.CDATA)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match CDATA node");
                }

                Log.Comment("Comment");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Comment)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Comment node");
                }

                Log.Comment("Element");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Element)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Element node");
                }

                Log.Comment("Text");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Text)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Text node");
                }

                Log.Comment("EndElement");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.EndElement)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match EndElement node");
                }

                Log.Comment("ProcessingInstruction");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.ProcessingInstruction)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match ProcessingInstruction node");
                }

                Log.Comment("Element");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.Element)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match Element node");
                }

                Log.Comment("SignificantWhitespace");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.SignificantWhitespace)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match SignificantWhitespace node");
                }

                Log.Comment("EndElement");
                testReader.Read();
                if (testReader.NodeType != XmlNodeType.EndElement)
                {
                    testResult = false;
                    Log.Exception("NodeType did not match EndElement node");
                }

                try
                {
                    testReader.Read();
                }
                catch (Exception e)
                {
                    if (testReader.ReadState != ReadState.Error)
                    {
                        testResult = false;
                        Log.Exception("ReadState failed to set to Error on parsing error ", e);
                    }
                }
            }
            catch (Exception e)
            {
                testResult = false;
                Log.Exception("Incorrect exception caught: ", e);
            }

            return(testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }