Skip to content

Commit

Permalink
Merge branch 'feature/Variables_not_passed_to_assertion_(#419)' into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
Cédric L. Charlier committed Oct 31, 2018
2 parents d4c8cf4 + 6d6b1d9 commit 1109098
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 76 deletions.
2 changes: 1 addition & 1 deletion NBi.NUnit/Builder/AbstractExecutionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected virtual IQuery GetQuery(ExecutionXml executionXml)
{
var builder = new QueryResolverArgsBuilder(ServiceLocator);
parameters = builder.BuildParameters(((QueryXml)executionXml.BaseItem).GetParameters());
variables = ((QueryXml)executionXml.BaseItem).GetVariables();
variables = ((QueryXml)executionXml.BaseItem).GetTemplateVariables();
timeout = ((QueryXml)executionXml.BaseItem).Timeout;
}
if (executionXml.BaseItem is ReportXml)
Expand Down
8 changes: 4 additions & 4 deletions NBi.NUnit/Builder/AbstractResultSetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ protected virtual IResultSetService InstantiateSystemUnderTest(ExecutionXml exec
var statement = (executionXml.Item as QueryableXml).GetQuery();

IEnumerable<IQueryParameter> parameters = null;
IEnumerable<IQueryTemplateVariable> variables = null;
IEnumerable<IQueryTemplateVariable> templateVariables = null;
int timeout = 0;
var commandType = System.Data.CommandType.Text;
var commandType = CommandType.Text;

if (executionXml.BaseItem is QueryXml)
{
parameters = argsBuilder.BuildParameters(((QueryXml)executionXml.BaseItem).GetParameters());
variables = ((QueryXml)executionXml.BaseItem).GetVariables();
templateVariables = ((QueryXml)executionXml.BaseItem).GetTemplateVariables();
timeout = ((QueryXml)executionXml.BaseItem).Timeout;
}
if (executionXml.BaseItem is ReportXml)
Expand All @@ -82,7 +82,7 @@ protected virtual IResultSetService InstantiateSystemUnderTest(ExecutionXml exec
commandType = ((ReportXml)executionXml.BaseItem).GetCommandType();
}

var queryArgs = new QueryResolverArgs(statement, connectionString, parameters, variables, new TimeSpan(0, 0, timeout), commandType);
var queryArgs = new QueryResolverArgs(statement, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout), commandType);
var args = new QueryResultSetResolverArgs(queryArgs);
var factory = ServiceLocator.GetResultSetResolverFactory();
var resolver = factory.Instantiate(args);
Expand Down
12 changes: 6 additions & 6 deletions NBi.NUnit/Builder/Helper/QueryResolverArgsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ public void Build()

var connectionString = queryXml.GetConnectionString();
var parameters = BuildParameters(queryXml.GetParameters());
var variables = queryXml.GetVariables();
var templateVariables = queryXml.GetTemplateVariables();
var timeout = queryXml.Timeout;

if (!string.IsNullOrEmpty(queryXml.InlineQuery))
args = new EmbeddedQueryResolverArgs(queryXml.InlineQuery
, connectionString, parameters, variables, new TimeSpan(0, 0, timeout));
, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));

else if (!string.IsNullOrEmpty(queryXml.File))
{
var file = GetFullPath(settingsXml?.BasePath, queryXml.File);

args = new ExternalFileQueryResolverArgs(file
, connectionString, parameters, variables, new TimeSpan(0, 0, timeout));
, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));
}

else if (queryXml.Assembly != null)
Expand All @@ -75,7 +75,7 @@ public void Build()
args = new AssemblyQueryResolverArgs(
file, queryXml.Assembly.Klass, queryXml.Assembly.Method,
queryXml.Assembly.Static, queryXml.Assembly.GetMethodParameters()
, connectionString, parameters, variables, new TimeSpan(0, 0, timeout));
, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));
}

else if (queryXml.Report != null)
Expand All @@ -84,7 +84,7 @@ public void Build()

args = new ReportDataSetQueryResolverArgs(
queryXml.Report.Source, path, queryXml.Report.Name, queryXml.Report.Dataset
, connectionString, parameters, variables, new TimeSpan(0, 0, timeout));
, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));
}

else if (queryXml.SharedDataset != null)
Expand All @@ -93,7 +93,7 @@ public void Build()

args = new SharedDataSetQueryResolverArgs(
queryXml.SharedDataset.Source, queryXml.SharedDataset.Path, queryXml.SharedDataset.Name
, connectionString, parameters, variables, new TimeSpan(0, 0, timeout));
, connectionString, parameters, templateVariables, new TimeSpan(0, 0, timeout));
}

