diff --git a/NBi.Core/ResultSet/Comparer/NumericBoundedPercentageTolerance.cs b/NBi.Core/ResultSet/Comparer/NumericBoundedPercentageTolerance.cs index aa3456b98..735fed7a9 100644 --- a/NBi.Core/ResultSet/Comparer/NumericBoundedPercentageTolerance.cs +++ b/NBi.Core/ResultSet/Comparer/NumericBoundedPercentageTolerance.cs @@ -26,9 +26,11 @@ public NumericBoundedPercentageTolerance(decimal percentage, decimal minValue, d : base(percentage) { if (minValue == 0 && maxValue == 0) - throw new ArgumentException(); - if (minValue < 0 || maxValue < 0) - throw new ArgumentException(); + throw new ArgumentException("You must specify a minimum or a maximum value but both were set to 0."); + if (minValue < 0) + throw new ArgumentException(String.Format("Minimum value can't be less than 0 but was set to {0}", minValue)); + if (maxValue < 0) + throw new ArgumentException(String.Format("Maximum value can't be less than 0 but was set to {0}", maxValue)); Value = percentage; Min = minValue; diff --git a/NBi.Core/ResultSet/Comparer/ToleranceFactory.cs b/NBi.Core/ResultSet/Comparer/ToleranceFactory.cs index aba95919b..911cd0d45 100644 --- a/NBi.Core/ResultSet/Comparer/ToleranceFactory.cs +++ b/NBi.Core/ResultSet/Comparer/ToleranceFactory.cs @@ -97,9 +97,9 @@ public static NumericTolerance BuildNumeric(string value) if (bound.Length>3 && (bound.Substring(0, 3) == "min" || bound.Substring(0, 3) == "max")) { isBoundedPercentage = decimal.TryParse(bound.Substring(3), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out toleranceBound); - if (bound.Contains("min")) + if (bound.ToLower().Contains("min")) min = toleranceBound; - if (bound.Contains("max")) + if (bound.ToLower().Contains("max")) max = toleranceBound; isBoundedPercentage = (min != max); } diff --git a/NBi.Core/ResultSet/DataRowBasedResultSetComparer.cs b/NBi.Core/ResultSet/DataRowBasedResultSetComparer.cs index 1f8730d08..52ed259ba 100644 --- a/NBi.Core/ResultSet/DataRowBasedResultSetComparer.cs +++ b/NBi.Core/ResultSet/DataRowBasedResultSetComparer.cs @@ -47,13 +47,12 @@ private void CalculateHashValues(DataTable dt, Dictionary dict.Clear(); Int64 keysHashed; - //Int64 valuesHashed; foreach (DataRow row in dt.Rows) { CompareHelper hlpr = new CompareHelper(); - keyComparer.GetHashCode64_KeysValues(row, out keysHashed);//, out valuesHashed); + keyComparer.GetHashCode64_KeysValues(row, out keysHashed); hlpr.KeysHashed = keysHashed; //hlpr.ValuesHashed = valuesHashed; diff --git a/NBi.Core/ResultSet/ResultSetCompareResult.cs b/NBi.Core/ResultSet/ResultSetCompareResult.cs index c7c723960..768eaf46f 100644 --- a/NBi.Core/ResultSet/ResultSetCompareResult.cs +++ b/NBi.Core/ResultSet/ResultSetCompareResult.cs @@ -15,9 +15,9 @@ public class ResultSetCompareResult { public bool Value { get; set; } public ResultSetDifferenceType Difference { get; set; } - public Sample Missing { get; set; } - public Sample Unexpected { get; set; } - public Sample Duplicated { get; set; } + public IEnumerable Missing { get; set; } + public IEnumerable Unexpected { get; set; } + public IEnumerable Duplicated { get; set; } public Sample NonMatchingValue { get; set; } @@ -54,38 +54,19 @@ public static ResultSetCompareResult Build(IEnumerable missingRows, IEn else res = new ResultSetCompareResult() { Difference = ResultSetDifferenceType.Content }; - res.Missing=GetSubset(missingRows); - res.Unexpected = GetSubset(unexpectedRows); - res.Duplicated = GetSubset(duplicatedRows); + res.Missing=missingRows; + res.Unexpected = unexpectedRows; + res.Duplicated = duplicatedRows; res.NonMatchingValue = GetSubset(nonMatchingValueRows, keyMatchingRows); return res; } - private const int MAX_ROWS_RESULT = 10; - private const int COUNT_ROWS_SAMPLE_RESULT = 10; - - private static Sample GetSubset(IEnumerable rows) - { - var subset = new List(MAX_ROWS_RESULT); - - if (rows.Count() > MAX_ROWS_RESULT) - subset = rows.Take(COUNT_ROWS_SAMPLE_RESULT).ToList(); - else - subset = rows.ToList(); - - return new Sample(subset, null, rows.Count()); - } private static Sample GetSubset(IEnumerable rows, IEnumerable reference) { - var subset = new List(MAX_ROWS_RESULT); - - if (rows.Count() > MAX_ROWS_RESULT) - subset = rows.Take(COUNT_ROWS_SAMPLE_RESULT).ToList(); - else - subset = rows.ToList(); - + var subset = new List(rows.Count()); + subset = rows.ToList(); return new Sample(subset, reference, rows.Count()); } diff --git a/NBi.Framework/FailureMessage/DataRowsMessage.cs b/NBi.Framework/FailureMessage/DataRowsMessage.cs index 878f5646e..02b87f73d 100644 --- a/NBi.Framework/FailureMessage/DataRowsMessage.cs +++ b/NBi.Framework/FailureMessage/DataRowsMessage.cs @@ -21,9 +21,9 @@ public void Build(IEnumerable expectedRows, IEnumerable actual expected = BuildTable(expectedRows, Profile.ExpectedSet); actual = BuildTable(actualRows, Profile.ActualSet); - compared = BuildNonEmptyTable(compareResult.Unexpected.Rows, "Unexpected", Profile.AnalysisSet); - compared.Append(BuildNonEmptyTable(compareResult.Missing.Rows ?? new List(), "Missing", Profile.AnalysisSet)); - compared.Append(BuildNonEmptyTable(compareResult.Duplicated.Rows ?? new List(), "Duplicated", Profile.AnalysisSet)); + compared = BuildNonEmptyTable(compareResult.Unexpected, "Unexpected", Profile.AnalysisSet); + compared.Append(BuildNonEmptyTable(compareResult.Missing ?? new List(), "Missing", Profile.AnalysisSet)); + compared.Append(BuildNonEmptyTable(compareResult.Duplicated ?? new List(), "Duplicated", Profile.AnalysisSet)); compared.Append(BuildCompareTable(compareResult.NonMatchingValue.Rows ?? new List(), "Non matching value", Profile.AnalysisSet)); } diff --git a/NBi.Testing/Acceptance/Resources/Positive/FasterThan.nbits b/NBi.Testing/Acceptance/Resources/Positive/FasterThan.nbits index 7b570e167..660a84cc5 100644 --- a/NBi.Testing/Acceptance/Resources/Positive/FasterThan.nbits +++ b/NBi.Testing/Acceptance/Resources/Positive/FasterThan.nbits @@ -1,5 +1,10 @@  + + + Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly + + @@ -19,7 +24,7 @@ - + SELECT NULL @@ -29,4 +34,22 @@ + + + + + 2008 + 10 + 1 + + + + + + + diff --git a/NBi.Testing/Acceptance/Resources/Positive/ReportEqualTo.nbits b/NBi.Testing/Acceptance/Resources/Positive/ReportEqualTo.nbits index 36310efa1..2a97c8967 100644 --- a/NBi.Testing/Acceptance/Resources/Positive/ReportEqualTo.nbits +++ b/NBi.Testing/Acceptance/Resources/Positive/ReportEqualTo.nbits @@ -5,7 +5,7 @@ Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly - - - - - - - 2008 - 10 - 1 - - - - - - - + diff --git a/NBi.Testing/DiskOnFile.cs b/NBi.Testing/DiskOnFile.cs index 87997ad8d..7cf0be9c7 100644 --- a/NBi.Testing/DiskOnFile.cs +++ b/NBi.Testing/DiskOnFile.cs @@ -44,6 +44,9 @@ public static string CreatePhysicalFile(string filename, string resource) using (Stream stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream(resource)) { + if (stream == null) + throw new FileNotFoundException(resource); + //Open another stream to persist the file on disk using (Stream file = File.OpenWrite(fullpath)) { diff --git a/NBi.Testing/NBi.Testing.csproj b/NBi.Testing/NBi.Testing.csproj index 200e95f3d..bda451ec9 100644 --- a/NBi.Testing/NBi.Testing.csproj +++ b/NBi.Testing/NBi.Testing.csproj @@ -560,6 +560,7 @@ + diff --git a/NBi.Testing/Unit/Xml/Resources/XmlManagerInvalidFormat.xml b/NBi.Testing/Unit/Xml/Resources/XmlManagerInvalidFormat.xml new file mode 100644 index 000000000..376ca9da1 --- /dev/null +++ b/NBi.Testing/Unit/Xml/Resources/XmlManagerInvalidFormat.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + SELECT MyHierarchy, MyMeasure FROM MyTable + + + + + diff --git a/NBi.Testing/Unit/Xml/XmlManagerTest.cs b/NBi.Testing/Unit/Xml/XmlManagerTest.cs index f6683cf1e..19dd52d25 100644 --- a/NBi.Testing/Unit/Xml/XmlManagerTest.cs +++ b/NBi.Testing/Unit/Xml/XmlManagerTest.cs @@ -30,6 +30,16 @@ public void Load_ValidFile_TestContentIsCorrect() Assert.That(manager.TestSuite.Tests[0].Content, Is.StringEnding("")); } + [Test] + public void Load_InvalidFormat_ThrowException() + { + var filename = DiskOnFile.CreatePhysicalFile("InvalidFormat.nbits", "NBi.Testing.Unit.Xml.Resources.XmlManagerInvalidFormat.xml"); + + var manager = new XmlManager(); + var ex = Assert.Throws(delegate { manager.Load(filename); }); + Assert.That(ex.Message, Is.StringContaining("At line 14")); + } + [Test] public void Load_InvalidFile_ThrowException() { diff --git a/NBi.Xml/XmlManager.cs b/NBi.Xml/XmlManager.cs index d42cc9e4e..60531fe82 100644 --- a/NBi.Xml/XmlManager.cs +++ b/NBi.Xml/XmlManager.cs @@ -10,6 +10,7 @@ using NBi.Xml.Constraints; using NBi.Xml.Settings; using NBi.Xml.Decoration.Command; +using System.Text.RegularExpressions; namespace NBi.Xml { @@ -116,13 +117,28 @@ protected virtual void Read(XmlReader reader) { if (ex.InnerException is XmlException) { + XmlSchemaException xmlSchemaException; if (ex.InnerException.Message.Contains("For security reasons DTD is prohibited")) + xmlSchemaException = new XmlSchemaException("DTD is prohibited. To activate it, set the flag allow-dtd-processing to true in the config file associated to this test-suite"); + else { - var msg = "DTD is prohibited. To activate it, set the flag allow-dtd-processing to true in the config file associated to this test-suite"; - Console.WriteLine(msg); - var dtdException = new XmlSchemaException(msg); - validationExceptions.Add(dtdException); + var regex = new Regex(@"Line (\d+), position (\d+).$"); + var match = regex.Match(ex.InnerException.Message); + if (match.Success) + { + int line = 0; + Int32.TryParse(match.Groups[1].Value, out line); + int position = 0; + Int32.TryParse(match.Groups[2].Value, out position); + xmlSchemaException = new XmlSchemaException(ex.InnerException.Message, ex, line, position); + } + else + xmlSchemaException = new XmlSchemaException(ex.InnerException.Message); + } + Console.WriteLine(xmlSchemaException.Message); + validationExceptions.Add(xmlSchemaException); + } else ParseCascadingInvalidOperationException(ex.InnerException as InvalidOperationException);