Skip to content

Commit

Permalink
Merge branch 'feature/Bug_for_multiple_expressions_(#374)' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed May 29, 2018
2 parents 7537ff0 + da9fef9 commit db8274a
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 40 deletions.
4 changes: 2 additions & 2 deletions NBi.NUnit/Builder/ResultSetNoRowsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ protected virtual NBiConstraint InstantiateConstraint()
protected IResultSetFilter InstantiateFilter()
{
var expressions = new List<IColumnExpression>();
if (ConstraintXml.Expression != null)
expressions.Add(ConstraintXml.Expression);
if (ConstraintXml.Expressions != null)
expressions.AddRange(ConstraintXml.Expressions);

var factory = new ResultSetFilterFactory();
if (ConstraintXml.Predication != null)
Expand Down
24 changes: 23 additions & 1 deletion NBi.Testing/Acceptance/Resources/Positive/QueryAllNoRows.nbits
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@
</all-rows>
</assert>
</test>
<test name="No-row with numeric informations mixing expressions, column name, column index and variable" uid="0010">
<test name="No-row with numeric informations mixing expression, column name, column index and variable" uid="0010">
<system-under-test>
<execution>
<query
Expand All @@ -660,6 +660,28 @@
</no-rows>
</assert>
</test>
<test name="No-row with numeric informations using multiple expressions" uid="0010">
<system-under-test>
<execution>
<query
connectionString="Data Source=mhknbn2kdz.database.windows.net;Initial Catalog=AdventureWorks2012;User Id=sqlfamily;password=sqlf@m1ly"
>
select 10 as 'A' ,11 as 'B', 12 as 'C'
union all select 5,6,7
union all select 7,8,9
</query>
</execution>
</system-under-test>
<assert>
<no-rows>
<expression name="Partial">[A] * [B]</expression>
<expression name="TotalDue">[Partial] * [C]</expression>
<predicate name="TotalDue">
<more-than>10000</more-than>
</predicate>
</no-rows>
</assert>
</test>
<test name="No-row with textual informations direct column name for predicate" uid="0011">
<system-under-test>
<execution>
Expand Down
48 changes: 37 additions & 11 deletions NBi.Testing/Unit/Xml/Constraints/AllRowsXmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,25 @@ public void Deserialize_SampleFile_ReadCorrectlyAnyOfComparer()
Assert.That(cpr.Values, Has.Count.EqualTo(3));
}

[Test]
public void Deserialize_SampleFile_ReadCorrectlyMultipleExpressions()
{
int testNr = 11;

// Create an instance of the XmlSerializer specifying type and namespace.
TestSuiteXml ts = DeserializeSample();
var allRows = ts.Tests[testNr].Constraints[0] as AllRowsXml;
var expressions = allRows.Expressions;

Assert.That(allRows.Expressions, Is.AssignableTo<IEnumerable<ExpressionXml>>());
Assert.That(allRows.Expressions, Has.Count.EqualTo(2));
}