if (args == null)
Expand Down
1 change: 1 addition & 0 deletions NBi.NUnit/Builder/Helper/ScalarResolverArgsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void Build()
var builder = new ResultSetResolverArgsBuilder(serviceLocator);
builder.Setup(((ProjectionXml)obj).ResultSet);
builder.Setup(settings);
builder.Setup(globalVariables);
builder.Build();
args = new RowCountResultSetScalarResolverArgs(builder.GetArgs());
}
Expand Down
1 change: 1 addition & 0 deletions NBi.NUnit/Builder/MembersContainBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected NBiConstraint InstantiateConstraint(ContainXml ctrXml)
var builder = new ResultSetResolverArgsBuilder(ServiceLocator);
builder.Setup(ctrXml.Query);
builder.Setup(ctrXml.Settings);
builder.Setup(Variables);
builder.Build();

var factory = ServiceLocator.GetResultSetResolverFactory();
Expand Down
1 change: 1 addition & 0 deletions NBi.NUnit/Builder/MembersContainedInBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected NBiConstraint InstantiateConstraint(ContainedInXml ctrXml)
var builder = new ResultSetResolverArgsBuilder(ServiceLocator);
builder.Setup(ctrXml.Query);
builder.Setup(ctrXml.Settings);
builder.Setup(Variables);
builder.Build();

var factory = ServiceLocator.GetResultSetResolverFactory();
Expand Down
1 change: 1 addition & 0 deletions NBi.NUnit/Builder/MembersEquivalentToBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected NBiConstraint InstantiateConstraint(EquivalentToXml ctrXml)
var builder = new ResultSetResolverArgsBuilder(ServiceLocator);
builder.Setup(ctrXml.Query);
builder.Setup(ctrXml.Settings);
builder.Setup(Variables);
builder.Build();

var factory = ServiceLocator.GetResultSetResolverFactory();
Expand Down
14 changes: 6 additions & 8 deletions NBi.NUnit/Builder/ResultSetEqualToBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ class ResultSetEqualToBuilder : AbstractResultSetBuilder
protected EqualToXml ConstraintXml { get; set; }

protected virtual EquivalenceKind EquivalenceKind
{
get { return EquivalenceKind.EqualTo; }
}
{ get => EquivalenceKind.EqualTo; }

public ResultSetEqualToBuilder()
{

}
{ }

