Skip to content

Commit

Permalink
Fix the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Jan 22, 2018
1 parent f3a5fbf commit 8305f70
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public AndCombinationPredicateFilter(IEnumerable<IColumnAlias> aliases, IEnumera
protected override bool RowApply(DataRow row)
{
var result = true;
foreach (var predication in predications)
var enumerator = predications.GetEnumerator();
while (enumerator.MoveNext() && result)
{
var value = GetValueFromRow(row, predication.Operand);
result &= predication.Predicate.Execute(value);
var value = GetValueFromRow(row, enumerator.Current.Operand);
result = enumerator.Current.Predicate.Execute(value);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public OrCombinationPredicateFilter(IEnumerable<IColumnAlias> aliases, IEnumerab
protected override bool RowApply(DataRow row)
{
var result = false;
foreach (var predication in predications)
var enumerator = predications.GetEnumerator();
while (enumerator.MoveNext() && !result)
{
var value = GetValueFromRow(row, predication.Operand);
result |= predication.Predicate.Execute(value);
var value = GetValueFromRow(row, enumerator.Current.Operand);
result = enumerator.Current.Predicate.Execute(value);
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion NBi.Core/ResultSet/Resolver/ObjectsToRowsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public IEnumerable<IRow> Execute(IEnumerable<object> objects)
if (items != null)
foreach (var item in items)
{
var cell = new Cell() { Value = item.ToString() };
var cell = new Cell() { Value = item?.ToString() };
row.Cells.Add(cell);
}
rows.Add(row);
Expand Down
47 changes: 47 additions & 0 deletions NBi.Testing/Acceptance/Resources/Positive/QueryAllNoRows.nbits
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,53 @@
</no-rows>
</assert>
</test>
<test name="All-rows with or-combination of numeric information and null" uid="0102">
<system-under-test>
<execution>
<query>
select '2015-10-09', 60
union all select '2015-10-10', null
union all select '2015-10-11', 75
</query>
</execution>
</system-under-test>
<assert>
<all-rows>
<combination operator="or">
<predicate operand="#1">
<null/>
</predicate>
<predicate name="#1">
<less-than>100</less-than>
</predicate>
</combination>
</all-rows>
</assert>
</test>
<test name="Single-row with and-combination of numeric information and null" uid="0102">
<system-under-test>
<execution>
<query>
select '2015-10-09', 60
union all select '2015-10-10', null
union all select '2015-10-11', 75
union all select '2015-10-12', 110
</query>
</execution>
</system-under-test>
<assert>
<single-row>
<combination operator="and">
<predicate operand="#1">
<null not="true"/>
</predicate>
<predicate name="#1">
<more-than>100</more-than>
</predicate>
</combination>
</single-row>
</assert>
</test>
<test name="No-row also works for textual information" uid="0001">
<system-under-test>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,45 @@ public void Apply_And_CorrectResult()
Assert.That(result.Rows, Has.Count.EqualTo(2));
}


[Test]
public void Apply_AndWillNotEvaluateAll_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
{
new List<object>() { null },
new List<object>() { 5 },
new List<object>() { 10 },
new List<object>() { null },
new List<object>() { 20 },
}));

var rs = service.Execute();

var aliases = new[] { Mock.Of<IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

var predicate1 = new Mock<IPredicateInfo>();
predicate1.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
predicate1.SetupGet(p => p.ComparerType).Returns(ComparerType.Null);
predicate1.SetupGet(p => p.Not).Returns(true);
predicate1.SetupGet(p => p.Operand).Returns("#0");

var predicate2 = new Mock<IPredicateInfo>();
predicate2.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
predicate2.SetupGet(p => p.ComparerType).Returns(ComparerType.LessThan);
predicate2.SetupGet(p => p.Operand).Returns("#0");
predicate2.As<IReferencePredicateInfo>().SetupGet(p => p.Reference).Returns(10);

var factory = new PredicateFilterFactory();
var filter = factory.Instantiate(aliases, new IColumnExpression[0], CombinationOperator.And, new[] { predicate1.Object, predicate2.Object });
var result = filter.Apply(rs);

Assert.That(result.Rows, Has.Count.EqualTo(1));
}


[Test]
public void Apply_Or_CorrectResult()
{
Expand Down Expand Up @@ -87,6 +126,42 @@ public void Apply_Or_CorrectResult()
Assert.That(result.Rows, Has.Count.EqualTo(4));
}

[Test]
public void Apply_OrWillNotEvaluateAll_CorrectResult()
{
var service = new ObjectsResultSetResolver(
new ObjectsResultSetResolverArgs(
new object[]
{
new List<object>() { null },
new List<object>() { 5 },
new List<object>() { 10 },
new List<object>() { null },
new List<object>() { 20 },
}));

var rs = service.Execute();

var aliases = new[] { Mock.Of<IColumnAlias>(v => v.Column == 0 && v.Name == "a") };

var predicate1 = new Mock<IPredicateInfo>();
predicate1.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
predicate1.SetupGet(p => p.ComparerType).Returns(ComparerType.Null);
predicate1.SetupGet(p => p.Operand).Returns("#0");

var predicate2 = new Mock<IPredicateInfo>();
predicate2.SetupGet(p => p.ColumnType).Returns(ColumnType.Numeric);
predicate2.SetupGet(p => p.ComparerType).Returns(ComparerType.LessThan);
predicate2.SetupGet(p => p.Operand).Returns("#0");
predicate2.As<IReferencePredicateInfo>().SetupGet(p => p.Reference).Returns(10);

var factory = new PredicateFilterFactory();
var filter = factory.Instantiate(aliases, new IColumnExpression[0], CombinationOperator.Or, new[] { predicate1.Object, predicate2.Object });
var result = filter.Apply(rs);

Assert.That(result.Rows, Has.Count.EqualTo(3));
}

[Test]
public void Apply_XOr_CorrectResult()
{
Expand Down

0 comments on commit 8305f70

Please sign in to comment.