Ejemplo n.º 1
0
        public static void AreEqual(CompilationError[] expectedCompilationErrors, CompilationErrorCollection actualCompilationErrors)
        {
            if (expectedCompilationErrors == null && actualCompilationErrors != null)
            {
                Assert.Fail("No errors expected, but errors occured during query execution.\r\nActual errors:\r\n\r\n{0}", GetErrors(actualCompilationErrors));
            }

            if (expectedCompilationErrors != null && actualCompilationErrors == null)
            {
                Assert.Fail("Expected errors, but no errors occured during query execution.\r\nExpected errors:\r\n\r\n{0}", GetErrors(expectedCompilationErrors));
            }

            try
            {
                if (expectedCompilationErrors == null)
                {
                    return;
                }

                Assert.AreEqual(expectedCompilationErrors.Length, actualCompilationErrors.Count);

                for (int i = 0; i < expectedCompilationErrors.Length; i++)
                {
                    Assert.AreEqual(expectedCompilationErrors[i].Id, actualCompilationErrors[i].Id, "Error message {0} of {1} is different", i + 1, expectedCompilationErrors.Length);
                    Assert.AreEqual(expectedCompilationErrors[i].Text, actualCompilationErrors[i].Text, "Error message {0} of {1} is different", i + 1, expectedCompilationErrors.Length);
                }
            }
            catch (AssertFailedException ex)
            {
                string msg = String.Format("Expected query errors do not match actual query errors. See inner exception for first mismatch.\r\nActual errors:\r\n\r\n{0}\r\nExpected errors:\r\n\r\n{1}", GetErrors(actualCompilationErrors), GetErrors(expectedCompilationErrors));
                throw new Exception(msg, ex);
            }
        }
Ejemplo n.º 2
0
		public static void AreEqual(CompilationError[] expectedCompilationErrors, CompilationErrorCollection actualCompilationErrors)
		{
			if (expectedCompilationErrors == null && actualCompilationErrors != null)
				Assert.Fail("No errors expected, but errors occured during query execution.\r\nActual errors:\r\n\r\n{0}", GetErrors(actualCompilationErrors));

			if (expectedCompilationErrors != null && actualCompilationErrors == null)
				Assert.Fail("Expected errors, but no errors occured during query execution.\r\nExpected errors:\r\n\r\n{0}", GetErrors(expectedCompilationErrors));

			try
			{
				if (expectedCompilationErrors == null)
					return;

				Assert.AreEqual(expectedCompilationErrors.Length, actualCompilationErrors.Count);

				for (int i = 0; i < expectedCompilationErrors.Length; i++)
				{
					Assert.AreEqual(expectedCompilationErrors[i].Id, actualCompilationErrors[i].Id, "Error message {0} of {1} is different", i + 1, expectedCompilationErrors.Length);
					Assert.AreEqual(expectedCompilationErrors[i].Text, actualCompilationErrors[i].Text, "Error message {0} of {1} is different", i + 1, expectedCompilationErrors.Length);
				}
			}
			catch (AssertFailedException ex)
			{
				string msg = String.Format("Expected query errors do not match actual query errors. See inner exception for first mismatch.\r\nActual errors:\r\n\r\n{0}\r\nExpected errors:\r\n\r\n{1}", GetErrors(actualCompilationErrors), GetErrors(expectedCompilationErrors));
				throw new Exception(msg, ex);
			}
		}
Ejemplo n.º 3
0
		public CompilationFailedEventArgs(IList<CompilationError> errors)
		{
			if (errors == null)
				throw ExceptionBuilder.ArgumentNull("errors");

			_compilationErrors = new CompilationErrorCollection(errors);
		}
Ejemplo n.º 4
0
		internal CompilationException(string message, IList<CompilationError> errors)
			: base(message)
		{
			if (errors == null)
				throw ExceptionBuilder.ArgumentNull("errors");

			_compilationErrors = new CompilationErrorCollection(errors);
		}
