Skip to content

Commit

Permalink
Merge branch 'feature/Predicate_reference_being_a_ContextScalarResolv…
Browse files Browse the repository at this point in the history
…er_(#537)' into develop
  • Loading branch information
Cédric L. Charlier committed Oct 8, 2019
2 parents 5a9d7ef + aa43094 commit d2966eb
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 38 deletions.
2 changes: 1 addition & 1 deletion NBi.Core/Scalar/Resolver/FunctionScalarResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NBi.Core.Scalar.Resolver
{
class FunctionScalarResolver<T> : IScalarResolver<T>
{
private FunctionScalarResolverArgs Args { get; }
protected internal FunctionScalarResolverArgs Args { get; }

public FunctionScalarResolver(FunctionScalarResolverArgs args) => Args = args;

Expand Down
3 changes: 0 additions & 3 deletions NBi.NUnit/Builder/Helper/PredicateArgsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace NBi.NUnit.Builder.Helper
{
class PredicateArgsBuilder
{
private bool IsSetup { get; } = false;
private PredicateArgs Args { get; } = null;

private SettingsXml Settings { get; } = SettingsXml.Empty;
private Context Context { get; }

Expand Down
64 changes: 32 additions & 32 deletions NBi.Testing.Core/Calculation/SinglePredicateFilterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public void Apply_Variable_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { "(null)", 10, 100 },
new List<object>() { "(empty)", 2, 75 },
new List<object>() { "C", 5, 50 }
new object[] { "(null)", 10, 100 },
new object[] { "(empty)", 2, 75 },
new object[] { "C", 5, 50 }
}));

var rs = service.Execute();
Expand All @@ -57,11 +57,11 @@ public void Apply_ColumnOrdinal_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { "(null)", 10, 100 },
new List<object>() { "(empty)", 2, 75 },
new List<object>() { "C", 5, 50 }
new object[] { "(null)", 10, 100 },
new object[] { "(empty)", 2, 75 },
new object[] { "C", 5, 50 }
}));
var rs = service.Execute();

Expand All @@ -85,11 +85,11 @@ public void Apply_ColumnName_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { "(null)", 10, 100 },
new List<object>() { "(empty)", 2, 75 },
new List<object>() { "C", 5, 50 }
new object[] { "(null)", 10, 100 },
new object[] { "(empty)", 2, 75 },
new object[] { "C", 5, 50 }
}));
var rs = service.Execute();
rs.Table.Columns[0].ColumnName = "first";
Expand All @@ -113,11 +113,11 @@ public void Apply_ColumnNameCaseNotMatching_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { "(null)", 10, 100 },
new List<object>() { "(empty)", 2, 75 },
new List<object>() { "C", 5, 50 }
new object[] { "(null)", 10, 100 },
new object[] { "(empty)", 2, 75 },
new object[] { "C", 5, 50 }
}));
var rs = service.Execute();
rs.Table.Columns[0].ColumnName = "first";
Expand All @@ -143,11 +143,11 @@ public void Apply_UnexistingColumnName_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { "(null)", 10, 100 },
new List<object>() { "(empty)", 2, 75 },
new List<object>() { "C", 5, 50 }
new object[] { "(null)", 10, 100 },
new object[] { "(empty)", 2, 75 },
new object[] { "C", 5, 50 }
}));
var rs = service.Execute();
rs.Table.Columns[0].ColumnName = "first";
Expand Down Expand Up @@ -176,11 +176,11 @@ public void Apply_NestedExpression_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { 1, 10, 100 },
new List<object>() { 2, 2, 75 },
new List<object>() { 3, 5, 50 }
new object[] { 1, 10, 100 },
new object[] { 2, 2, 75 },
new object[] { 3, 5, 50 }
}));
var rs = service.Execute();

