Skip to content

Commit

Permalink
Merge branch 'master' into release/v1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric L. Charlier committed Jul 13, 2015
2 parents d3c9664 + 30960c6 commit 96c8f79
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions NBi.Core/ResultSet/Comparer/ToleranceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions NBi.Core/ResultSet/DataRowBasedResultSetComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,12 @@ private void CalculateHashValues(DataTable dt, Dictionary<Int64, CompareHelper>
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;
Expand Down
35 changes: 8 additions & 27 deletions NBi.Core/ResultSet/ResultSetCompareResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataRow> Missing { get; set; }
public IEnumerable<DataRow> Unexpected { get; set; }
public IEnumerable<DataRow> Duplicated { get; set; }
public Sample NonMatchingValue { get; set; }


Expand Down Expand Up @@ -54,38 +54,19 @@ public static ResultSetCompareResult Build(IEnumerable<DataRow> 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<DataRow> rows)
{
var subset = new List<DataRow>(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<DataRow> rows, IEnumerable<DataRow> reference)
{
var subset = new List<DataRow>(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<DataRow>(rows.Count());
subset = rows.ToList();
return new Sample(subset, reference, rows.Count());
}

Expand Down
6 changes: 3 additions & 3 deletions NBi.Framework/FailureMessage/DataRowsMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public void Build(IEnumerable<DataRow> expectedRows, IEnumerable<DataRow> 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<DataRow>(), "Missing", Profile.AnalysisSet));
compared.Append(BuildNonEmptyTable(compareResult.Duplicated.Rows ?? new List<DataRow>(), "Duplicated", Profile.AnalysisSet));
compared = BuildNonEmptyTable(compareResult.Unexpected, "Unexpected", Profile.AnalysisSet);
compared.Append(BuildNonEmptyTable(compareResult.Missing ?? new List<DataRow>(), "Missing", Profile.AnalysisSet));
compared.Append(BuildNonEmptyTable(compareResult.Duplicated ?? new List<DataRow>(), "Duplicated", Profile.AnalysisSet));
compared.Append(BuildCompareTable(compareResult.NonMatchingValue.Rows ?? new List<DataRow>(), "Non matching value", Profile.AnalysisSet));
}

Expand Down
25 changes: 24 additions & 1 deletion NBi.Testing/Acceptance/Resources/Positive/FasterThan.nbits
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<testSuite name="Acceptance Testing: Faster Than" xmlns="http://NBi/TestSuite">
<settings>
<default apply-to="system-under-test">
<connectionString>Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly</connectionString>
</default>
</settings>
<test name="A fast query MDX">
<system-under-test>
<execution>
Expand All @@ -19,7 +24,7 @@
<test name="A fast query SQL">
<system-under-test>
<execution>
<query name="SQL" connectionString="Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly">
<query name="SQL">
SELECT
NULL
</query>
Expand All @@ -29,4 +34,22 @@
<fasterThan max-time-milliSeconds="5000" timeout-milliSeconds="10000"/>
</assert>
</test>
<test name="Faster than from a report" uid="0001">
<system-under-test>
<execution>
<report
path="..\Reports\"
name="Employee_Sales_Summary"
dataset="EmpSalesMonth2008R2"
>
<parameter name="@ReportYear" sql-type="int">2008</parameter>
<parameter name="@ReportMonth" sql-type="int">10</parameter>
<parameter name="@EmployeeID" sql-type="int">1</parameter>
</report>
</execution>
</system-under-test>
<assert>
<fasterThan max-time-milliSeconds="10000"/>
</assert>
</test>
</testSuite>
26 changes: 4 additions & 22 deletions NBi.Testing/Acceptance/Resources/Positive/ReportEqualTo.nbits
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<connectionString>Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly</connectionString>
</default>
</settings>
<!--<test name="Validate the different business entities" uid="0001">
<test name="Validate the different business entities" uid="0001">
<condition>
<service-running name="MSSQL$SQL2012"/>
</condition>
Expand Down Expand Up @@ -61,8 +61,8 @@
</resultSet>
</equalTo>
</assert>
</test>-->
<!--<test name="Validate the different business entities" uid="0001">
</test>
<test name="Validate the different business entities" uid="0001">
<system-under-test>
<execution>
<report
Expand All @@ -79,23 +79,5 @@
<resultSet file="..\Csv\BusinessEntity.csv"/>
</equalTo>
</assert>
</test>-->
<test name="Get sales summary for an employee" uid="0001">
<system-under-test>
<execution>
<report
path="..\Reports\"
name="Employee_Sales_Summary"
dataset="EmpSalesMonth2008R2"
>
<parameter name="@ReportYear" sql-type="int">2008</parameter>
<parameter name="@ReportMonth" sql-type="int">10</parameter>
<parameter name="@EmployeeID" sql-type="int">1</parameter>
</report>
</execution>
</system-under-test>
<assert>
<fasterThan max-time-milliSeconds="1000"/>
</assert>
</test>
</test>
</testSuite>
3 changes: 3 additions & 0 deletions NBi.Testing/DiskOnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
1 change: 1 addition & 0 deletions NBi.Testing/NBi.Testing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@
<EmbeddedResource Include="Unit\Xml\Resources\SettingsXmlWithDefaultEverywhere.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Unit\Xml\Resources\XmlManagerInvalidFormat.xml" />
<EmbeddedResource Include="Unit\Xml\Resources\TablesXmlTestSuite.xml" />
<EmbeddedResource Include="Unit\Xml\Resources\SetXmlTestSuite.xml" />
<EmbeddedResource Include="Unit\Xml\Resources\XmlManagerInvalidSyntaxMultiple.xml" />
Expand Down
24 changes: 24 additions & 0 deletions NBi.Testing/Unit/Xml/Resources/XmlManagerInvalidFormat.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<testSuite name="My first test suite" xmlns="http://NBi/TestSuite">
<test name="My first test">
<system-under-test>
<execution>
<query connectionString="...">
<![CDATA[
SELECT
{[Measure].[MyMeasure]} ON 0,
{[MyDimension].[MyHierarchy].Members} ON 1
FROM
MyCube
]]>
</execution>
</system-under-test>
<assert>
<equalTo>
<query connectionString="...">
SELECT MyHierarchy, MyMeasure FROM MyTable
</query>
</equalTo>
</assert>
</test>
</testSuite>
10 changes: 10 additions & 0 deletions NBi.Testing/Unit/Xml/XmlManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public void Load_ValidFile_TestContentIsCorrect()
Assert.That(manager.TestSuite.Tests[0].Content, Is.StringEnding("</test>"));
}

[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<ArgumentException>(delegate { manager.Load(filename); });
Assert.That(ex.Message, Is.StringContaining("At line 14"));
}

[Test]
public void Load_InvalidFile_ThrowException()
{
Expand Down
24 changes: 20 additions & 4 deletions NBi.Xml/XmlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using NBi.Xml.Constraints;
using NBi.Xml.Settings;
using NBi.Xml.Decoration.Command;
using System.Text.RegularExpressions;

namespace NBi.Xml
{
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 96c8f79

Please sign in to comment.