Ejemplo n.º 5
0
        protected static void RunTest(string resNameOfTestDefinition)
        {
            TestDefinition testDefinition = TestDefinition.FromResource(resNameOfTestDefinition);

            if (testDefinition == null)
            {
                Assert.Fail("Could not find test definition XML for test '{0}'.", resNameOfTestDefinition);
            }

            Query query = QueryFactory.CreateQuery();

            query.Text = testDefinition.CommandText;

            CompilationErrorCollection actualCompilationErrors = null;
            string    actualRuntimeError = null;
            ShowPlan  actualPlan         = null;
            DataTable actualResults      = null;

            try
            {
                actualResults = query.ExecuteDataTable();
                actualPlan    = query.GetShowPlan();
            }
            catch (RuntimeException ex)
            {
                actualRuntimeError = ex.Message;
            }
            catch (CompilationException ex)
            {
                actualCompilationErrors = ex.CompilationErrors;
            }

            Assert.AreEqual(testDefinition.ExpectedRuntimeError, actualRuntimeError);
            AssertHelpers.AreEqual(testDefinition.ExpectedCompilationErrors, actualCompilationErrors);
            AssertHelpers.AreEqual(testDefinition.ExpectedResults, actualResults);
            AssertHelpers.AreEqual(testDefinition.ExpectedPlan, actualPlan);
        }
Ejemplo n.º 6
0
        private void ExportTestDefinition()
        {
            if (saveTestDefinitionFileDialog.ShowDialog() == DialogResult.OK)
            {
                Text = String.Format("NQuery - [{0}]", Path.GetFileName(saveTestDefinitionFileDialog.FileName));
                CompilationErrorCollection compilationErrors = null;
                RuntimeException           runtimeException  = null;
                DataTable result   = null;
                ShowPlan  showPlan = null;

                Query query = new Query();
                query.DataContext = _query.DataContext;
                query.Text        = syntaxEditor.Text;

                try
                {
                    result   = query.ExecuteDataTable();
                    showPlan = query.GetShowPlan();
                }
                catch (RuntimeException ex)
                {
                    runtimeException = ex;
                }
                catch (CompilationException ex)
                {
                    compilationErrors = ex.CompilationErrors;
                }

                XmlDocument testDefinition = new XmlDocument();
                XmlNode     rootNode       = testDefinition.CreateElement("test");
                testDefinition.AppendChild(rootNode);

                XmlNode sqlNode = testDefinition.CreateElement("sql");
                sqlNode.InnerText = syntaxEditor.Text;
                rootNode.AppendChild(sqlNode);

                if (runtimeException != null)
                {
                    XmlNode expectedRuntimeErrorNode = testDefinition.CreateElement("expectedRuntimeError");
                    rootNode.AppendChild(expectedRuntimeErrorNode);
                    expectedRuntimeErrorNode.InnerText = runtimeException.Message;
                }
                else if (compilationErrors != null)
                {
                    XmlNode expectedErrorsNode = testDefinition.CreateElement("expectedErrors");
                    rootNode.AppendChild(expectedErrorsNode);

                    foreach (CompilationError error in compilationErrors)
                    {
                        XmlNode errorNode = testDefinition.CreateElement("expectedError");

                        XmlAttribute idAtt = testDefinition.CreateAttribute("id");
                        idAtt.Value = error.Id.ToString();
                        errorNode.Attributes.Append(idAtt);

                        XmlAttribute textAtt = testDefinition.CreateAttribute("text");
                        textAtt.Value = error.Text;
                        errorNode.Attributes.Append(textAtt);

                        expectedErrorsNode.AppendChild(errorNode);
                    }
                }

                if (result != null)
                {
                    XmlNode resultsNode = testDefinition.CreateElement("expectedResults");
                    rootNode.AppendChild(resultsNode);

                    StringBuilder sb = new StringBuilder();
                    using (StringWriter stringWriter = new StringWriter(sb))
                    {
                        DataSet dataSet = new DataSet();
                        dataSet.Tables.Add(result);
                        dataSet.WriteXml(stringWriter, XmlWriteMode.WriteSchema);
                    }

                    resultsNode.InnerXml = sb.ToString();
                }

                if (showPlan != null)
                {
                    XmlNode planNode = testDefinition.CreateElement("expectedPlan");
                    rootNode.AppendChild(planNode);

                    XmlNode executionPlanNode = testDefinition.ImportNode(showPlan.ToXml().SelectSingleNode("executionPlan"), true);
                    planNode.AppendChild(executionPlanNode);
                }

                testDefinition.Save(saveTestDefinitionFileDialog.FileName);
            }
        }
Ejemplo n.º 7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="CompilationException"/> class with serialized data.  
		/// </summary>
		/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context"> The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
		/// <exception name="ArgumentNullException">The <paramref name="info"/> parameter is <see langword="null"/>.</exception>
		/// <exception name="SerializationException">The class name is <see langword="null"/> or <see cref="Exception.HResult"/> is zero (<c>0</c>).</exception>
		private CompilationException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			_compilationErrors = (CompilationErrorCollection) info.GetValue("CompilationErrors", typeof(CompilationErrorCollection));
		}