Best NBi code snippet using NBi.Core.ResultSet.Alteration.Reshaping.UnstackEngine
UnstackEngineTest.cs
Source:UnstackEngineTest.cs
...12using System.Data;13using System.Diagnostics;14namespace NBi.Testing.Core.ResultSet.Alteration.Reshaping15{16 public class UnstackEngineTest17 {18 [Test]19 public void Execute_SingleKeySingleValue_ExpectedResultSet()20 {21 var resolver = new ObjectsResultSetResolver(22 new ObjectsResultSetResolverArgs(23 new[] {24 new object[] { "alpha", "A", 1 },25 new object[] { "alpha", "B", 2 },26 new object[] { "beta", "A", 3 },27 new object[] { "beta", "B", 4 }28 }29 ));30 var rs = resolver.Execute();31 rs.Columns[0].ColumnName = "keyColumn";32 rs.Columns[1].ColumnName = "headerColumn";33 rs.Columns[2].ColumnName = "valueColumn";34 var args = new UnstackArgs(35 new ColumnNameIdentifier("headerColumn"),36 new List<IColumnDefinitionLight>()37 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }38 );39 var unstack = new UnstackEngine(args);40 var result = unstack.Execute(rs);41 Assert.That(result, Is.Not.Null);42 Assert.That(result.Columns.Count, Is.EqualTo(3));43 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));44 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));45 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));46 Assert.That(result.Rows.Count, Is.EqualTo(2));47 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A"]) == 1);48 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B"]) == 2);49 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["A"]) == 3);50 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["B"]) == 4);51 }52 [Test]53 public void Execute_SingleKeyMultipleValue_ExpectedResultSet()54 {55 var resolver = new ObjectsResultSetResolver(56 new ObjectsResultSetResolverArgs(57 new[] {58 new object[] { "alpha", "A", 1, -1 },59 new object[] { "alpha", "B", 2, -2 },60 new object[] { "beta", "A", 3, -3 },61 new object[] { "beta", "B", 4, -4 }62 }63 ));64 var rs = resolver.Execute();65 rs.Columns[0].ColumnName = "keyColumn";66 rs.Columns[1].ColumnName = "headerColumn";67 rs.Columns[2].ColumnName = "value1Column";68 rs.Columns[3].ColumnName = "value2Column";69 var args = new UnstackArgs(70 new ColumnNameIdentifier("headerColumn"),71 new List<IColumnDefinitionLight>()72 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }73 );74 var unstack = new UnstackEngine(args);75 var result = unstack.Execute(rs);76 Assert.That(result, Is.Not.Null);77 Assert.That(result.Columns.Count, Is.EqualTo(5));78 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));79 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A_value1Column"));80 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B_value1Column"));81 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A_value2Column"));82 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B_value2Column"));83 Assert.That(result.Rows.Count, Is.EqualTo(2));84 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A_value1Column"]) == 1);85 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B_value1Column"]) == 2);86 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["A_value1Column"]) == 3);87 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["B_value1Column"]) == 4);88 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A_value2Column"]) == -1);89 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B_value2Column"]) == -2);90 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["A_value2Column"]) == -3);91 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["B_value2Column"]) == -4);92 }93 [Test]94 public void Execute_MultipleKeysSingleValue_ExpectedResultSet()95 {96 var resolver = new ObjectsResultSetResolver(97 new ObjectsResultSetResolverArgs(98 new[] {99 new object[] { "alpha", "one", "A", 1 },100 new object[] { "alpha", "one", "B", 2 },101 new object[] { "beta", "one", "A", 3 },102 new object[] { "beta", "one", "B", 4 },103 new object[] { "beta", "two", "B", -4 }104 }105 ));106 var rs = resolver.Execute();107 rs.Columns[0].ColumnName = "key1Column";108 rs.Columns[1].ColumnName = "key2Column";109 rs.Columns[2].ColumnName = "headerColumn";110 rs.Columns[3].ColumnName = "valueColumn";111 var args = new UnstackArgs(112 new ColumnNameIdentifier("headerColumn"),113 new List<IColumnDefinitionLight>()114 {115 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("key1Column") && x.Type == ColumnType.Text),116 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("key2Column") && x.Type == ColumnType.Text),117 }118 );119 var unstack = new UnstackEngine(args);120 var result = unstack.Execute(rs);121 Assert.That(result, Is.Not.Null);122 Assert.That(result.Columns.Count, Is.EqualTo(4));123 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "key1Column"));124 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "key2Column"));125 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));126 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));127 Assert.That(result.Rows.Count, Is.EqualTo(3));128 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "alpha" && x["key2Column"] as string == "one")["A"]) == 1);129 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "alpha" && x["key2Column"] as string == "one")["B"]) == 2);130 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "one")["A"]) == 3);131 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "one")["B"]) == 4);132 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "two")["B"]) == -4);133 Assert.That(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "two")["A"] == DBNull.Value);134 }135 [Test]136 public void Execute_EnforcedColumnsThatWasNotExpected_ExpectedResultSet()137 {138 var resolver = new ObjectsResultSetResolver(139 new ObjectsResultSetResolverArgs(140 new[] {141 new object[] { "alpha", "A", 1 },142 new object[] { "alpha", "B", 2 },143 new object[] { "beta", "A", 3 },144 new object[] { "beta", "B", 4 }145 }146 ));147 var rs = resolver.Execute();148 rs.Columns[0].ColumnName = "keyColumn";149 rs.Columns[1].ColumnName = "headerColumn";150 rs.Columns[2].ColumnName = "valueColumn";151 var args = new UnstackArgs(152 new ColumnNameIdentifier("headerColumn"),153 new List<IColumnDefinitionLight>()154 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) },155 new List<ColumnNameIdentifier>() { new ColumnNameIdentifier("C") }156 );157 var unstack = new UnstackEngine(args);158 var result = unstack.Execute(rs);159 Assert.That(result, Is.Not.Null);160 Assert.That(result.Columns.Count, Is.EqualTo(4));161 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));162 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));163 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));164 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "C"));165 Assert.That(result.Rows.Count, Is.EqualTo(2));166 Assert.That(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["C"] == DBNull.Value);167 Assert.That(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["C"] == DBNull.Value);168 }169 [Test]170 public void Execute_EnforcedColumnsThatWasAlreadyExpected_ExpectedResultSet()171 {172 var resolver = new ObjectsResultSetResolver(173 new ObjectsResultSetResolverArgs(174 new[] {175 new object[] { "alpha", "A", 1 },176 new object[] { "alpha", "B", 2 },177 new object[] { "beta", "A", 3 },178 new object[] { "beta", "B", 4 }179 }180 ));181 var rs = resolver.Execute();182 rs.Columns[0].ColumnName = "keyColumn";183 rs.Columns[1].ColumnName = "headerColumn";184 rs.Columns[2].ColumnName = "valueColumn";185 var args = new UnstackArgs(186 new ColumnNameIdentifier("headerColumn"),187 new List<IColumnDefinitionLight>()188 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) },189 new List<ColumnNameIdentifier>() { new ColumnNameIdentifier("A"), new ColumnNameIdentifier("B") }190 );191 var unstack = new UnstackEngine(args);192 var result = unstack.Execute(rs);193 Assert.That(result, Is.Not.Null);194 Assert.That(result.Columns.Count, Is.EqualTo(3));195 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));196 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));197 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));198 Assert.That(result.Columns.Cast<DataColumn>().Count(x => x.ColumnName == "A") == 1);199 Assert.That(result.Columns.Cast<DataColumn>().Count(x => x.ColumnName == "B") == 1);200 }201 [Test]202 [TestCase(100)]203 [TestCase(1000)]204 [TestCase(10000)]205 [TestCase(40000)]206 [Retry(3)]207 [Parallelizable(ParallelScope.Self)]208 public void Execute_LargeResultSet_ExpectedPerformance(int count)209 {210 var values = new List<object>();211 for (int i = 0; i < count; i++)212 values.Add(new object[] { i % 2 == 0 ? "alpha" : "beta", (i/2) % (count/2), 1 });213 var resolver = new ObjectsResultSetResolver(new ObjectsResultSetResolverArgs(values));214 var rs = resolver.Execute();215 rs.Columns[0].ColumnName = "keyColumn";216 rs.Columns[1].ColumnName = "headerColumn";217 rs.Columns[2].ColumnName = "valueColumn";218 var args = new UnstackArgs(219 new ColumnNameIdentifier("headerColumn"),220 new List<IColumnDefinitionLight>()221 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }222 );223 var unstack = new UnstackEngine(args);224 var stopWatch = new Stopwatch();225 stopWatch.Start();226 var result = unstack.Execute(rs);227 stopWatch.Stop();228 Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(15));229 }230 }231}...
UnstackEngine.cs
Source:UnstackEngine.cs
...9using System.Text;10using System.Threading.Tasks;11namespace NBi.Core.ResultSet.Alteration.Reshaping12{13 class UnstackEngine : IReshapingEngine14 {15 private UnstackArgs Args { get; }16 public UnstackEngine(UnstackArgs args)17 => Args = args;18 public IResultSet Execute(IResultSet rs)19 {20 //Build structre of the resulting table21 var valueColumns = rs.Columns.Cast<DataColumn>().Where(22 x => x != Args.Header.GetColumn(rs.Table)23 && !Args.GroupBys.Select(y => y.Identifier.GetColumn(rs.Table)).Contains(x)24 );25 26 var headerValues = Args.EnforcedColumns.Select(x => x.Name).ToList();27 rs.Rows.Cast<DataRow>().ToList().ForEach(x => headerValues.Add(Args.Header.GetValue(x).ToString()));28 headerValues = headerValues.Distinct().ToList();29 using (var dataTable = new DataTable())30 {...
ReshapingFactory.cs
Source:ReshapingFactory.cs
...10 public IReshapingEngine Instantiate(IReshapingArgs args)11 {12 switch(args)13 {14 case UnstackArgs x: return new UnstackEngine(x);15 default: throw new ArgumentException();16 }17 }18 }19}...
UnstackEngine
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.Reshaping;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Resolver;9{10 {11 static void Main(string[] args)12 {13 var engine = new UnstackEngine();14 var resultSet = new ResultSet();15 resultSet.Columns.Add(new Column("col1", "System.String"));16 resultSet.Columns.Add(new Column("col2", "System.String"));17 resultSet.Columns.Add(new Column("col3", "System.String"));18 resultSet.Rows.Add(new Row(new object[] { "a", "b", "c" }));19 resultSet.Rows.Add(new Row(new object[] { "d", "e", "f" }));20 resultSet.Rows.Add(new Row(new object[] { "g", "h", "i" }));21 var resolver = new ResultSetResolver();22 resolver.ResultSet = resultSet;23 engine.ColumnNames = new List<string>() { "col1", "col2", "col3" };24 engine.NewColumnName = "newCol";25 engine.NewColumnPosition = 1;26 engine.NewColumnType = "System.String";27 var result = engine.Execute(resolver);28 foreach (var row in result.ResultSet.Rows)29 {30 Console.WriteLine(row[0] + " " + row[1] + " " + row[2]);31 }32 }33 }34}
UnstackEngine
Using AI Code Generation
1using NBi.Core.ResultSet.Alteration.Reshaping;2using NBi.Core.ResultSet;3using NBi.Core;4using NBi.Core.ResultSet.Resolver;5using NBi.Core.ResultSet.Resolver.Fake;6using System.Collections.Generic;7using System.Data;8using System.Linq;9using System;10using System.Collections;11using System.Collections.ObjectModel;12using System.Text.RegularExpressions;13using System.Collections.Specialized;14using System.Text;15using System.IO;16using NBi.Core.Calculation;17using NBi.Core.Calculation.Predicate;18using NBi.Core.Calculation.Grouping;19using NBi.Core.Calculation.Ranking;20using NBi.Core.ResultSet.Equivalence;21using NBi.Core.ResultSet.Lookup.Violation;22using NBi.Core.ResultSet.Comparer;23using NBi.Core.ResultSet.Filtering;24using NBi.Core.Sequence.Resolver;25using NBi.Core.Sequence.Resolver.Loop;26using NBi.Core.Sequence.Resolver.Loop.Fixed;27using NBi.Core.Sequence.Resolver.Loop.Random;28using NBi.Core.Sequence.Resolver.Loop.Sequential;29using NBi.Core.Sequence.Resolver.Loop.Time;30using NBi.Core.Sequence.Resolver.Loop.Time.Daily;31using NBi.Core.Sequence.Resolver.Loop.Time.Hourly;32using NBi.Core.Sequence.Resolver.Loop.Time.Monthly;33using NBi.Core.Sequence.Resolver.Loop.Time.Yearly;34using NBi.Core.Sequence.Resolver.Loop.Time.Weekly;35using NBi.Core.Sequence.Resolver.Loop.Time.Minutely;36using NBi.Core.Sequence.Resolver.Loop.Time.Secondly;37using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly;38using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByDay;39using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByMonth;40using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByWeek;41using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByWeekDay;42using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByWeekDayOfMonth;43using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByWeekOfMonth;44using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByYearDay;45using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByYearWeek;46using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByYearWeekDay;47using NBi.Core.Sequence.Resolver.Loop.Time.Quarterly.ByYearWeekDayOfMonth;
UnstackEngine
Using AI Code Generation
1using NBi.Core.ResultSet.Alteration.Reshaping;2var engine = new UnstackEngine();3var result = engine.Execute(ResultSet, args);4using NBi.Core.ResultSet.Alteration.Reshaping;5var engine = new UnstackEngine();6var result = engine.Execute(ResultSet, args);7using NBi.Core.ResultSet.Alteration.Reshaping;8var engine = new UnstackEngine();9var result = engine.Execute(ResultSet, args);10using NBi.Core.ResultSet.Alteration.Reshaping;11var engine = new UnstackEngine();12var result = engine.Execute(ResultSet, args);13using NBi.Core.ResultSet.Alteration.Reshaping;14var engine = new UnstackEngine();15var result = engine.Execute(ResultSet, args);16using NBi.Core.ResultSet.Alteration.Reshaping;17var engine = new UnstackEngine();18var result = engine.Execute(ResultSet, args);19using NBi.Core.ResultSet.Alteration.Reshaping;20var engine = new UnstackEngine();21var result = engine.Execute(ResultSet, args);22using NBi.Core.ResultSet.Alteration.Reshaping;23var engine = new UnstackEngine();24var result = engine.Execute(ResultSet, args);25using NBi.Core.ResultSet.Alteration.Reshaping;26var engine = new UnstackEngine();27var result = engine.Execute(ResultSet, args);
UnstackEngine
Using AI Code Generation
1using NBi.Core.ResultSet.Alteration.Reshaping;2using NBi.Core.ResultSet;3using System.Data;4UnstackEngine unstack = new UnstackEngine();5ResultSet rs = new ResultSet();6DataTable dt = new DataTable();7DataColumn dc = new DataColumn();8dt.Columns.Add("Name");9dt.Rows.Add("John");10dt.Rows.Add("Mary");11dt.Rows.Add("Peter");12dt.Columns.Add("Age");13dt.Rows.Add(20);14dt.Rows.Add(30);15dt.Rows.Add(40);16dt.Columns.Add("Salary");17dt.Rows.Add(10000);18dt.Rows.Add(20000);19dt.Rows.Add(30000);20rs.Tables.Add(dt);21UnstackArgs args = new UnstackArgs();22args.ColumnName = "Name";23args.ColumnValues = new string[] { "Age", "Salary" };24ResultSet rsUnstack = unstack.Execute(rs, args);25foreach (DataRow row in rsUnstack.Tables[0].Rows)26{27 Console.WriteLine(row["Name"].ToString() + " " + row["Age"].ToString() + " " + row["Salary"].ToString());28}29using NBi.Core.ResultSet.Alteration.Reshaping;30using NBi.Core.ResultSet;31using System.Data;
UnstackEngine
Using AI Code Generation
1var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));2var result = unstack.Execute(resultSet);3var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));4var result = unstack.Execute(resultSet);5var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));6var result = unstack.Execute(resultSet);7var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));8var result = unstack.Execute(resultSet);9var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));10var result = unstack.Execute(resultSet);11var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));12var result = unstack.Execute(resultSet);13var unstack = new UnstackEngine(new UnstackArgs(0, new[] { "1", "2" }, new[] { "3", "4" }));14var result = unstack.Execute(resultSet);
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!!