Skip to content

Commit

Permalink
new-name is now accepting a ScalarResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Jul 1, 2019
1 parent 9a57fe2 commit be5deb9
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 60 deletions.
7 changes: 4 additions & 3 deletions NBi.Core/ResultSet/Alteration/Renaming/NewNameRenamingArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Core.Scalar.Resolver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -9,9 +10,9 @@ namespace NBi.Core.ResultSet.Alteration.Renaming
public class NewNameRenamingArgs : IRenamingArgs
{
public IColumnIdentifier OriginalIdentification { get; set; }
public IColumnIdentifier NewIdentification { get; set; }
public IScalarResolver<string> NewIdentification { get; set; }

public NewNameRenamingArgs(IColumnIdentifier originalIdentification, IColumnIdentifier newIdentification)
public NewNameRenamingArgs(IColumnIdentifier originalIdentification, IScalarResolver<string> newIdentification)
=> (OriginalIdentification, NewIdentification) = (originalIdentification, newIdentification);
}
}
11 changes: 6 additions & 5 deletions NBi.Core/ResultSet/Alteration/Renaming/NewNameRenamingEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using NBi.Core.Scalar.Resolver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -9,14 +10,14 @@ namespace NBi.Core.ResultSet.Alteration.Renaming
class NewNameRenamingEngine : IRenamingEngine
{
private IColumnIdentifier OriginalIdentification { get; }
private ColumnNameIdentifier NewIdentification { get; }
private IScalarResolver<string> NewIdentification { get; }

public NewNameRenamingEngine(IColumnIdentifier originalIdentification, IColumnIdentifier newIdentification)
=> (OriginalIdentification, NewIdentification) = (originalIdentification, newIdentification as ColumnNameIdentifier);
public NewNameRenamingEngine(IColumnIdentifier originalIdentification, IScalarResolver<string> newIdentification)
=> (OriginalIdentification, NewIdentification) = (originalIdentification, newIdentification);

public ResultSet Execute(ResultSet rs)
{
OriginalIdentification.GetColumn(rs.Table).ColumnName = NewIdentification.Name;
OriginalIdentification.GetColumn(rs.Table).ColumnName = NewIdentification.Execute();
return rs;
}
}
Expand Down
5 changes: 4 additions & 1 deletion NBi.NUnit/Builder/Helper/ResultSetSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ public IEnumerable<Alter> InstantiateAlterations(ResultSetSystemXml resultSetXml
{
foreach (var renameXml in resultSetXml.Alteration.Renamings)
{
var helper = new ScalarHelper(serviceLocator, variables);
var newName = helper.InstantiateResolver<string>(renameXml.NewName);

var factory = new RenamingFactory();
var renamer = factory.Instantiate(new NewNameRenamingArgs(renameXml.Identifier, renameXml.NewName));
var renamer = factory.Instantiate(new NewNameRenamingArgs(renameXml.Identifier, newName));
yield return renamer.Execute;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,21 +855,21 @@
</query>
<alteration>
<rename identifier="[f0]" new-name="keyField"/>
<rename identifier="[f2]" new-name="valueField"/>
<rename identifier="[f2]" new-name="@CY2007"/>
</alteration>
</result-set>
</system-under-test>
<assert>
<equal-to>
<column name="keyField" role="key" type="text"/>
<column name="valueField" role="value" type="text"/>
<column name="CY 2007" role="value" type="text"/>
<result-set>
<query connection-string="@ref1">
select 'a' as f0, 'FOO' as f1, null as f2 union all select 'B', 'bar', null
</query>
<alteration>
<rename identifier="[f0]" new-name="keyField"/>
<rename identifier="[f1]" new-name="valueField"/>
<rename identifier="[f1]" new-name="@CY2007"/>
</alteration>
</result-set>
</equal-to>
Expand Down
72 changes: 36 additions & 36 deletions NBi.Testing/Acceptance/RuntimeOverrider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,43 @@ public void TearDownMethods()

//By Acceptance Test Suite (file) create a Test Case
[Test]
//[TestCase("QueryUniqueRows.nbits")]
//[TestCase("AssemblyEqualToResultSet.nbits")]
//[TestCase("CsvEqualToResultSet.nbits")]
//[TestCase("QueryEqualToWithParameter.nbits")]
//[TestCase("QueryEqualToCsv.nbits")]
//[TestCase("QueryEqualToCsvWithProfile.nbits")]
//[TestCase("QueryEqualToQuery.nbits")]
//[TestCase("QuerySubsetOfQuery.nbits")]
//[TestCase("QuerySupersetOfQuery.nbits")]
//[TestCase("QueryEqualToResultSet.nbits")]
//[TestCase("QueryEqualToResultSetWithNull.nbits")]
//[TestCase("QueryWithReference.nbits")]
//[TestCase("Ordered.nbits")]
//[TestCase("Count.nbits")]
//[TestCase("Contain.nbits")]
//[TestCase("ContainStructure.nbits")]
//[TestCase("FasterThan.nbits")]
//[TestCase("SyntacticallyCorrect.nbits")]
//[TestCase("Exists.nbits")]
//[TestCase("LinkedTo.nbits")]
//[TestCase("SubsetOfStructure.nbits")]
//[TestCase("EquivalentToStructure.nbits")]
//[TestCase("SubsetOfMembers.nbits")]
//[TestCase("EquivalentToMembers.nbits")]
//[TestCase("MatchPatternMembers.nbits")]
//[TestCase("ResultSetMatchPattern.nbits")]
//[TestCase("QueryWithParameters.nbits")]
//[TestCase("ReportEqualTo.nbits")]
//[TestCase("Decoration.nbits")]
//[TestCase("Is.nbits")]
//[TestCase("QueryEqualToXml.nbits")]
//[TestCase("QueryRowCount.nbits")]
//[TestCase("QueryAllNoRows.nbits")]
[TestCase("QueryUniqueRows.nbits")]
[TestCase("AssemblyEqualToResultSet.nbits")]
[TestCase("CsvEqualToResultSet.nbits")]
[TestCase("QueryEqualToWithParameter.nbits")]
[TestCase("QueryEqualToCsv.nbits")]
[TestCase("QueryEqualToCsvWithProfile.nbits")]
[TestCase("QueryEqualToQuery.nbits")]
[TestCase("QuerySubsetOfQuery.nbits")]
[TestCase("QuerySupersetOfQuery.nbits")]
[TestCase("QueryEqualToResultSet.nbits")]
[TestCase("QueryEqualToResultSetWithNull.nbits")]
[TestCase("QueryWithReference.nbits")]
[TestCase("Ordered.nbits")]
[TestCase("Count.nbits")]
[TestCase("Contain.nbits")]
[TestCase("ContainStructure.nbits")]
[TestCase("FasterThan.nbits")]
[TestCase("SyntacticallyCorrect.nbits")]
[TestCase("Exists.nbits")]
[TestCase("LinkedTo.nbits")]
[TestCase("SubsetOfStructure.nbits")]
[TestCase("EquivalentToStructure.nbits")]
[TestCase("SubsetOfMembers.nbits")]
[TestCase("EquivalentToMembers.nbits")]
[TestCase("MatchPatternMembers.nbits")]
[TestCase("ResultSetMatchPattern.nbits")]
[TestCase("QueryWithParameters.nbits")]
[TestCase("ReportEqualTo.nbits")]
[TestCase("Decoration.nbits")]
[TestCase("Is.nbits")]
[TestCase("QueryEqualToXml.nbits")]
[TestCase("QueryRowCount.nbits")]
[TestCase("QueryAllNoRows.nbits")]
[TestCase("ResultSetConstraint.nbits")]
//[TestCase("Scoring.nbits")]
//[TestCase("Environment.nbits")]
//[TestCase("MultipleInstance.nbits")]
[TestCase("Scoring.nbits")]
[TestCase("Environment.nbits")]
[TestCase("MultipleInstance.nbits")]
//[TestCase("Etl.nbits")]
//[TestCase("PowerBiDesktop.nbits")]
//[TestCase("EvaluateRows.nbits")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NBi.Core.ResultSet;
using NBi.Core.ResultSet.Alteration.Renaming;
using NBi.Core.ResultSet.Resolver;
using NBi.Core.Scalar.Resolver;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand All @@ -21,7 +22,7 @@ public void Execute_FirstColumnIsText_FirstColumnIsNumeric()

var renamer = new NewNameRenamingEngine(
new ColumnOrdinalIdentifier(1),
new ColumnNameIdentifier("myNewName")
new LiteralScalarResolver<string>("myNewName")
);
var newRs = renamer.Execute(rs);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NBi.Core.ResultSet;
using NBi.Core.ResultSet.Alteration.Renaming;
using NBi.Core.ResultSet.Resolver;
using NBi.Core.Scalar.Resolver;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand All @@ -18,7 +19,7 @@ public void Instantiate_NewNameRenamingEngineArgs_NewNameRenamingEngineArgs()
var factory = new RenamingFactory();
var renamer = factory.Instantiate(new NewNameRenamingArgs(
new ColumnOrdinalIdentifier(1),
new ColumnNameIdentifier("myNewName")
new LiteralScalarResolver<string>("myNewName")
));
Assert.That(renamer, Is.Not.Null);
Assert.That(renamer, Is.TypeOf<NewNameRenamingEngine>());
Expand Down
7 changes: 4 additions & 3 deletions NBi.Testing/Unit/Xml/Systems/ResultSetSystemXmlTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NBi.Core.ResultSet;
using NBi.Core.Scalar.Resolver;
using NBi.Core.Transformation;
using NBi.Xml;
using NBi.Xml.Items;
Expand Down Expand Up @@ -259,7 +260,7 @@ public void Deserialize_SampleFile_AlterationRename()
Assert.That(rs.Alteration.Renamings, Has.Count.EqualTo(1));

Assert.That(rs.Alteration.Renamings[0].Identifier.Label, Is.EqualTo("#3"));
Assert.That(rs.Alteration.Renamings[0].NewName.Label, Is.EqualTo("[myNewName]"));
Assert.That(rs.Alteration.Renamings[0].NewName, Is.EqualTo("myNewName"));
}

[Test]
Expand Down Expand Up @@ -333,7 +334,7 @@ public void Serialize_Renaming_Correct()
Alteration = new AlterationXml()
{
Renamings = new List<RenamingXml>() { new RenamingXml()
{ Identifier= new ColumnOrdinalIdentifier(5), NewName = new ColumnNameIdentifier("myNewName") } }
{ Identifier= new ColumnOrdinalIdentifier(5), NewName = "myNewName" } }
}
};

Expand All @@ -342,7 +343,7 @@ public void Serialize_Renaming_Correct()
Console.WriteLine(xml);
Assert.That(xml, Is.StringContaining("<rename"));
Assert.That(xml, Is.StringContaining("#5"));
Assert.That(xml, Is.StringContaining("[myNewName]"));
Assert.That(xml, Is.StringContaining("myNewName"));
}

}
Expand Down
8 changes: 1 addition & 7 deletions NBi.Xml/Items/Alteration/Renaming/RenamingXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ public IColumnIdentifier Identifier
}

[XmlAttribute("new-name")]
public string NewNameSerializer { get; set; }
[XmlIgnore]
public IColumnIdentifier NewName
{
get => new ColumnIdentifierFactory().Instantiate(NewNameSerializer);
set => NewNameSerializer = value.Label;
}
public string NewName { get; set; }
}
}

0 comments on commit be5deb9

Please sign in to comment.