Best NBi code snippet using NBi.GenbiL.Action.Case.SplitCaseAction.Execute
FilterDistinctCaseActionTest.cs
Source:FilterDistinctCaseActionTest.cs
...17 var action = new FilterDistinctCaseAction();18 Assert.That(action.Display, Is.EqualTo("Filtering distinct cases."));19 }20 [Test]21 public void Execute_OneRowDuplicated_OnlyOneRemains()22 {23 var state = new GenerationState();24 state.CaseCollection.CurrentScope.Content.Columns.Add("firstColumn");25 state.CaseCollection.CurrentScope.Content.Columns.Add("secondColumn");26 var firstRow = state.CaseCollection.CurrentScope.Content.NewRow();27 firstRow[0] = "firstCell1";28 firstRow[1] = "secondCell1";29 state.CaseCollection.CurrentScope.Content.Rows.Add(firstRow);30 var secondRow = state.CaseCollection.CurrentScope.Content.NewRow();31 secondRow[0] = "firstCell1";32 secondRow[1] = "secondCell1";33 state.CaseCollection.CurrentScope.Content.Rows.Add(secondRow);34 var action = new FilterDistinctCaseAction();35 action.Execute(state);36 Assert.That(state.CaseCollection.CurrentScope.Content.Columns, Has.Count.EqualTo(2));37 Assert.That(state.CaseCollection.CurrentScope.Content.Rows, Has.Count.EqualTo(1));38 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[0], Is.EqualTo("firstCell1"));39 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[1], Is.EqualTo("secondCell1"));40 }41 [Test]42 public void Execute_TwoRowsDuplicatedContainingAnArray_OnlyOneRemains()43 {44 var state = new GenerationState();45 state.CaseCollection.CurrentScope.Content.Columns.Add("firstColumn");46 state.CaseCollection.CurrentScope.Content.Columns.Add("secondColumn", typeof(object));47 var firstRow = state.CaseCollection.CurrentScope.Content.NewRow();48 firstRow[0] = "firstCell1";49 firstRow[1] = "foo/bar";50 state.CaseCollection.CurrentScope.Content.Rows.Add(firstRow);51 var secondRow = state.CaseCollection.CurrentScope.Content.NewRow();52 secondRow[0] = "firstCell1";53 secondRow[1] = "foo/bar";54 state.CaseCollection.CurrentScope.Content.Rows.Add(secondRow);55 var splitAction = new SplitCaseAction(new[] { "secondColumn" }, "/");56 splitAction.Execute(state);57 var action = new FilterDistinctCaseAction();58 action.Execute(state);59 Assert.That(state.CaseCollection.CurrentScope.Content.Columns, Has.Count.EqualTo(2));60 Assert.That(state.CaseCollection.CurrentScope.Content.Rows, Has.Count.EqualTo(1));61 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[0], Is.EqualTo("firstCell1"));62 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[1], Has.Member("foo"));63 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[1], Has.Member("bar"));64 }65 public void Execute_TwoRowsDuplicatedContainingAnArrayWithDifference_TwoRowsRemain()66 {67 var state = new GenerationState();68 state.CaseCollection.CurrentScope.Content.Columns.Add("firstColumn", typeof(object));69 state.CaseCollection.CurrentScope.Content.Columns.Add("secondColumn", typeof(object));70 var firstRow = state.CaseCollection.CurrentScope.Content.NewRow();71 firstRow[0] = "firstCell1";72 firstRow[1] = "foo/bar";73 state.CaseCollection.CurrentScope.Content.Rows.Add(firstRow);74 var secondRow = state.CaseCollection.CurrentScope.Content.NewRow();75 secondRow[0] = "firstCell1";76 secondRow[1] = "foo/bar/x";77 state.CaseCollection.CurrentScope.Content.Rows.Add(secondRow);78 var splitAction = new SplitCaseAction(new[] { "secondColumn" }, "/");79 splitAction.Execute(state);80 var action = new FilterDistinctCaseAction();81 action.Execute(state);82 Assert.That(state.CaseCollection.CurrentScope.Content.Columns, Has.Count.EqualTo(2));83 Assert.That(state.CaseCollection.CurrentScope.Content.Rows, Has.Count.EqualTo(2));84 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[0], Is.EqualTo("firstCell1"));85 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[1], Has.Member("foo"));86 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0].ItemArray[1], Has.Member("bar"));87 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[1].ItemArray[1], Has.Member("x"));88 }89 }90}...
SplitCaseActionTest.cs
Source:SplitCaseActionTest.cs
...13{14 public class SplitCaseActionTest15 {16 [Test]17 public void Execute_OneColumnToSplit_Correct()18 {19 var state = new GenerationState();20 state.CaseCollection.CurrentScope.Content.Columns.Add("initialColumn");21 state.CaseCollection.CurrentScope.Content.Columns.Add("otherColumn");22 var firstRow = state.CaseCollection.CurrentScope.Content.NewRow();23 firstRow[0] = "a-b-c";24 firstRow[1] = "other";25 state.CaseCollection.CurrentScope.Content.Rows.Add(firstRow);26 var secondRow = state.CaseCollection.CurrentScope.Content.NewRow();27 secondRow[0] = "a-b";28 secondRow[1] = "other";29 state.CaseCollection.CurrentScope.Content.Rows.Add(secondRow);30 var thirdRow = state.CaseCollection.CurrentScope.Content.NewRow();31 thirdRow[0] = "a-b-c-d";32 thirdRow[1] = "(none)";33 state.CaseCollection.CurrentScope.Content.Rows.Add(thirdRow);34 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0]["initialColumn"], Is.TypeOf<string>());35 var columns = new string[] { "initialColumn" };36 var action = new SplitCaseAction(columns, "-");37 action.Execute(state);38 var dataTable = state.CaseCollection.CurrentScope.Content;39 Assert.That(dataTable.Columns, Has.Count.EqualTo(2));40 Assert.That(dataTable.Rows, Has.Count.EqualTo(3));41 Assert.That(dataTable.Rows[0]["otherColumn"], Is.TypeOf<string>());42 Assert.That(dataTable.Rows[0]["initialColumn"], Is.TypeOf<string[]>());43 44 Assert.That((dataTable.Rows[0]["initialColumn"] as Array).Length, Is.EqualTo(3));45 Assert.That((dataTable.Rows[1]["initialColumn"] as Array).Length, Is.EqualTo(2));46 Assert.That((dataTable.Rows[2]["initialColumn"] as Array).Length, Is.EqualTo(4));47 }48 [Test]49 public void Execute_TwoColumnsToSplit_Correct()50 {51 var state = new GenerationState();52 state.CaseCollection.CurrentScope.Content.Columns.Add("initialColumn");53 state.CaseCollection.CurrentScope.Content.Columns.Add("otherColumn");54 state.CaseCollection.CurrentScope.Content.Columns.Add("thirdColumn");55 var firstRow = state.CaseCollection.CurrentScope.Content.NewRow();56 firstRow[0] = "a-b-c";57 firstRow[1] = "other";58 firstRow[2] = "1-2";59 state.CaseCollection.CurrentScope.Content.Rows.Add(firstRow);60 var secondRow = state.CaseCollection.CurrentScope.Content.NewRow();61 secondRow[0] = "a-b";62 secondRow[1] = "other";63 secondRow[2] = "3-4";64 state.CaseCollection.CurrentScope.Content.Rows.Add(secondRow);65 var thirdRow = state.CaseCollection.CurrentScope.Content.NewRow();66 thirdRow[0] = "a-b-c-d";67 thirdRow[1] = "(none)";68 thirdRow[2] = "5-6-7-8";69 state.CaseCollection.CurrentScope.Content.Rows.Add(thirdRow);70 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0]["initialColumn"], Is.TypeOf<string>());71 Assert.That(state.CaseCollection.CurrentScope.Content.Rows[0]["thirdColumn"], Is.TypeOf<string>());72 var columns = new string[] { "initialColumn", "thirdColumn" };73 var action = new SplitCaseAction(columns, "-");74 action.Execute(state);75 var dataTable = state.CaseCollection.CurrentScope.Content;76 Assert.That(dataTable.Columns, Has.Count.EqualTo(3));77 Assert.That(dataTable.Rows, Has.Count.EqualTo(3));78 Assert.That(dataTable.Rows[0]["otherColumn"], Is.TypeOf<string>());79 Assert.That(dataTable.Rows[0]["initialColumn"], Is.TypeOf<string[]>());80 Assert.That(dataTable.Rows[0]["thirdColumn"], Is.TypeOf<string[]>());81 Assert.That((dataTable.Rows[0]["initialColumn"] as Array).Length, Is.EqualTo(3));82 Assert.That((dataTable.Rows[1]["initialColumn"] as Array).Length, Is.EqualTo(2));83 Assert.That((dataTable.Rows[2]["initialColumn"] as Array).Length, Is.EqualTo(4));84 Assert.That((dataTable.Rows[0]["thirdColumn"] as Array).Length, Is.EqualTo(2));85 Assert.That((dataTable.Rows[1]["thirdColumn"] as Array).Length, Is.EqualTo(2));86 Assert.That((dataTable.Rows[2]["thirdColumn"] as Array).Length, Is.EqualTo(4));87 }88 }...
SplitCaseAction.cs
Source:SplitCaseAction.cs
...15 {16 Columns = columns;17 Separator = separator;18 }19 public void Execute(GenerationState state) => Execute(state.CaseCollection.CurrentScope);20 public void Execute(CaseSet testCases)21 {22 var dataTable = testCases.Content;23 foreach (var columnName in Columns)24 {25 if (!testCases.Variables.Contains(columnName))26 throw new ArgumentOutOfRangeException(String.Format("No column named '{0}' has been found.", columnName));27 dataTable.Columns.Add("_" + columnName, typeof(string[]));28 var columnListId = dataTable.Columns["_" + columnName].Ordinal;29 var columnId = dataTable.Columns[columnName].Ordinal;30 for (int i = 0; i < dataTable.Rows.Count; i++)31 {32 if (dataTable.Rows[i][columnId] is IEnumerable<string>)33 throw new ArgumentOutOfRangeException(String.Format("The column named '{0}' was already an array.", columnName));34 var array = dataTable.Rows[i][columnId].ToString().Split(new[] { Separator }, StringSplitOptions.None);...
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!!