Expand Down Expand Up @@ -218,11 +218,11 @@ public void Apply_MixedExpression_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { 1, 10, 100 },
new List<object>() { 2, 2, 75 },
new List<object>() { 3, 5, 50 }
new object[] { 1, 10, 100 },
new object[] { 2, 2, 75 },
new object[] { 3, 5, 50 }
}));
var rs = service.Execute();
rs.Table.Columns[2].ColumnName = "c1";
Expand Down Expand Up @@ -259,11 +259,11 @@ public void Apply_NativeExpression_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
new []
{
new List<object>() { new DateTime(2019, 10, 01, 8, 0, 0), 10, 100 },
new List<object>() { new DateTime(2019, 10, 01, 23, 0, 0), 2, 75 },
new List<object>() { new DateTime(2019, 10, 02, 05, 0, 0), 5, 50 }
new object[] { new DateTime(2019, 10, 01, 8, 0, 0), 10, 100 },
new object[] { new DateTime(2019, 10, 01, 23, 0, 0), 2, 75 },
new object[] { new DateTime(2019, 10, 02, 05, 0, 0), 5, 50 }
}));
var rs = service.Execute();
rs.Table.Columns[0].ColumnName = "a";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,37 @@
</equalTo>
</assert>
</test>
<test name="Filter with one predicate having the reference defined based on the context of the row and a native function" uid="0206">
<system-under-test>
<result-set file="..\Csv\ResellerOrderCountByYearBefore2006bis.csv">
<alteration>
<rename identifier="#2" new-name="myColumn"/>
<filter>
<predicate name="#1" type="numeric">
<less-than>[myColumn] | numeric-to-increment</less-than>
</predicate>
</filter>
<project-away>
<column identifier="#2"/>
</project-away>
</alteration>
</result-set>
</system-under-test>
<assert>
<equal-to>
<result-set>
<row>
<cell>CY 2005</cell>
<cell>366</cell>
</row>
<row>
<cell>CY 2008</cell>
<cell>894</cell>
</row>
</result-set>
</equal-to>
</assert>
</test>
<test name="Filter with one ranking top" uid="0211">
<system-under-test>
<resultSet file="..\Csv\ResellerOrderCountByYearBefore2006.csv">
Expand Down Expand Up @@ -1006,7 +1037,7 @@
<result-set>
<query>
select 'ABCDE', 'foo', 3, '*'
union all select 'bc', 'bar', 4, '-'
union all select 'bc', 'bar', 4, '#'
union all select null, '', 2, '*'
</query>
<alteration>
Expand All @@ -1029,7 +1060,7 @@
<cell>foo</cell>
</row>
<row>
<cell>bc--</cell>
<cell>bc##</cell>
<cell>bar</cell>
</row>
<row>
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 @@ -202,6 +202,7 @@
<Compile Include="Integration\Core\Scalar\Resolver\QueryScalarResolverTest.cs" />
<Compile Include="Integration\Core\DirectoryInfoExtensionsTest.cs" />
<Compile Include="Unit\NUnit\Builder\Helper\ConnectionStringHelperTest.cs" />
<Compile Include="Unit\NUnit\Builder\Helper\PredicateArgsBuilderTest.cs" />
<Compile Include="Unit\NUnit\Builder\Helper\ScalarResolverArgsBuilderTest.cs" />
<Compile Include="Unit\NUnit\Builder\Helper\SetupHelperTest.cs" />
<Compile Include="Unit\NUnit\Builder\ResultSetAllRowsBuilderTest.cs" />
Expand Down
37 changes: 37 additions & 0 deletions NBi.Testing/Unit/NUnit/Builder/Helper/PredicateArgsBuilderTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using NBi.Core.Calculation.Predicate;
using NBi.Core.Injection;
using NBi.Core.Scalar.Resolver;
using NBi.Core.Variable;
using NBi.NUnit.Builder.Helper;
using NBi.Xml.Constraints.Comparer;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NBi.Testing.Unit.NUnit.Builder.Helper
{
public class PredicateArgsBuilderTest
{
[Test]
public void Build_VariableAndFunctions_FunctionScalarResolverArgs()
{
var predicateXml = new MoreThanXml()
{
Reference = "#12 | text-to-upper | text-to-first-chars([ColA])"
};

var builder = new PredicateArgsBuilder(new ServiceLocator(), new Context(null));
var args = builder.Execute(Core.ResultSet.ColumnType.Text, predicateXml);
Assert.That(args, Is.AssignableTo<ReferencePredicateArgs>());

var typedArgs = args as ReferencePredicateArgs;
Assert.That(typedArgs.Reference, Is.TypeOf<FunctionScalarResolver<string>>());

var function = typedArgs.Reference as FunctionScalarResolver<string>;
Assert.That(function.Args.Resolver, Is.TypeOf<ContextScalarResolver<object>>());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using NBi.Core.Injection;
using NBi.Core.Transformation.Transformer.Native;
using NBi.Core.Variable;

namespace NBi.Testing.Unit.NUnit.Builder.Helper
{
Expand Down Expand Up @@ -39,6 +40,37 @@ public void Build_Variable_GlobalVariableScalarResolverArgs()
Assert.That(args, Is.TypeOf<GlobalVariableScalarResolverArgs>());
}

[Test]
public void Build_ContextColumnName_ContextScalarResolverArgs()
{
var builder = new ScalarResolverArgsBuilder(new ServiceLocator(), new Context(null));
builder.Setup("[ColA]");
builder.Build();
var args = builder.GetArgs();
Assert.That(args, Is.TypeOf<ContextScalarResolverArgs>());
}

[Test]
public void Build_ContextColumnOrdinal_ContextScalarResolverArgs()
{
var builder = new ScalarResolverArgsBuilder(new ServiceLocator(), new Context(null));
builder.Setup("#12");
builder.Build();
var args = builder.GetArgs();
Assert.That(args, Is.TypeOf<ContextScalarResolverArgs>());
}

[Test]
public void Build_ContextColumnOrdinalFollowedByNativeTransformations_ContextScalarResolverArgs()
{
var builder = new ScalarResolverArgsBuilder(new ServiceLocator(), new Context(null));
builder.Setup("#12 | text-to-upper | text-to-first-chars([ColA])");
builder.Build();
var args = builder.GetArgs();
Assert.That(args, Is.TypeOf<FunctionScalarResolverArgs>());
Assert.That((args as FunctionScalarResolverArgs).Resolver, Is.AssignableFrom<ContextScalarResolver<object>>());
}

[Test]
public void Build_LiteralAndFunctions_FunctionScalarResolverArgs()
{
Expand Down

0 comments on commit d2966eb

Please sign in to comment.