Best NBi code snippet using NBi.Core.Variable.Context.Context
ScalarResolverFactoryTest.cs
Source:ScalarResolverFactoryTest.cs
...33 var resolver = factory.Instantiate(args);34 Assert.That(resolver, Is.TypeOf<GlobalVariableScalarResolver<object>>());35 }36 [Test]37 public void Instantiate_ContextArgs_ContextResolver()38 {39 using (var dt = new DataTable())40 {41 var context = Context.None;42 context.Switch(dt.NewRow());43 var args = new ContextScalarResolverArgs(context, new ColumnOrdinalIdentifier(0));44 var factory = new ScalarResolverFactory(null);45 var resolver = factory.Instantiate(args);46 Assert.That(resolver, Is.TypeOf<ContextScalarResolver<object>>());47 }48 }49 [Test]50 public void Instantiate_QueryArgs_QueryResolver()51 {52 var args = new QueryScalarResolverArgs(new EmbeddedQueryResolverArgs("select * from table;", "connStr", null, null, new TimeSpan()));53 var factory = new ScalarResolverFactory(null);54 var resolver = factory.Instantiate(args);55 Assert.That(resolver, Is.TypeOf<QueryScalarResolver<object>>());56 }57 [Test]58 public void Instantiate_ProjectionResultSetArgs_ProjectionResultSetResolver()59 {60 var args = new RowCountResultSetScalarResolverArgs(new ResultSetResolverArgs());61 var stub = new Mock<ServiceLocator>();62 stub.Setup(x => x.GetResultSetResolverFactory()).Returns(new ResultSetResolverFactory(stub.Object));63 var factory = new ScalarResolverFactory(stub.Object);64 var resolver = factory.Instantiate(args);65 Assert.That(resolver, Is.TypeOf<ProjectionResultSetScalarResolver<object>>());66 }67 [Test]68 public void Instantiate_CSharpArgs_CSharpResolver()69 {70 var args = new CSharpScalarResolverArgs("DateTime.Now.Year");71 var factory = new ScalarResolverFactory(null);72 var resolver = factory.Instantiate(args);73 Assert.That(resolver, Is.TypeOf<CSharpScalarResolver<object>>());74 }75 [Test]76 public void Instantiate_EnvironmentArgs_EnvironmentResolver()77 {78 var args = new EnvironmentScalarResolverArgs("myVar");79 var factory = new ScalarResolverFactory(null);80 var resolver = factory.Instantiate(args);81 Assert.That(resolver, Is.TypeOf<EnvironmentScalarResolver<object>>());82 }83 [Test]84 public void Instantiate_FormatArgs_FormatResolver()85 {86 var args = new FormatScalarResolverArgs("myVar", new Dictionary<string, IVariable>());87 var factory = new ScalarResolverFactory(null);88 var resolver = factory.Instantiate<string>(args);89 Assert.That(resolver, Is.TypeOf<FormatScalarResolver>());90 }91 [Test]92 public void InstantiateNeutral_FormatArgs_FormatResolver()93 {94 var args = new FormatScalarResolverArgs("myVar", new Dictionary<string, IVariable>());95 var factory = new ScalarResolverFactory(null);96 var resolver = factory.Instantiate(args);97 Assert.That(resolver, Is.TypeOf<FormatScalarResolver>());98 }99 [Test]100 public void InstantiateNotString_FormatArgs_FormatResolver()101 {102 var args = new FormatScalarResolverArgs("myVar", new Dictionary<string, IVariable>());103 var factory = new ScalarResolverFactory(null);104 var ex = Assert.Throws<ArgumentException>(() => factory.Instantiate<object>(args));105 }106 [Test]107 public void Instantiate_FunctionArgs_FunctionResolver()108 {109 var args = new FunctionScalarResolverArgs(new LiteralScalarResolver<string>("myVar"), new INativeTransformation[] { });110 var factory = new ScalarResolverFactory(null);111 var resolver = factory.Instantiate(args);112 Assert.That(resolver, Is.TypeOf<FunctionScalarResolver<object>>());113 }114 [Test]115 public void Instantiate_NCalcArgs_NcalcResolver()116 {117 var context = new Context(null);118 var args = new NCalcScalarResolverArgs("a * b - 2", context);119 var factory = new ScalarResolverFactory(null);120 var resolver = factory.Instantiate(args);121 Assert.That(resolver, Is.TypeOf<NCalcScalarResolver<object>>());122 }123 }124}...
RowValueExtractor.cs
Source:RowValueExtractor.cs
...17 {18 private ServiceLocator ServiceLocator { get; }19 public RowValueExtractor(ServiceLocator serviceLocator)20 => (ServiceLocator) = (serviceLocator);21 public object Execute(Context context, IColumnIdentifier identifier)22 {23 if (identifier is ColumnOrdinalIdentifier)24 {25 var ordinal = (identifier as ColumnOrdinalIdentifier).Ordinal;26 if (ordinal <= context.CurrentRow.Table.Columns.Count)27 return context.CurrentRow.ItemArray[ordinal];28 else29 throw new ArgumentException($"The variable of the predicate is identified as '{identifier.Label}' but the column in position '{ordinal}' doesn't exist. The dataset only contains {context.CurrentRow.Table.Columns.Count} columns.");30 }31 var name = (identifier as ColumnNameIdentifier).Name;32 var alias = context.Aliases?.SingleOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));33 if (alias != null)34 return context.CurrentRow.ItemArray[alias.Column];35 var expression = context.Expressions?.SingleOrDefault(x => string.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));36 if (expression != null)37 {38 var result = EvaluateExpression(expression, context);39 var expColumnName = $"exp::{name}";40 if (!context.CurrentRow.Table.Columns.Contains(expColumnName))41 {42 var newColumn = new DataColumn(expColumnName, typeof(object));43 context.CurrentRow.Table.Columns.Add(newColumn);44 }45 context.CurrentRow[expColumnName] = result;46 return result;47 }48 var column = context.CurrentRow.Table.Columns.Cast<DataColumn>().SingleOrDefault(x => string.Equals(x.ColumnName, name, StringComparison.OrdinalIgnoreCase));49 if (column != null)50 return context.CurrentRow[column.ColumnName];51 var existingNames = context.CurrentRow.Table.Columns.Cast<DataColumn>().Select(x => x.ColumnName)52 .Union(context.Aliases.Select(x => x.Name)53 .Union(context.Expressions.Select(x => x.Name)));54 throw new ArgumentException($"The value '{name}' is not recognized as a column position, a column name, a column alias or an expression. Possible arguments are: '{string.Join("', '", existingNames.ToArray())}'");55 }56 protected object EvaluateExpression(IColumnExpression expression, Context context)57 {58 if (expression.Language == LanguageType.NCalc)59 {60 var exp = new NCalc.Expression(expression.Value);61 var factory = new ColumnIdentifierFactory();62 exp.EvaluateParameter += delegate (string name, NCalc.ParameterArgs args)63 {64 args.Result = name.StartsWith("@")65 ? context.Variables[name.Substring(1, name.Length-1)].GetValue()66 : Execute(context, factory.Instantiate(name));67 };68 return exp.Evaluate();69 }70 else if (expression.Language == LanguageType.Native)...
ContextScalarResolver.cs
Source:ContextScalarResolver.cs
...8using System.Text;9using System.Threading.Tasks;10namespace NBi.Core.Scalar.Resolver11{12 class ContextScalarResolver<T> : IScalarResolver<T>13 {14 private Context Context { get; }15 private IColumnIdentifier ColumnIdentifier { get; }16 public ContextScalarResolver(ContextScalarResolverArgs args)17 => (Context, ColumnIdentifier) = (args.Context, args.ColumnIdentifier);18 internal ContextScalarResolver(Context context, IColumnIdentifier columnIdentifier)19 => (Context, ColumnIdentifier) = (context, columnIdentifier);20 public T Execute()21 {22 var evaluation = Context.CurrentRow.GetValue(ColumnIdentifier);23 var typedEvaluation = StrongTypingVariable(evaluation);24 return (T)typedEvaluation;25 }26 object IResolver.Execute() => Execute();27 private static object StrongTypingVariable(object input)28 {29 IFormatProvider formatProvider = typeof(T) == typeof(DateTime)30 ? (IFormatProvider)System.Globalization.DateTimeFormatInfo.InvariantInfo31 : System.Globalization.NumberFormatInfo.InvariantInfo;32 if (input != null && input.ToString().EndsWith("%"))33 input = input.ToString().Substring(0, input.ToString().Length - 1);34 var output = Convert.ChangeType(input, typeof(T), formatProvider);35 return output;36 }...
Context
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Variable;7{8 {9 static void Main(string[] args)10 {11 var context = new Context();12 context.Add("a", "b");13 context.Add("c", "d");14 context.Add("e", "f");15 var result = context.Get("a");16 Console.WriteLine(result);17 Console.ReadKey();18 }19 }20}
Context
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Variable;7{8 {9 static void Main(string[] args)10 {11 Context context = new Context();12 context.Add("var1", "value1");13 context.Add("var2", "value2");14 context.Add("var3", "value3");15 string value = context.Get("var1");16 Console.WriteLine(value);17 Console.ReadKey();18 }19 }20}
Context
Using AI Code Generation
1var context = new NBi.Core.Variable.Context();2context.Add("var1", "value1");3context.Add("var2", "value2");4context.Add("var3", "value3");5context.Add("var4", "value4");6context.Add("var5", "value5");7context.Add("var6", "value6");8context.Add("var7", "value7");9context.Add("var8", "value8");10context.Add("var9", "value9");11context.Add("var10", "value10");12context.Add("var11", "value11");13context.Add("var12", "value12");14context.Add("var13", "value13");15context.Add("var14", "value14");16context.Add("var15", "value15");17context.Add("var16", "value16");18context.Add("var17", "value17");19context.Add("var18", "value18");20context.Add("var19", "value19");21context.Add("var20", "value20");22context.Add("var21", "value21");23context.Add("var22", "value22");24context.Add("var23", "value23");25context.Add("var24", "value24");26context.Add("var25", "value25");27context.Add("var26", "value26");28context.Add("var27", "value27");29context.Add("var28", "value28");30context.Add("var29", "value29");31context.Add("var30", "value30");32context.Add("var31", "value31");33context.Add("var32", "value32");34context.Add("var33", "value33");35context.Add("var34", "value34");36context.Add("var35", "value35");37context.Add("var36", "value36");38context.Add("var37", "value37");39context.Add("var38", "value38");40context.Add("var39", "value39");41context.Add("var40", "value40");42context.Add("var41", "value41");43context.Add("var42", "value42");44context.Add("var43", "value43");45context.Add("var44", "value44");46context.Add("var45", "value45");47context.Add("var46", "value46");48context.Add("var47", "value47");49context.Add("var48", "value48");50context.Add("var49", "value
Context
Using AI Code Generation
1using NBi.Core.Variable;2{3 static void Main(string[] args)4 {5 var context = new Context();6 context.Add("name", "John");7 context.Add("surname", "Doe");8 context.Add("age", 42);9 var name = context.Get<string>("name");10 var surname = context.Get<string>("surname");11 var age = context.Get<int>("age");12 Console.WriteLine($"Name: {name}");13 Console.WriteLine($"Surname: {surname}");14 Console.WriteLine($"Age: {age}");15 }16}17using NBi.Core.Variable;18{19 static void Main(string[] args)20 {21 var context = new Context();22 context.Add("name", "John");23 context.Add("surname", "Doe");24 context.Add("age", 42);25 var name = context.Get<string>("name");26 var surname = context.Get<string>("surname");27 var age = context.Get<int>("age");28 Console.WriteLine($"Name: {name}");29 Console.WriteLine($"Surname: {surname}");30 Console.WriteLine($"Age: {age}");31 }32}33using NBi.Core.Variable;34{35 static void Main(string[] args)36 {37 var context = new Context();38 context.Add("name", "John");39 context.Add("surname", "Doe");40 context.Add("age", 42);41 var name = context.Get<string>("name");42 var surname = context.Get<string>("surname");43 var age = context.Get<int>("age");44 Console.WriteLine($"Name: {name}");45 Console.WriteLine($"Surname: {surname}");46 Console.WriteLine($"Age: {age}");47 }48}49using NBi.Core.Variable;50{51 static void Main(string[] args)52 {53 var context = new Context();54 context.Add("name", "John");55 context.Add("surname", "Doe");56 context.Add("age", 42);57 var name = context.Get<string>("name");58 var surname = context.Get<string>("surname");59 var age = context.Get<int>("age");60 Console.WriteLine($"Name
Context
Using AI Code Generation
1var context = new NBi.Core.Variable.Context();2var value = context.Get("myVariable");3var context = new NBi.Core.Variable.Context();4var value = context.Get("myVariable");5var context = new NBi.Core.Variable.Context();6var value = context.Get("myVariable");7var context = new NBi.Core.Variable.Context();8var value = context.Get("myVariable");9var context = new NBi.Core.Variable.Context();10var value = context.Get("myVariable");11var context = new NBi.Core.Variable.Context();12var value = context.Get("myVariable");13var context = new NBi.Core.Variable.Context();14var value = context.Get("myVariable");15var context = new NBi.Core.Variable.Context();16var value = context.Get("myVariable");17var context = new NBi.Core.Variable.Context();18var value = context.Get("myVariable");19var context = new NBi.Core.Variable.Context();20var value = context.Get("myVariable");
Context
Using AI Code Generation
1using NBi.Core.Variable;2using System;3using System.Collections.Generic;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7{8 {9 static void Main(string[] args)10 {11 Context context = new Context();12 string value = context.Get("variable1");13 Console.WriteLine(value);14 }15 }16}
Context
Using AI Code Generation
1var context = new Context();2var expected = context.Get("string");3var context = new NBi.Core.Variable.Context();4var expected = context.Get("string");5var context = new Context();6var expected = context.Get("string");7var context = new NBi.Core.Variable.Context();8var expected = context.Get("string");9Name Description {guid} A GUID (Globally Unique Identifier) value. {random} A random integer value. {today} The current date. {now} The current date and time. {tomorrow} The date of tomorrow. {yesterday} The date of yesterday. {today+1d} The date of the day after tomorrow. {today-1d} The date of the day before yesterday. {today+1m} The date of next month. {today-1m} The date of previous month. {today+1y} The date of next year. {today-1y} The date of previous year. {today+1w} The date of next week. {today-1w} The date of previous week. {today+2w} The date of the week after next. {today-2w} The date of the week before previous. {today+3w} The date of the week after after next. {today-3w} The date of the week before before previous. {today+4w} The date of the week after after after next. {today-4w} The date of the week before before before previous. {today+5w} The date of the week after after after after next. {today-5w} The date of the week before before
Context
Using AI Code Generation
1using NBi.Core.Variable;2string str = Context.Get("myVar");3using NBi.Core.Variable;4string str = Context.Get("myVar");5using NBi.Core.Variable;6string str = Context.Get("myVar");
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!!