[Test]
public void Serialize_AllRowsXml_OnlyAliasNoVariable()
{
var allRowsXml = new AllRowsXml
#pragma warning disable 0618
#pragma warning disable 0618
{
InternalAliasesOld = new List<AliasXml>()
{
Expand All @@ -327,7 +341,7 @@ public void Serialize_AllRowsXml_OnlyAliasNoVariable()
},
Predication = new PredicationXml()
};
#pragma warning restore 0618
#pragma warning restore 0618

var serializer = new XmlSerializer(typeof(AllRowsXml));
var stream = new MemoryStream();
Expand All @@ -346,9 +360,16 @@ public void Serialize_AllRowsXml_OnlyAliasNoVariable()
[Test]
public void Serialize_AllRowsXml_AnyOfXml()
{
var allRowsXml = new AllRowsXml();
allRowsXml.Predication = new PredicationXml();
allRowsXml.Predication.Predicate = new AnyOfXml() { Values = new List<string>() { "first", "second" } };
var allRowsXml = new AllRowsXml
{
Predication = new PredicationXml()
{
Predicate = new AnyOfXml()
{
Values = new List<string>() { "first", "second" }
}
}
};

var serializer = new XmlSerializer(typeof(AllRowsXml));
var stream = new MemoryStream();
Expand All @@ -369,12 +390,17 @@ public void Serialize_AllRowsXml_AnyOfXml()
[Test]
public void Serialize_ExecutionXml_NoColumnIndex()
{
var allRowsXml = new AllRowsXml();
allRowsXml.Expression = new ExpressionXml()
var allRowsXml = new AllRowsXml
{
Value = "a + b = c",
Type = ColumnType.Boolean,
Name = "calculate"
Expressions = new List<ExpressionXml>()
{
new ExpressionXml()
{
Value = "a + b = c",
Type = ColumnType.Boolean,
Name = "calculate"
}
}
};

var serializer = new XmlSerializer(typeof(AllRowsXml));
Expand All @@ -385,7 +411,7 @@ public void Serialize_ExecutionXml_NoColumnIndex()
serializer.Serialize(writer, allRowsXml);
content = Encoding.UTF8.GetString(stream.ToArray());
}

Debug.WriteLine(content);

Assert.That(content, Is.StringContaining("expression"));
Expand Down
15 changes: 15 additions & 0 deletions NBi.Testing/Unit/Xml/Resources/AllRowsXmlTestSuite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,19 @@
</all-rows>
</assert>
</test>
<test name="With multiple expressions" uid="0011">
<system-under-test>
<execution>
<query name="Select first departments">
select 10 union select 20 union select 30
</query>
</execution>
</system-under-test>
<assert>
<all-rows>
<expression name="div">[#0] / 2</expression>
<expression name="multi">[#0] * 2</expression>
</all-rows>
</assert>
</test>
</testSuite>
12 changes: 7 additions & 5 deletions NBi.Testing/Unit/Xml/TestXmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ public void Serialize_StructureXml_NoDefaultAndSettings()
{ new ReferenceXml()
{ Name = "Bob", ConnectionString = "connStr" }
};
var perspectiveXml = new PerspectiveXml();
perspectiveXml.Caption = "My Caption";
perspectiveXml.Default = new DefaultXml() { ApplyTo = SettingsXml.DefaultScope.Assert, ConnectionString = "connStr" };
perspectiveXml.Settings = new SettingsXml()
var perspectiveXml = new PerspectiveXml
{
References = references
Caption = "My Caption",
Default = new DefaultXml() { ApplyTo = SettingsXml.DefaultScope.Assert, ConnectionString = "connStr" },
Settings = new SettingsXml()
{
References = references
}
};
var structureXml = new StructureXml()
{
Expand Down
3 changes: 2 additions & 1 deletion NBi.Xml/Constraints/NoRowsXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public List<IColumnAlias> Aliases
}

[XmlElement("expression")]
public ExpressionXml Expression { get; set; }
public List<ExpressionXml> Expressions { get; set; }

[XmlElement("alias")]
public List<AliasXml> InternalAliases
Expand Down Expand Up @@ -56,6 +56,7 @@ public List<AliasXml> InternalAliasesOld
public NoRowsXml()
{
internalAliases = new List<AliasXml>();
Expressions = new List<ExpressionXml>();
}
}
}
37 changes: 17 additions & 20 deletions NBi.Xml/XmlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ protected virtual void Read(XmlReader reader)
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);
Int32.TryParse(match.Groups[1].Value, out var line);
Int32.TryParse(match.Groups[2].Value, out var position);
xmlSchemaException = new XmlSchemaException(ex.InnerException.Message, ex, line, position);
}
else
Expand Down Expand Up @@ -182,10 +180,15 @@ private void ParseCascadingInvalidOperationException(InvalidOperationException e
private XmlReaderSettings BuildXmlReaderBaseSettings(bool isDtdProcessing)
{
// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();

//Define the type/level of validation
settings.ValidationType = ValidationType.Schema;
XmlReaderSettings settings = new XmlReaderSettings
{
ValidationType = ValidationType.Schema,
DtdProcessing = isDtdProcessing ? DtdProcessing.Parse : DtdProcessing.Prohibit,
XmlResolver = new LocalXmlUrlResolver(basePath)
{
Credentials = System.Net.CredentialCache.DefaultCredentials
}
};
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += delegate (object sender, ValidationEventArgs args)
{
Expand All @@ -197,14 +200,6 @@ private XmlReaderSettings BuildXmlReaderBaseSettings(bool isDtdProcessing)
validationExceptions.Add(args.Exception);
};

//Allow DTD processing
settings.DtdProcessing = isDtdProcessing ? DtdProcessing.Parse : DtdProcessing.Prohibit;

// Supply the credentials necessary to access the DTD file stored on the network.
var resolver = new LocalXmlUrlResolver(basePath);
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;
settings.XmlResolver = resolver;

return settings;
}

Expand Down Expand Up @@ -251,10 +246,12 @@ protected virtual SettingsXml LoadSettings(string settingsFilename)

//Create an empty XmlRoot.
//This is needed because the class settingsXml is not decorated with an attribute "XmlRoot".
XmlRootAttribute xmlRoot = new XmlRootAttribute();
xmlRoot.ElementName = "settings";
xmlRoot.Namespace = "http://NBi/TestSuite";
xmlRoot.IsNullable = true;
XmlRootAttribute xmlRoot = new XmlRootAttribute
{
ElementName = "settings",
Namespace = "http://NBi/TestSuite",
IsNullable = true
};

SettingsXml settings = null;
// Create the XmlReader object.
Expand Down

0 comments on commit db8274a

Please sign in to comment.