Best NBi code snippet using NBi.Core.ResultSet.Alteration.Projection.ProjectEngine.ProjectEngine
ProjectEngineTest.cs
Source:ProjectEngineTest.cs
...7using System.Text;8using System.Threading.Tasks;9namespace NBi.Testing.Core.ResultSet.Alteration.Projection10{11 public class ProjectEngineTest12 {13 [TestCase("#0")]14 [TestCase("Foo")]15 [Test]16 public void Execute_Identifier_ColumnFilterped(string identifier)17 {18 var rs = new NBi.Core.ResultSet.ResultSet();19 rs.Load("a;1;120");20 rs.Columns[0].ColumnName = "Foo";21 rs.Columns[1].ColumnName = "Col1";22 rs.Columns[2].ColumnName = "Col2";23 var factory = new ColumnIdentifierFactory();24 var id = factory.Instantiate(identifier);25 var filter = new ProjectEngine(new ProjectArgs(new[] { id }));26 filter.Execute(rs);27 Assert.That(rs.Columns.Count, Is.EqualTo(1));28 Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Foo"));29 }30 [TestCase("#0", "#2")]31 [TestCase("Foo", "Bar")]32 [Test]33 public void Execute_MultipleIdentifiers_ColumnFilterped(string id1, string id2)34 {35 var rs = new NBi.Core.ResultSet.ResultSet();36 rs.Load("a;1;120");37 rs.Columns[0].ColumnName = "Foo";38 rs.Columns[1].ColumnName = "Col1";39 rs.Columns[2].ColumnName = "Bar";40 var factory = new ColumnIdentifierFactory();41 var filter = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) }));42 filter.Execute(rs);43 Assert.That(rs.Columns.Count, Is.EqualTo(2));44 Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Foo"));45 Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Bar"));46 }47 [TestCase("#2", "#0")]48 [TestCase("Bar", "Foo")]49 [Test]50 public void Execute_MultipleIdentifiersNotSameOrder_ColumnFilteredOrderChanged(string id1, string id2)51 {52 var rs = new NBi.Core.ResultSet.ResultSet();53 rs.Load("a;1;120");54 rs.Columns[0].ColumnName = "Foo";55 rs.Columns[1].ColumnName = "Col1";56 rs.Columns[2].ColumnName = "Bar";57 var factory = new ColumnIdentifierFactory();58 var project = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) }));59 project.Execute(rs);60 Assert.That(rs.Columns.Count, Is.EqualTo(2));61 Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Bar"));62 Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Foo"));63 }64 [TestCase("#0", "#0")]65 [TestCase("Foo", "Foo")]66 [TestCase("Foo", "#0")]67 [Test]68 public void Execute_DuplicatedIdentifiers_ColumnFilterped(string id1, string id2)69 {70 var rs = new NBi.Core.ResultSet.ResultSet();71 rs.Load("a;1;120");72 rs.Columns[0].ColumnName = "Foo";73 rs.Columns[1].ColumnName = "Col1";74 rs.Columns[2].ColumnName = "Col2";75 var factory = new ColumnIdentifierFactory();76 var filter = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id1), factory.Instantiate(id2) }));77 filter.Execute(rs);78 Assert.That(rs.Columns.Count, Is.EqualTo(1));79 }80 [TestCase("#1", "#1")]81 [TestCase("Foo", "Foo")]82 [TestCase("Foo", "#1")]83 [TestCase("#1", "Bar")]84 [Test]85 public void Execute_DuplicatedIdentifiersAndChangeOrder_ColumnFilteredOrderedChanged(string id1, string id2)86 {87 var rs = new NBi.Core.ResultSet.ResultSet();88 rs.Load("a;1;120");89 rs.Columns[0].ColumnName = "Col1";90 rs.Columns[1].ColumnName = "Foo";91 rs.Columns[2].ColumnName = "Bar";92 var factory = new ColumnIdentifierFactory();93 var filter = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate("#2"), factory.Instantiate(id1), factory.Instantiate(id2) }));94 filter.Execute(rs);95 Assert.That(rs.Columns.Count, Is.EqualTo(2));96 Assert.That(rs.Columns[0].ColumnName, Is.EqualTo("Bar"));97 Assert.That(rs.Columns[1].ColumnName, Is.EqualTo("Foo"));98 }99 [TestCase("#999")]100 [TestCase("Bar")]101 [Test]102 public void Execute_NonExistingIdentifiers_ColumnFilterped(string id)103 {104 var rs = new NBi.Core.ResultSet.ResultSet();105 rs.Load("a;1;120");106 rs.Columns[0].ColumnName = "Foo";107 rs.Columns[1].ColumnName = "Col1";108 rs.Columns[2].ColumnName = "Col2";109 var factory = new ColumnIdentifierFactory();110 var filter = new ProjectEngine(new ProjectArgs(new[] { factory.Instantiate(id) }));111 filter.Execute(rs);112 Assert.That(rs.Columns.Count, Is.EqualTo(0));113 }114 }115}...
ProjectEngine.cs
Source:ProjectEngine.cs
...6using System.Text;7using System.Threading.Tasks;8namespace NBi.Core.ResultSet.Alteration.Projection9{10 class ProjectEngine : IProjectionEngine11 {12 public IEnumerable<IColumnIdentifier> Identifiers { get; }13 public ProjectEngine(ProjectArgs args)14 => Identifiers = args.Identifiers;15 public IResultSet Execute(IResultSet resultSet)16 {17 var columns = new List<DataColumn>();18 foreach (var identifier in Identifiers)19 {20 switch (identifier)21 {22 case ColumnOrdinalIdentifier id:23 if (id.Ordinal < resultSet.Columns.Count)24 columns.Add(resultSet.Columns[id.Ordinal]);25 break;26 case ColumnNameIdentifier id:27 if (resultSet.Columns.Contains(id.Name))...
ProjectAwayEngine.cs
Source:ProjectAwayEngine.cs
...6using System.Text;7using System.Threading.Tasks;8namespace NBi.Core.ResultSet.Alteration.Projection9{10 class ProjectAwayEngine : ProjectEngine11 {12 public ProjectAwayEngine(ProjectAwayArgs args)13 : base(args) { }14 protected override bool IsColumnToRemove(DataColumn dataColumn, IEnumerable<DataColumn> columns)15 => columns.Contains(dataColumn);16 }17}...
ProjectEngine
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Projection;7{8 {9 static void Main(string[] args)10 {11 var engine = new ProjectEngine();12 var result = engine.Execute(new string[] { "1", "2", "3" }, new int[] { 1, 2 });13 foreach(var item in result)14 {15 Console.WriteLine(item);16 }17 Console.ReadLine();18 }19 }20}21using System;22using System.Collections.Generic;23using System.Linq;24using System.Text;25using System.Threading.Tasks;26using NBi.Core.ResultSet.Alteration.Projection;27{28 {29 static void Main(string[] args)30 {31 var engine = new ProjectEngine();32 var result = engine.Execute(new string[] { "1", "2", "3" }, new int[] { 2, 1 });33 foreach (var item in result)34 {35 Console.WriteLine(item);36 }37 Console.ReadLine();38 }39 }40}41using System;42using System.Collections.Generic;43using System.Linq;44using System.Text;45using System.Threading.Tasks;46using NBi.Core.ResultSet.Alteration.Projection;47{48 {49 static void Main(string[] args)50 {51 var engine = new ProjectEngine();52 var result = engine.Execute(new string[] { "1", "2", "3" }, new int[] { 2, 1, 0 });53 foreach (var item in result)54 {55 Console.WriteLine(item);56 }57 Console.ReadLine();58 }59 }60}61using System;62using System.Collections.Generic;63using System.Linq;64using System.Text;65using System.Threading.Tasks;66using NBi.Core.ResultSet.Alteration.Projection;67{68 {69 static void Main(string[] args)70 {71 var engine = new ProjectEngine();72 var result = engine.Execute(new string[] { "1", "2", "3" }, new int[] { 0, 1, 2 });73 foreach (var item in result)74 {
ProjectEngine
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Projection;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Resolver;9{10 {11 static void Main(string[] args)12 {13 var rs = new ResultSet();14 rs.Load(NBi.Core.Calculation.Predicate.RowPositionType.First, new[] { "A", "B", "C" });15 rs.Rows.Add(new object[] { "1", "2", "3" });16 rs.Rows.Add(new object[] { "4", "5", "6" });17 rs.Rows.Add(new object[] { "7", "8", "9" });18 var engine = new ProjectEngine();19 var result = engine.Execute(rs, new[] { "A" });20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using NBi.Core.ResultSet.Alteration.Projection;29using NBi.Core.ResultSet;30using NBi.Core.ResultSet.Resolver;31{32 {33 static void Main(string[] args)34 {35 var rs = new ResultSet();36 rs.Load(NBi.Core.Calculation.Predicate.RowPositionType.First, new[] { "A", "B", "C" });37 rs.Rows.Add(new object[] { "1", "2", "3" });38 rs.Rows.Add(new object[] { "4", "5", "6" });39 rs.Rows.Add(new object[] { "7", "8", "9" });40 var engine = new ProjectEngine();41 var result = engine.Execute(rs, new[] { "B" });42 }43 }44}45using System;46using System.Collections.Generic;47using System.Linq;48using System.Text;49using System.Threading.Tasks;50using NBi.Core.ResultSet.Alteration.Projection;51using NBi.Core.ResultSet;52using NBi.Core.ResultSet.Resolver;53{54 {55 static void Main(string[] args)56 {57 var rs = new ResultSet();
ProjectEngine
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using NBi.Core.ResultSet.Alteration.Projection;6using NBi.Core.ResultSet;7using NBi.Core.Calculation;8{9 {10 static void Main(string[] args)11 {12 var engine = new ProjectEngine();13 var rs = new ResultSet();14 rs.Columns.Add(new Column("col1"));15 rs.Columns.Add(new Column("col2"));16 rs.Columns.Add(new Column("col3"));17 rs.Rows.Add(new List<object>() { 1, 2, 3 });18 rs.Rows.Add(new List<object>() { 4, 5, 6 });19 rs.Rows.Add(new List<object>() { 7, 8, 9 });20 var projection = new ProjectOn(new ColumnOrdinalIdentifier(0));21 var result = engine.Execute(rs, projection);22 foreach (var row in result.Rows)23 {24 foreach (var item in row)25 Console.Write(item + " ");26 Console.WriteLine();27 }28 Console.ReadLine();29 }30 }31}
ProjectEngine
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet;7using NBi.Core.ResultSet.Alteration.Projection;8using NBi.Core.Calculation;9{10 {11 static void Main(string[] args)12 {13 ResultSet rs = new ResultSet();14 rs.Columns.Add(new Column("Id"));15 rs.Columns.Add(new Column("Name"));16 rs.Rows.Add(new Row(new[] { "1", "John" }));17 rs.Rows.Add(new Row(new[] { "2", "Mary" }));18 rs.Rows.Add(new Row(new[] { "3", "Jane" }));19 rs.Rows.Add(new Row(new[] { "4", "Jack" }));20 var projection = new ProjectEngine();21 var newColumn = new Column("NewColumn");22 var newColumnExpression = new ColumnExpression();23 newColumnExpression.Expression = "Id + 2";24 newColumn.Expressions.Add(newColumnExpression);25 projection.Columns.Add(newColumn);26 var projectedResultSet = projection.Execute(rs);27 foreach (var row in projectedResultSet.Rows)28 {29 Console.WriteLine(row[0] + " " + row[1] + " " + row[2]);30 }31 Console.ReadLine();32 }33 }34}
ProjectEngine
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Projection;7using NBi.Core.ResultSet;8using NBi.Core.Calculation;9{10 {11 static void Main(string[] args)12 {13 ResultSet rs = new ResultSet();14 rs.LoadXml(@"<ResultSet>15 </ResultSet>");16 var projection = new ProjectEngine(new ColumnIdentifier("Column1"));17 var rsProjected = projection.Execute(rs);18 Console.WriteLine(rsProjected.GetXml());19 Console.ReadLine();20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using NBi.Core.ResultSet.Alteration.Projection;29using NBi.Core.ResultSet;30using NBi.Core.Calculation;31{32 {33 static void Main(string[] args)34 {35 ResultSet rs = new ResultSet();36 rs.LoadXml(@"<ResultSet>
ProjectEngine
Using AI Code Generation
1using NBi.Core.ResultSet.Alteration.Projection;2using System.Data;3using System.Linq;4using System;5using System.Collections.Generic;6using System.Text;7{8 {9 static void Main(string[] args)10 {11 DataTable dt = new DataTable();12 dt.Columns.Add("Column1", typeof(string));13 dt.Columns.Add("Column2", typeof(string));14 dt.Columns.Add("Column3", typeof(string));15 dt.Columns.Add("Column4", typeof(string));16 dt.Columns.Add("Column5", typeof(string));17 dt.Columns.Add("Column6", typeof(string));18 dt.Columns.Add("Column7", typeof(string));19 dt.Columns.Add("Column8", typeof(string));20 dt.Columns.Add("Column9", typeof(string));21 dt.Columns.Add("Column10", typeof(string));22 dt.Columns.Add("Column11", typeof(string));23 dt.Columns.Add("Column12", typeof(string));24 dt.Columns.Add("Column13", typeof(string));25 dt.Columns.Add("Column14", typeof(string));26 dt.Columns.Add("Column15", typeof(string));27 dt.Columns.Add("Column16", typeof(string));28 dt.Columns.Add("Column17", typeof(string));29 dt.Columns.Add("Column18", typeof(string));30 dt.Columns.Add("Column19", typeof(string));31 dt.Columns.Add("Column20", typeof(string));32 dt.Columns.Add("Column21", typeof(string));33 dt.Columns.Add("Column22", typeof(string));34 dt.Columns.Add("Column23", typeof(string));35 dt.Columns.Add("Column24", typeof(string));36 dt.Columns.Add("Column25", typeof(string));37 dt.Columns.Add("Column26", typeof(string));38 dt.Columns.Add("Column27", typeof(string));39 dt.Columns.Add("Column28", typeof(string));40 dt.Columns.Add("Column29", typeof(string));41 dt.Columns.Add("Column30", typeof(string));42 dt.Columns.Add("Column31", typeof(string));43 dt.Columns.Add("Column32", typeof(string));44 dt.Columns.Add("Column33", typeof(string));45 dt.Columns.Add("Column34", typeof(string));46 dt.Columns.Add("Column35", typeof(string));47 dt.Columns.Add("Column36", typeof(string));48 dt.Columns.Add("Column37", typeof(string));49 dt.Columns.Add("Column38", typeof(string));50 dt.Columns.Add("Column39", typeof(string));51 dt.Columns.Add("Column40", typeof(string));
ProjectEngine
Using AI Code Generation
1using System;2using System.Linq;3using System.Collections.Generic;4using NBi.Core.ResultSet;5using NBi.Core.ResultSet.Alteration.Projection;6using NBi.Core.ResultSet.Alteration.Projection.Strategy;7using NBi.Core.ResultSet.Alteration.Projection.Hierarchy;8using NBi.Core.Calculation;9using NBi.Core.Calculation.Ranking;10using NBi.Core.Calculation.Ranking.Strategy;11using NBi.Core.Calculation.Ranking.Profiler;12using NBi.Core.Calculation.Ranking.Profiler.Numerical;13using NBi.Core.Calculation.Ranking.Profiler.Textual;14{15 {16 static void Main(string[] args)17 {18 var rs = new ResultSet();19 rs.Columns.Add(new Column("Column1"));20 rs.Columns.Add(new Column("Column2"));21 rs.Columns.Add(new Column("Column3"));22 rs.Columns.Add(new Column("Column4"));23 rs.Columns.Add(new Column("Column5"));24 rs.Columns.Add(new Column("Column6"));25 rs.Rows.Add(new Row(new List<object> { 1, "a", 1, "a", 1, "a" }));26 rs.Rows.Add(new Row(new List<object> { 2, "b", 2, "b", 2, "b" }));27 rs.Rows.Add(new Row(new List<object> { 3, "c", 3, "c", 3, "c" }));28 rs.Rows.Add(new Row(new List<object> { 4, "d", 4, "d", 4, "d" }));29 rs.Rows.Add(new Row(new List<object> { 5, "e", 5, "e", 5, "e" }));30 rs.Rows.Add(new Row(new List<object> { 6, "f", 6, "f", 6, "f" }));31 rs.Rows.Add(new Row(new List<object> { 7, "g", 7, "g", 7, "g" }));32 rs.Rows.Add(new Row(new List<object> { 8, "h", 8, "h", 8, "h" }));33 rs.Rows.Add(new Row(new List<object> { 9, "i", 9, "i",
ProjectEngine
Using AI Code Generation
1using System;2using System.Data;3using System.IO;4using NBi.Core.ResultSet.Alteration.Projection;5using NBi.Core.ResultSet;6using System.Collections.Generic;7{8 {9 private readonly IList<string> columns;10 public ProjectEngine(IList<string> columns)11 {12 this.columns = columns;13 }14 public DataTable Execute(DataTable dt)15 {16 var projected = new DataTable();17 foreach (var column in columns)18 {19 if (!dt.Columns.Contains(column))20 throw new ArgumentException($"The column '{column}' doesn't exist in the result-set.");21 projected.Columns.Add(column, dt.Columns[column].DataType);22 }23 foreach (DataRow row in dt.Rows)24 {25 var newRow = projected.NewRow();26 foreach (var column in columns)27 newRow[column] = row[column];28 projected.Rows.Add(newRow);29 }30 return projected;31 }32 }33}34using System;35using System.Data;36using System.IO;37using NBi.Core.ResultSet.Alteration.Projection;38using NBi.Core.ResultSet;39using System.Collections.Generic;40{41 {42 private readonly IList<string> columns;43 public ProjectEngine(IList<string> columns)44 {45 this.columns = columns;46 }47 public DataTable Execute(DataTable dt)48 {49 var projected = new DataTable();50 foreach (var column in columns)51 {52 if (!dt.Columns.Contains(column))53 throw new ArgumentException($"The column '{column}' doesn't exist in the result-set.");54 projected.Columns.Add(column, dt.Columns[column].DataType);55 }56 foreach (DataRow row in dt.Rows)57 {58 var newRow = projected.NewRow();59 foreach (var column in columns)60 newRow[column] = row[column];61 projected.Rows.Add(newRow);62 }63 return projected;64 }65 }66}67using System;68using System.Data;69using System.IO;70using NBi.Core.ResultSet.Alteration.Projection;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!