Best NBi code snippet using NBi.Core.Variable.Context
InstanceArgsBuilder.cs
Source:InstanceArgsBuilder.cs
...81 var derivationArgs = new Dictionary<string, DerivationArgs>();82 foreach (var derivation in (obj as InstanceSettlingXml).DerivedVariables)83 {84 var transformerArgs = new TransformaterArgs() { Language = derivation.Script.Language, Code = derivation.Script.Code };85 var transformerFactory = new TransformerFactory(ServiceLocator, new Context(Variables));86 var transformer = transformerFactory.Instantiate(transformerArgs);87 transformer.Initialize(derivation.Script.Code);88 derivationArgs.Add(derivation.Name, new DerivationArgs() { Source = derivation.BasedOn, Transformer = transformer });89 }90 args = new DerivedVariableInstanceArgs()91 {92 Name = variable.Name,93 Resolver = sequenceResolver,94 Derivations = derivationArgs,95 Categories = (obj as InstanceSettlingXml).Categories,96 Traits = (obj as InstanceSettlingXml).Traits.ToDictionary(x => x.Name, x => x.Value),97 };98 }99 }100 }101 private ISequenceResolver BuildFilterSequenceResolver(ColumnType type, ISequenceResolver resolver, FilterSequenceXml filterXml)102 {103 if (filterXml == null)104 return resolver;105 var predicateBuilder = new PredicateArgsBuilder(ServiceLocator, new Context(Variables));106 var predicateArgs = predicateBuilder.Execute(filterXml.Predication.ColumnType, filterXml.Predication.Predicate);107 var predicate = new PredicateFactory().Instantiate(predicateArgs);108 var operandTransformation = new TransformerFactory(ServiceLocator, new Context(Variables)).Instantiate109 (110 new OperandTransformation111 {112 OriginalType = type,113 Code = filterXml.Predication.Operand114 }115 );116 operandTransformation.Initialize(filterXml.Predication.Operand);117 var factory = new SequenceResolverFactory(ServiceLocator);118 return factory.Instantiate(type, new FilterSequenceResolverArgs(resolver, predicate, operandTransformation));119 }120 private class OperandTransformation : ITransformationInfo121 {122 public ColumnType OriginalType { get ; set; }...
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)...
Context
Using AI Code Generation
1using NBi.Core.Variable;2var context = new Context();3context.Variables.Add("var1", "value1");4context.Variables.Add("var2", "value2");5context.Variables.Add("var3", "value3");6context.Variables.Add("var4", "value4");7context.Variables.Add("var5", "value5");8context.Variables.Add("var6", "value6");9context.Variables.Add("var7", "value7");10context.Variables.Add("var8", "value8");11context.Variables.Add("var9", "value9");12context.Variables.Add("var10", "value10");13context.Variables.Add("var11", "value11");14context.Variables.Add("var12", "value12");15context.Variables.Add("var13", "value13");16context.Variables.Add("var14", "value14");17context.Variables.Add("var15", "value15");18context.Variables.Add("var16", "value16");19context.Variables.Add("var17", "value17");20context.Variables.Add("var18", "value18");21context.Variables.Add("var19", "value19");22context.Variables.Add("var20", "value20");23context.Variables.Add("var21", "value21");24context.Variables.Add("var22", "value22");25context.Variables.Add("var23", "value23");26context.Variables.Add("var24", "value24");27context.Variables.Add("var25", "value25");28context.Variables.Add("var26", "value26");29context.Variables.Add("var27", "value27");30context.Variables.Add("var28", "value28");31context.Variables.Add("var29", "value29");32context.Variables.Add("var30", "value30");33context.Variables.Add("var31", "value31");34context.Variables.Add("var32", "value32");35context.Variables.Add("var33", "value33");36context.Variables.Add("var34", "value34");37context.Variables.Add("var35", "value35");38context.Variables.Add("var36", "value36");39context.Variables.Add("var37", "value37");40context.Variables.Add("var38", "value38");41context.Variables.Add("var39", "value39");42context.Variables.Add("var40", "value40");43context.Variables.Add("
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("myVar", "myVal");13 Console.WriteLine(context.Get("myVar"));14 Console.ReadLine();15 }16 }17}18using System;19using System.Collections.Generic;20using System.Linq;21using System.Text;22using System.Threading.Tasks;23using NBi.Core;24{25 {26 static void Main(string[] args)27 {28 var context = new Context();29 context.Add("myVar", "myVal");30 Console.WriteLine(context.Get("myVar"));31 Console.ReadLine();32 }33 }34}35using System;36using System.Collections.Generic;37using System.Linq;38using System.Text;39using System.Threading.Tasks;40using NBi.Core;41{42 {43 static void Main(string[] args)44 {45 var context = new Context();46 context.Add("myVar", "myVal");47 Console.WriteLine(context.Get("myVar"));48 Console.ReadLine();49 }50 }51}52using System;53using System.Collections.Generic;54using System.Linq;55using System.Text;56using System.Threading.Tasks;57using NBi.Core;58{59 {60 static void Main(string[] args)61 {62 var context = new Context();63 context.Add("myVar", "myVal");64 Console.WriteLine(context.Get("myVar"));65 Console.ReadLine();66 }67 }68}69using System;70using System.Collections.Generic;71using System.Linq;72using System.Text;73using System.Threading.Tasks;74using NBi.Core;75{76 {77 static void Main(string[] args)78 {79 var context = new Context();80 context.Add("myVar", "myVal");81 Console.WriteLine(context.Get
Context
Using AI Code Generation
1using NBi.Core.Variable;2using System;3{4 {5 public MyContext() : base() { }6 public MyContext(string connectionString) : base(connectionString) { }7 public object GetObjectValue(string objectName)8 {9 if (objectName == "MyObject")10 return new MyObject();11 return null;12 }13 }14}15using System;16{17 {18 public string MyProperty { get; set; }19 }20}21using System;22using NBi.Core.Sequence.Resolver.Loop;23{24 {25 public IEnumerable<object> Execute(object start, object end)26 {27 var startValue = Convert.ToInt32(start);28 var endValue = Convert.ToInt32(end);29 for (var i = startValue; i <= endValue; i++)30 yield return i;31 }32 }33}34using System;35using NBi.Core.Sequence.Resolver.Loop;36{37 {38 public IEnumerable<object> Execute(object start, object end)39 {40 var startValue = Convert.ToInt32(start);41 var endValue = Convert.ToInt32(end);42 for (var i = startValue; i <= endValue; i++)43 yield return i;44 }45 }46}47using System;48using NBi.Core.Sequence.Resolver.Loop;49{50 {51 public IEnumerable<object> Execute(object start, object end)52 {53 var startValue = Convert.ToInt32(start);54 var endValue = Convert.ToInt32(end);55 for (var i = startValue; i <= endValue; i++)56 yield return i;57 }58 }59}60using System;61using NBi.Core.Sequence.Resolver.Loop;62{63 {
Context
Using AI Code Generation
1var context = new Context();2context.Add("MyVar", "MyValue");3var myVar = context.Get("MyVar");4var context = new Context();5context.Add("MyVar", "MyValue");6var myVar = context.Get("MyVar");7var context = new Context();8context.Add("MyVar", "MyValue");9var myVar = context.Get("MyVar");10var context = new Context();11context.Add("MyVar", "MyValue");12var myVar = context.Get("MyVar");13var context = new Context();14context.Add("MyVar", "MyValue");15var myVar = context.Get("MyVar");16var context = new Context();17context.Add("MyVar", "MyValue");18var myVar = context.Get("MyVar");19var context = new Context();20context.Add("MyVar", "MyValue");21var myVar = context.Get("MyVar");22var context = new Context();23context.Add("MyVar", "MyValue");24var myVar = context.Get("MyVar");25var context = new Context();26context.Add("MyVar", "MyValue");27var myVar = context.Get("MyVar");28var context = new Context();29context.Add("MyVar", "MyValue");30var myVar = context.Get("MyVar");31var context = new Context();32context.Add("MyVar", "MyValue");33var myVar = context.Get("MyVar");
Context
Using AI Code Generation
1using NBi.Core.Variable;2using System;3{4 {5 public override string Resolve(string variable)6 {7 if (variable == "myVariable")8 return "myValue";9 return base.Resolve(variable);10 }11 }12}13using NBi.Core;14using NBi.Core.Elasticsearch.Query.Client;15using NBi.Core.Elasticsearch.Query.Command;16using NBi.Core.Elasticsearch.Query.Execution;17using NBi.Core.Query;18using NBi.Core.Query.Client;19using NBi.Core.Query.Command;20using NBi.Core.Query.Execution;21using NBi.Core.Query.Resolver;22using NBi.Core.Scalar.Resolver;23using NBi.Core.Sequence.Resolver;24using NBi.Core.Variable;25using System;26using System.Collections.Generic;27using System.Linq;28using System.Text;29using System.Threading.Tasks;30{31 {32 public void MyMethod()33 {34 var context = new MyContext();35 context.Variables.Add("myVariable", new VariableScalarResolver<string>("myVariable"));36 var clientFactory = new ElasticsearchClientFactory();37 var command = new ElasticsearchCommand();38 command.Text = "SELECT * FROM myTable WHERE myColumn = '{{myVariable}}'";39 var resolverFactory = new ResolverFactory();40 var commandResolver = new CommandResolver(command, resolverFactory, context);41 var client = clientFactory.Instantiate(connectionString);42 var engine = new ElasticsearchExecutionEngine(client);43 var result = engine.Execute(commandResolver);44 }45 }46}
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!!