protected override void SpecificSetup(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)
{
Expand Down Expand Up @@ -111,6 +107,7 @@ protected virtual BaseResultSetComparisonConstraint InstantiateConstraint(object
var argsBuilder = new ResultSetResolverArgsBuilder(ServiceLocator);
argsBuilder.Setup(obj);
argsBuilder.Setup(settings);
argsBuilder.Setup(Variables);
argsBuilder.Build();

var factory = ServiceLocator.GetResultSetResolverFactory();
Expand All @@ -123,9 +120,10 @@ protected virtual BaseResultSetComparisonConstraint InstantiateConstraint(object

var service = serviceBuilder.GetService();

return new EqualToConstraint(service);
return InstantiateConstraint(service);
}


protected virtual BaseResultSetComparisonConstraint InstantiateConstraint(IResultSetService service)
=> new EqualToConstraint(service);
}
}
38 changes: 6 additions & 32 deletions NBi.NUnit/Builder/ResultSetSubsetOfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ namespace NBi.NUnit.Builder
{
class ResultSetSubsetOfBuilder : ResultSetEqualToBuilder
{
public ResultSetSubsetOfBuilder()
{

}
protected override EquivalenceKind EquivalenceKind
{
get { return EquivalenceKind.SubsetOf; }
}
{ get => EquivalenceKind.SubsetOf; }

public ResultSetSubsetOfBuilder()
{ }

protected override void SpecificSetup(AbstractSystemUnderTestXml sutXml, AbstractConstraintXml ctrXml)
{
Expand All @@ -39,30 +36,7 @@ protected override void SpecificSetup(AbstractSystemUnderTestXml sutXml, Abstrac
ConstraintXml = (SubsetOfXml)ctrXml;
}

protected override void SpecificBuild()
{
Constraint = InstantiateConstraint();
}


protected override BaseResultSetComparisonConstraint InstantiateConstraint(object obj, SettingsXml settings, TransformationProvider transformation)
{
var argsBuilder = new ResultSetResolverArgsBuilder(ServiceLocator);
argsBuilder.Setup(obj);
argsBuilder.Setup(settings);
argsBuilder.Build();

var factory = ServiceLocator.GetResultSetResolverFactory();
var resolver = factory.Instantiate(argsBuilder.GetArgs());

var builder = new ResultSetServiceBuilder();
builder.Setup(resolver);
if (transformation != null)
builder.Setup(transformation.Transform);
var service = builder.GetService();

return new SubsetOfConstraint(service);
}

protected override BaseResultSetComparisonConstraint InstantiateConstraint(IResultSetService service)
=> new SubsetOfConstraint(service);
}
}
23 changes: 2 additions & 21 deletions NBi.NUnit/Builder/ResultSetSupersetOfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,8 @@ protected override void SpecificSetup(AbstractSystemUnderTestXml sutXml, Abstrac
ConstraintXml = (SupersetOfXml)ctrXml;
}

protected override void SpecificBuild()
{
Constraint = InstantiateConstraint();
}

protected override BaseResultSetComparisonConstraint InstantiateConstraint(object obj, SettingsXml settings, TransformationProvider transformation)
{
var argsBuilder = new ResultSetResolverArgsBuilder(ServiceLocator);
argsBuilder.Setup(obj);
argsBuilder.Build();
protected override BaseResultSetComparisonConstraint InstantiateConstraint(IResultSetService service)
=> new SupersetOfConstraint(service);

var factory = ServiceLocator.GetResultSetResolverFactory();
var resolver = factory.Instantiate(argsBuilder.GetArgs());

var builder = new ResultSetServiceBuilder();
builder.Setup(resolver);
if (transformation != null)
builder.Setup(transformation.Transform);
var service = builder.GetService();

return new SupersetOfConstraint(service);
}
}
}
1 change: 1 addition & 0 deletions NBi.Testing/Acceptance/Resources/Positive/Variable.nbits
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
</system-under-test>
<assert>
<equalTo>
<column index="0" type="dateTime" role="key"/>
<query>
<parameter name="common">@common</parameter>
select @common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void GetConstraint_Build_CorrectConstraint()
var itemXmlStubFactory = new Mock<QueryableXml>();
itemXmlStubFactory.Setup(i => i.GetQuery()).Returns("query");
itemXmlStubFactory.Setup(i => i.GetParameters()).Returns(new List<QueryParameterXml>());
itemXmlStubFactory.Setup(i => i.GetVariables()).Returns(new List<QueryTemplateVariableXml>());
itemXmlStubFactory.Setup(i => i.GetTemplateVariables()).Returns(new List<QueryTemplateVariableXml>());
sutXmlStubFactory.Setup(s => s.Item).Returns(itemXmlStubFactory.Object);
var sutXml = sutXmlStubFactory.Object;
sutXml.Item = itemXmlStubFactory.Object;
Expand All @@ -77,7 +77,7 @@ public void GetSystemUnderTest_Build_CorrectIDbCommand()
var itemXmlStubFactory = new Mock<QueryableXml>();
itemXmlStubFactory.Setup(i => i.GetQuery()).Returns("query");
itemXmlStubFactory.Setup(i => i.GetParameters()).Returns(new List<QueryParameterXml>());
itemXmlStubFactory.Setup(i => i.GetVariables()).Returns(new List<QueryTemplateVariableXml>());
itemXmlStubFactory.Setup(i => i.GetTemplateVariables()).Returns(new List<QueryTemplateVariableXml>());
sutXmlStubFactory.Setup(s => s.Item).Returns(itemXmlStubFactory.Object);
var sutXml = sutXmlStubFactory.Object;
sutXml.Item = itemXmlStubFactory.Object;
Expand Down
2 changes: 1 addition & 1 deletion NBi.Testing/Unit/Xml/Settings/SettingsXmlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public void DeserializeStructurePerspective_SettingsWithVariables_True()
// Create an instance of the XmlSerializer specifying type and namespace.
TestSuiteXml ts = DeserializeSample("SettingsXmlWithVariables");

var parameters = ((QueryXml)ts.Tests[testNr].Systems[0].BaseItem).GetVariables();
var parameters = ((QueryXml)ts.Tests[testNr].Systems[0].BaseItem).GetTemplateVariables();
Assert.That(parameters.Count, Is.EqualTo(3));
}

Expand Down
2 changes: 1 addition & 1 deletion NBi.Xml/Items/QueryableXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public virtual List<QueryParameterXml> GetParameters()
return list;
}

public virtual List<QueryTemplateVariableXml> GetVariables()
public virtual List<QueryTemplateVariableXml> GetTemplateVariables()
{
var list = Variables;
foreach (var variable in Default.Variables)
Expand Down

0 comments on commit 1109098

Please sign in to comment.